In answer to Polly's question, here is a complete routine that I use to send any string to the serial port and read in the returning response. If you want to send binary data you do have to use an array to do this. I have included my Decimal converter which makes it easier to see what you are sending. I always work with Port Monitor (freeware) running and just step through my code until I get the required response on the Port Monitor screen. It's much easier that using debug or immediate. This routine uses a defined (vertical) range on an Excel sheet where you can enter your string to be sent. In my case I had to send %01#WCSY0000**CR to my microprocessor. This was just simply entered into the cells on my test sheet individually, except for the CR. This routine can be used for testing any string, either binary or ASCII. Once you have got the required response working, then you can get rid of the excess code, but at least it helps to see what is going on.
*********************************************************
Sub SendFPOTestQueryString()
'Sends the entire string directly from the Excel sheet, stopping at the first blank line.
'Use this routine for testing new commands.
Dim PortSettings As String, BinaryResponse As String, ResponseString As String
Dim Interval As Integer, i As Integer, DataCol As Integer
Dim ArrayOut(0 To 50) As Byte 'Set the length of transmission array
Dim ArBytes(0 To 229) As Byte
Dim strFPO As String
Dim j As Integer
Dim fStartTime As Single
Dim fCurrentTime As Single
Dim bIsPortOk As Boolean
Dim nNumBytesWaiting As Integer
Dim nNumBytesReceived As Integer
Dim BytesToSend As Integer
'Routine scans the Range where the test message is stored until it comes to the first blank line
Range("TestString")(1, 1).Select
i = 1
While ActiveCell <> ""
ActiveCell.Offset(1, 0).Select
Pi = Range("TestString")(i, 1)
If i = 1 Then P1 = Pi
If i = 2 Then P2 = Pi
If i = 3 Then P3 = Pi
If i = 4 Then P4 = Pi
If i = 5 Then P5 = Pi
If i = 6 Then P6 = Pi
If i = 7 Then P7 = Pi
If i = 8 Then P8 = Pi
If i = 9 Then P9 = Pi
If i = 10 Then P10 = Pi
If i = 11 Then P11 = Pi
If i = 12 Then P12 = Pi
If i = 13 Then P13 = Pi
If i = 14 Then P14 = Pi
If i = 15 Then P15 = Pi
If i = 16 Then P16 = Pi
If i = 17 Then P17 = Pi
If i = 18 Then P18 = Pi
If i = 19 Then P19 = Pi
If i = 20 Then P20 = Pi
If i = 21 Then P21 = Pi
If i = 22 Then P22 = Pi
If i = 23 Then P23 = Pi
If i = 24 Then P24 = Pi
If i = 25 Then P25 = Pi
If i = 26 Then P26 = Pi
If i = 27 Then P27 = Pi
If i = 28 Then P28 = Pi
If i = 29 Then P29 = Pi
If i = 30 Then P30 = Pi
i = i + 1
Wend
BytesToSend = ActiveCell.Row - 2 'This is the number of characters in the test message
' Open selected serial port according to settings in PublicDeclarations
PortSettings = CStr(BaudRate & "," & Parity & "," & DataBits & "," & StopBits)
bIsPortOk = Form1.CheapComm1.OpenCommPort(ActivePort, PortSettings)
'if port can't be opened successfully, end program
If bIsPortOk = False Then
MsgBox "Can't open serial port. Ending Program"
End
End If
Form1.CheapComm1.ClearCommPort 'clear buffers
'Define array for the FPO string
ArrayOut(0) = DecimalCode(CStr(P1)) ' Use ASCII translator to convert to numbers
ArrayOut(1) = DecimalCode(CStr(P2))
ArrayOut(2) = DecimalCode(CStr(P3))
ArrayOut(3) = DecimalCode(CStr(P4))
ArrayOut(4) = DecimalCode(CStr(P5))
ArrayOut(5) = DecimalCode(CStr(P6))
ArrayOut(6) = DecimalCode(CStr(P7))
ArrayOut(7) = DecimalCode(CStr(P8))
ArrayOut(8) = DecimalCode(CStr(P9))
ArrayOut(9) = DecimalCode(CStr(P10))
ArrayOut(10) = DecimalCode(CStr(P11))
ArrayOut(11) = DecimalCode(CStr(P12))
ArrayOut(12) = DecimalCode(CStr(P13))
ArrayOut(13) = DecimalCode(CStr(P14))
ArrayOut(14) = DecimalCode(CStr(P15))
ArrayOut(15) = DecimalCode(CStr(P16))
ArrayOut(16) = DecimalCode(CStr(P17))
ArrayOut(17) = DecimalCode(CStr(P18))
ArrayOut(18) = DecimalCode(CStr(P19))
ArrayOut(19) = DecimalCode(CStr(P20))
ArrayOut(20) = DecimalCode(CStr(P21))
ArrayOut(21) = DecimalCode(CStr(P22))
ArrayOut(22) = DecimalCode(CStr(P23))
ArrayOut(23) = DecimalCode(CStr(P24))
ArrayOut(24) = DecimalCode(CStr(P25))
ArrayOut(25) = DecimalCode(CStr(P26))
ArrayOut(26) = DecimalCode(CStr(P27))
ArrayOut(27) = DecimalCode(CStr(P28))
ArrayOut(28) = DecimalCode(CStr(P29))
ArrayOut(29) = DecimalCode(CStr(P30))
nNumBytesSent = Form1.CheapComm1.SendSubArray(ArrayOut, BytesToSend) 'send FPO array
'Form1.CheapComm1.SendBinaryData (ArrayOut) 'send FPO string
'get the current time (seconds since midnight)
fStartTime = Timer
Do
'Give the program time to read the input buffer
nNumBytesWaiting = Form1.CheapComm1.GetNumBytes
fCurrentTime = Timer 'get current time
'if no reply within 2 sec, exit
If fCurrentTime - fStartTime > 2 Then
MsgBox "No Reply from Matsushita FPO PLC !", vbCritical, "Reply Error"
Form1.CheapComm1.CloseCommPort 'close Comport
End
End If
Loop Until nNumBytesWaiting > 0 'Change this value to suit number of words
'Select the number of bytes to be removed from buffer for processing
nNumBytesReceived = Form1.CheapComm1.GetBinaryData(ArBytes, 9)
Form1.CheapComm1.CloseCommPort 'close Comport
DataByte1 = ASCIIChr((ArBytes(7)))
DataByte2 = ASCIIChr((ArBytes(8)))
DataByte3 = ASCIIChr((ArBytes(9)))
DataByte4 = ASCIIChr((ArBytes(10)))
For j = 2 To 51 'Log first 50 HEX bytes received to FPO HEXData (for debugging)
ThisWorkbook.Sheets("FPOHEXData").Range("FPO.HEX.Data")(j, 1) = ASCIIChr((ArBytes(j - 2)))
Next j
'ASCIIChr
End Sub
Function DecimalCode(StringToConvert As String) As Integer
' Converts ASCII characters into Decimal
Select Case StringToConvert
Case Is = "NUL": DecimalCode = 0
Case Is = "SOH": DecimalCode = 1
Case Is = "STX": DecimalCode = 2
Case Is = "ETX": DecimalCode = 3
Case Is = "EOT": DecimalCode = 4
Case Is = "ENQ": DecimalCode = 5
Case Is = "ACK": DecimalCode = 6
Case Is = "BEL": DecimalCode = 7
Case Is = "BS": DecimalCode = 8
Case Is = "HT": DecimalCode = 9
Case Is = "NL": DecimalCode = 10
Case Is = "VT": DecimalCode = 11
Case Is = "NP": DecimalCode = 12
Case Is = "CR": DecimalCode = 13
Case Is = "SO": DecimalCode = 14
Case Is = "SI": DecimalCode = 15
Case Is = "DLE": DecimalCode = 16
Case Is = "DC1": DecimalCode = 17
Case Is = "DC2": DecimalCode = 18
Case Is = "DC3": DecimalCode = 19
Case Is = "DC4": DecimalCode = 20
Case Is = "NAK": DecimalCode = 21
Case Is = "SYN": DecimalCode = 22
Case Is = "ETB": DecimalCode = 23
Case Is = "CAN": DecimalCode = 24
Case Is = "EM": DecimalCode = 25
Case Is = "SUB": DecimalCode = 26
Case Is = "ESC": DecimalCode = 27
Case Is = "FS": DecimalCode = 28
Case Is = "GS": DecimalCode = 29
Case Is = "RS": DecimalCode = 30
Case Is = "US": DecimalCode = 31
Case Is = "SP": DecimalCode = 32
Case Is = "!": DecimalCode = 33
Case Is = """

ecimalCode=34"
Case Is = "#": DecimalCode = 35
Case Is = "$": DecimalCode = 36
Case Is = "%": DecimalCode = 37
Case Is = "&": DecimalCode = 38
Case Is = "'": DecimalCode = 39
Case Is = "(": DecimalCode = 40
Case Is = ")": DecimalCode = 41
Case Is = "*": DecimalCode = 42
Case Is = "+": DecimalCode = 43
Case Is = ",": DecimalCode = 44
Case Is = "-": DecimalCode = 45
Case Is = ".": DecimalCode = 46
Case Is = "/": DecimalCode = 47
Case Is = "0": DecimalCode = 48
Case Is = "1": DecimalCode = 49
Case Is = "2": DecimalCode = 50
Case Is = "3": DecimalCode = 51
Case Is = "4": DecimalCode = 52
Case Is = "5": DecimalCode = 53
Case Is = "6": DecimalCode = 54
Case Is = "7": DecimalCode = 55
Case Is = "8": DecimalCode = 56
Case Is = "9": DecimalCode = 57
Case Is = ":": DecimalCode = 58
Case Is = ";": DecimalCode = 59
Case Is = "<": DecimalCode = 60
Case Is = "=": DecimalCode = 61
Case Is = ">": DecimalCode = 62
Case Is = "?": DecimalCode = 63
Case Is = "@": DecimalCode = 64
Case Is = "A": DecimalCode = 65
Case Is = "B": DecimalCode = 66
Case Is = "C": DecimalCode = 67
Case Is = "D": DecimalCode = 68
Case Is = "E": DecimalCode = 69
Case Is = "F": DecimalCode = 70
Case Is = "G": DecimalCode = 71
Case Is = "H": DecimalCode = 72
Case Is = "I": DecimalCode = 73
Case Is = "J": DecimalCode = 74
Case Is = "K": DecimalCode = 75
Case Is = "L": DecimalCode = 76
Case Is = "M": DecimalCode = 77
Case Is = "N": DecimalCode = 78
Case Is = "O": DecimalCode = 79
Case Is = "P": DecimalCode = 80
Case Is = "Q": DecimalCode = 81
Case Is = "R": DecimalCode = 82
Case Is = "S": DecimalCode = 83
Case Is = "T": DecimalCode = 84
Case Is = "U": DecimalCode = 85
Case Is = "V": DecimalCode = 86
Case Is = "W": DecimalCode = 87
Case Is = "X": DecimalCode = 88
Case Is = "Y": DecimalCode = 89
Case Is = "Z": DecimalCode = 90
Case Is = "[": DecimalCode = 91
Case Is = "\": DecimalCode = 92
Case Is = "]": DecimalCode = 93
Case Is = "^": DecimalCode = 94
Case Is = "_": DecimalCode = 95
Case Is = "`": DecimalCode = 96
Case Is = "a": DecimalCode = 97
Case Is = "b": DecimalCode = 98
Case Is = "c": DecimalCode = 99
Case Is = "d": DecimalCode = 100
Case Is = "e": DecimalCode = 101
Case Is = "f": DecimalCode = 102
Case Is = "g": DecimalCode = 103
Case Is = "h": DecimalCode = 104
Case Is = "i": DecimalCode = 105
Case Is = "j": DecimalCode = 106
Case Is = "k": DecimalCode = 107
Case Is = "l": DecimalCode = 108
Case Is = "m": DecimalCode = 109
Case Is = "n": DecimalCode = 110
Case Is = "o": DecimalCode = 111
Case Is = "p": DecimalCode = 112
Case Is = "q": DecimalCode = 113
Case Is = "r": DecimalCode = 114
Case Is = "s": DecimalCode = 115
Case Is = "t": DecimalCode = 116
Case Is = "u": DecimalCode = 117
Case Is = "v": DecimalCode = 118
Case Is = "w": DecimalCode = 119
Case Is = "x": DecimalCode = 120
Case Is = "y": DecimalCode = 121
Case Is = "z": DecimalCode = 122
Case Is = "{": DecimalCode = 123
Case Is = "|": DecimalCode = 124
Case Is = "}": DecimalCode = 125
Case Is = "~": DecimalCode = 126
Case Is = "(del)": DecimalCode = 127
Case Is = " ": DecimalCode = 32
End Select
End Function