|
The following VBA subroutine
sends a string of control codes out the serial port by issuing
the DDE command "[SendOut()]" to
WinWedge. This example sends an escape character (ASCII 27),
a capitol "P" and a carriage return-linefeed (ASCII
13 and ASCII 10).
| |
Sub SendEscapeP()
ChannelNumber = DDEInitiate("WinWedge", "COM1")
DDEExecute ChannelNumber, "[SENDOUT(27,’P’,13,10)]"
DDETerminate ChannelNumber
End Sub
|
The following subroutine shows how to send a
text string passed as an argument to the routine.
| |
Sub SendText(StringToSend$)
ChannelNumber = Application.DDEInitiate("WinWedge",
"COM2")
' The following line concatenates the
SEND command with the data to be sent
Application.DDEExecute channelNumber, "[SEND("
& StringToSend$ &")]"
' The & operator is the Excel string
concatenation operator thus we are concatenating
' The three strings "[SEND(" , the data in the string
variable StringToSend$ and ")]"
' Thus if StringToSend$ ="ABC" then the command that
is sent to WinWedge would
' be: [SEND(ABC)]"
Application.DDETerminate channelNumber
End Sub
|
The following subroutine sends a column of
data out the serial port starting in the currently active
cell. After each cell's data is sent it reads the cell directly
below the current cell. If the cell contains no data then
it stops otherwise it continues sending until it hits an empty
cell.
| |
Sub SendCells()
' open a link to winwedge on com1
chan = DDEInitiate("WinWedge", "COM1")
' starting offset from current cell is 0:
MyPointer = 0
' put string from current cell in variable x$
x$ = ActiveCell.Offset(rowOffset:=MyPointer, columnOffset:=0).Value
' while the length of the string is not 0
While Len(x$)
' send the string out the port
followed by a carriage return DDEExecute chan, "[SENDOUT(' " & x$ & " ',13)]"
' point to the next cell down
MyPointer = MyPointer + 1
' get next cell
x$ = ActiveCell.Offset(rowOffset:=MyPointer, columnOffset:=0).Value
' loop until we reach an empty cell
Wend
'Close DDE Channel
DDETerminate chan
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()
' open a DDE channel
chan = DDEInitiate("WinWedge", "COM2")
'
poke the word "Hello" followed by a carriage return
'(ASCII 13) to the outputbuffer
DDEPoke chan, "OutputBuffer", "Hello" + Chr$(13)
' close the channel
DDETerminate chan
End Sub
|
|