AN005. Remotely Controlling I/O Lines on the DS
|Top Previous Next|
What's in this Application Note
Many of our Customers have asked us if it possible to make our Modules (such as EM100) or "finished" devices (DS100) work as a sort of remote I/O i.e. use the DS to control "loads" (switch something on/off) and monitor "sensors" (detect if the switch is closed or opened). The answer is "YES" and this Application Note examines how this can be done.
- General-purpose I/O lines of Tibbo Device Servers
- Controlling I/O lines through a Virtual Serial Port
- Setting and sensing the status of I/O lines using on-the-fly commands
- Using notifications to get the status of I/O lines
General-purpose I/O lines of Tibbo Device Servers
You probably know that every DS model we manufacture contains some number of lines that can be used as remote I/O. For example, the serial port of our DS100R Serial Device Server contains RTS (output) and CTS (input) serial lines. From the serial port's standpoint, RTS and CTS have a specific serial port-related function but at the same time they can be used as generic output and input!
Other "external" Serial Device Servers, such as DS100B and DS203 also have DTR (output) and DSR (input) lines. Together with RTS/CTS, this brings the total number of available lines to two outputs and two inputs.
Most embedded Modules such as EM100 and EM200 have even larger number of I/O lines, some of which are not related to the standard serial port control lines in any way. For example, in addition to RTS, CTS, DTR, and DSR the EM200 has five additional I/O lines- P0, P1, P6, P7, P8. All 9 lines can be used as universal inputs/outputs- on the Module level there are no dedicated "input only" or "output only" pins*.
Controlling I/O lines through a Virtual Serial Port
The simplest way to control I/O lines of the DS is through a Virtual Serial Port. Naturally, this will be limited to setting the status of RTS and DTR lines and sensing the status of CTS and DSR lines. Extra lines such as P0, P1, etc. cannot be controlled this way. Additionally, RTS/DTR will only work as outputs and CTS/DSR- as inputs, even on embedded Modules whose I/O pins are bi-directional (see above). The advantage of using VSP is in simplicity- you don't need to write a lot of additional code.
To test how VSP works with I/O lines of the DS you can create a simple application in Visual Basic. Use MSComm ActiveX control to work with the VSP. Remember, that same rules that apply to a regular COM port of the PC also apply to the remote control of the serial port on the DS:
Before you can make this test you need to have a proper setup for the VSP and DS. Run Connection Wizard and make the following choices. Important points:
(all remaining choices are obvious or irrelevant).
After the Wizard has done its job and is at the last screen you need to do the following:
Here are some comments on the setup that we've just described. On-the-fly commands are enabled because control of the state of I/O lines is effected through these on-the-fly commands. Connection mode of the VSP was set to "immediately" to enable so called status change notifications to be sent from the DS to the VSP (PC) right from the moment the VSP is opened. More on this can be found in one of the sections below (see "using notifications to get the status of I/O lines").
After the setup is finished you can use your VB program to work with RTS, CTS, DTR, and DSR lines. While you are playing with the system take a look at what is recorded by the Port Monitor. Here is a sample output:
COM4 (INFO): "On-the-Fly" command for 192.168.100.97: enabling line change notification for DSR, CTS...success <--- notifications setup
COM4 (INFO): "On-the-Fly" command for 192.168.100.97: set DTR to low...success <--- command from VSP to DS
COM4 (INFO): "On-the-Fly" command for 192.168.100.97: set DTR to high...success <--- command from VSP to DS
COM4 (INFO): "On-the-Fly" command for 192.168.100.97: set RTS to low...success <--- command from VSP to DS
COM4 (INFO): "On-the-Fly" command for 192.168.100.97: set RTS to high...success <--- command from VSP to DS
COM4 (INFO): Line status change notification: DSR:low CTS:high <--- notification from DS to VSP
COM4 (INFO): Line status change notification: DSR:low CTS:low <--- notification from DS to VSP
As you can see from this log, an individual command is sent from the VSP to the DS when it is necessary to change the state of a particular output. A notification containing the status of both inputs are sent from the DS to the VSP when at least one of the inputs (DSR or DTR) is found to have changed the state. Notifications are explained below (see "using notifications to get the status of I/O lines").
Setting and sensing the status of I/O lines using on-the-fly commands
Virtual Serial Port works with RTS, CTS, DTR, and DSR lines using so-called on-the-fly commands. On-the-fly commands are officially known as "network-side parameters and instructions". As the name implies, these commands are sent through the network. The word "on-the-fly" refers to the fact the sending any command causes an immediate corresponding change in the serial port or I/O pin of the DS.
Related to the discussion of controlling I/O lines are two instructions:
For these instructions to work, the DS must be preset to accept them. This is done by setting On-the-fly Commands (RC) setting to 1 (enabled).
On-the-fly commands are send just like all other network programming commands which means that delivery method can be out-of-band, inband, etc. Out-of-band on-the-fly commands can be optionally password-protected by programming On-the-fly Commands (RC) setting to 1 (enabled) and defining a password in the Password (PW) setting.
If you are planning to work with P2(DSR), P3(DTR), P4(CTS), or P5(RTS) lines you need to disable their "special" functions to turn them into "pure" I/O lines. When you control those lines:
Note: when you are using the VSP you don't need to make these changes by yourself. Running Connection Wizard as described above will take care of everything.
We are not going into "much" details regarding the use of Set I/O Pin Status and Get I/O Pin Status instructions here as this would be a repetition of information already found in the topics highlighted above.
Using notifications to get the status of I/O lines
Get I/O Pin Status (Gx) instriction mentioned above offers a way to get the state of any I/O pin of the DS but in a "polled" way. If you want to monitor the status of a particular pin you need to send this command repeatedly (i.e. "poll" this pin).
Another, more convenient, possibility is make use of Notification (J) message. With proper preset, you can make the DS send a special message to the PC whenever one of "monitored" pins of the DS changes its state. Read Notification (J) message topic and you will get complete picture on how this works.
One important point that needs to be understood: notification messages are only sent when there is a data connection between the network host (that is supposed to get notifications) and the DS. This is why we have asked you to change the Connection Mode of the VSP to "connect immediately". If you didn't do this you would have to have the data connection established first (i.e. send some data). Only after that the DS would start sending notifications.
* The only exception is pin P2 of EM100 which can only work as an input.