Frequently Asked Questions about Sending Commands to RS232 Serial Devices
Many software packages now support macro languages to control other programs. Details of how to send data using various packages are listed below
- Send Serial RS232 Data using Microsoft Word
- Send Serial RS232 Data using Microsoft Excel
- Send Serial RS232 Data using FileMaker Pro
- Sending special characters to Matrix Orbital MOS Displays and other displays
- Command Line Arguments to configure the Serial Port
- I'm a registered user.
How do I get free updates to Serial Port Control using DDE?
Send Serial RS232 Data using Microsoft Word
To build a simple macro with Word, record a macro, and include the following code:
Sub SendRS232usingDDE() ' ' SendRS232usingDDE Macro ' Macro created 22/06/2006 by Wieser Software Ltd ' iChannel = DDEInitiate("matrxdde", "system") DDEExecute iChannel, "Send this to\r\nthe Serial Port" DDETerminate iChannel End Sub
Send Serial RS232 Data using Microsoft ExcelThe procedure using Excel is identical to using word. Below is an example of sending the data that is in the current cell.
Sub SendCurrentCell() ' ' SendCurrentCell Macro ' Macro recorded 22/06/2006 by Wieser Software Ltd ' iChannel = DDEInitiate("matrxdde", "system") DDEExecute iChannel, ActiveCell.Value DDETerminate iChannel End Sub
Alternatively, you could replace the
DDEExecute command with:
DDEExecute iChannel, Range("a1").Value
That would send the value of whatever is in cell A1 to the serial port.
Send Serial RS232 Data using FileMaker Pro
Using Filemaker Pro, when you define a script, you use the Send DDE Execute script item. You would use settings as follows, selecting the Text pushbutton shown by filemaker instead of the file button:
Send DDE Execute [Service Name: "matrxdde"; Topic: "system"; Commands: "put this on the display"]
Obviously, it will be more useful, if you combine fields that are actually in your database
Sending special characters to Matrix Orbital MOS Displays and other displays
Some devices, like the Matrix Orbital MOS AL202 LCD display use special commands to configure the display. Many of the commands are in binary format, and therefore need special handling. Because many software packages cannot handle numbers in binary format, we allow you to insert them in a quoted format which doesn't require any special handling from the program running the macros.
For instance, the Matrix Orbital Documentation says:
4.3.13 Clear Display Syntax: Hexadecimal 0xFE 0x58 Description: This command clears the display and resets the text insertion point to the top left of the screen.
To include these characters in your text, simply add them to the beginning of your text as follows:
DDEExecute iChannel, "\xFE\x58Show this after \nclearing the display"
You'll notice two things about the code. First, it can escape hexadecimal sequences by using \x followed by two hexadecimal digits. If you need to convert a decimal number to hexadecimal, do the following:
- Start the Windows calculator
- Press F6 to switch to decimal
- Type your number in decimal
- Finally, press F5 to convert the number to hexadecimal.
Secondly, you'll notice the \n character; shorthand for a new line character (\x0A). You can also use the following:
- \t for a tab character (\x09)
- \r for a carriage return (go back to the beginning of the line) (\x0D)
- \a for an alert (\x07)
- \b for a backspace character (\x08)
- \v for a vertical tab (\x0B)
- \f for a form feed, or new page (\x0C)
As a result, it is now difficult to include a \ character. To do so, simply use two in a row, like this: \\
Command Line Arguments to configure the Serial Port
If you configure your program to start with a shortcut, you can add additional arguments to the command line to control which serial port is opened, and what baud rate is used for communication. The switches are:
The software always uses 8 bits for the data width, and 1 stop bit, with no handshaking.