|
End Sub
The following subroutine demonstrates how to send the contents of
any string variable out the serial port - even strings that contain control characters or
non printable ASCII characters. The string to be sent out the serial port is passed as an
argument to the SendString subroutine.
Sub SendString(StringToSend$)
' The following
loop reads the StringToSend$ variable and generates a string
' containing the ASCII values for each character in the string separated
by commas.
' This resulting string is then used as the argument to the SENDOUT
command
' below. Ex: if the variable StringToSend$ = "ABC" then
the variable Arg$ will be
' "65,66,67" See the syntax of the SENDOUT command in
the Wedge users manual
' for details.
For x = 1 To Len(StringToSend$)
Arg$ = Arg$ + LTrim$(Str$(Asc(Mid$(StringToSend$, x, 1))))
If x <> Len(StringToSend$) Then Arg$ = Arg$ + ","
Next
channelNumber = Application.DDEInitiate("WinWedge", "COM2")
' The following line concatenates the SENDOUT
command with the data to be sent
Application.DDEExecute channelNumber, "[SENDOUT(" &
Arg$ &")]"
' The & operator is the Excel string concatenation
operator thus we are concatenating
' The three strings "[SENDOUT(" , the data in the string
variable Arg$ and ")]"
' Thus if StringToSend$="ABC" then the command that is
sent to WinWedge would
' be:[SENDOUT(65,66,67)]" - (the ASCII values for chars A,
B and C are 65, 66 and
' 67)
Application.DDETerminate channelNumber
End Sub
The following subroutine demonstrates how you would call
the above routine passing it the contents of a spreadsheet cell thus sending the cell
contents out the serial port.
Sub TestSendString()
X$ = Sheets("Sheet1").Cells(1,
1).Value
SendString(X$)
End Sub
The following Excel VBA subroutine demonstrates how to transmit
data out the serial port by "DDEPoking" to the WinWedge
OutputBuffer DDE item. Sub PokeData()
|