Flow Control and Its Importance and Purpose

Question: We are able to communicate with our Serial Device via the DS100 (EM100) but there are a lot of data errors. It seems that data bytes are randomly lost. What is the problem here?

Answer: The most frequent cause of data loss is some problem with the handshaking (RTS/CTS) between your serial device and the Device Server. Using handshaking is recommended whenever possible. Just because your serial device could operate without handshaking when connected directly to the PC doesn't mean that it will also work fine without handshaking when connected to the Device Server. Here is why:

Unlike a serial cable which serves exclusively to connect together two devices, the Ethernet (TCP/IP) is a shared media that is used by many devices at the same time. Depending on the network conditions the DS100 may not be able to route all the serial data as it arrives into the serial port, so this data may need to be buffered. The buffer has a limited size (see below) and, to prevent it from overflowing, you need to enable RTS/CTS handshaking between the DS100 and your serial device.

The procedure below will help you determine if your RTS/CTS handshaking is enabled and is functioning correctly. The problem with handshaking may be:

  • In the Settings or current operating parameters of the Device Server.
  • In your serial device.
  • In the wiring of the cable which connects the Device Server to your serial device.

Make Sure The Device Server Is Operating With RTS/CTS Handshaking Enabled

One Setting and one Parameter define whether the Device Server is running with the Flow Control enabled or disabled:

  • The Flow Control (FC) Setting of the Device Server which is a “permanent” parameter that is kept in the Device Server's non-volatile memory and is “recalled” each time the Device Server is powered up. This Setting (like all other Settings) can be edited through the DS Manager; you can find it on the Serial Properties page in the DS Properties dialog. Connection Wizard always sets the Flow Control to “RTS/CTS” (enabled)
  • The Flow Control “on-the-fly” Parameter that may be sent from the PC to temporarily override the Flow Control Setting. Parameters are usually supplied by a Virtual Serial Port (VSP) when it is opened by the application software. Parameters provide a way to adjust the serial port of the Device Server to function as needed by the application software. Parameters will only work when (a) The VSP is set to send the on-the-fly Parameters; and (b) the DS100 is set to accept the on-the-fly Parameters. Connection Wizard always enables Parameter passing.

The bottom line of all this is that the DS100 may be running with RTS/CTS disabled even if the Flow Control is enabled in the DS100's Settings. The flowchart on Figure 4 shows the “action plan” for making sure that the DS100 is running with RTS/CTS enabled.

Figure 1. “Action plan” flowchart

If your serial application does not use the VSP but is working with the Device Server directly via the TCP/IP or UDP/IP protocol then you needn't worry about Parameters (unless, of course, you have implemented Parameter passing in your application software). All you need to do is make sure that the Flow Control Setting of the Device Server is set to “RTS/CTS”.

If your serial application does use the VSP, you need to check if on-the-fly Parameter passing is enabled (you need to check both the VSP side and the Device Server side).

  • If on-the-fly Parameter passing is disabled then all you need to do is make sure that the Flow Control Setting of the Device Server is set to “RTS/CTS”.
  • If on-the-fly Parameter passing is enabled then the value of the Flow Control Setting doesn't really matter. You need to make sure that:
  • Your application software, when opening the VSP, enables the RTS/CTS flow control. We cannot provide an advice on how to do this for all programming languages. For Visual Basic this means setting the Handshaking Property of the MSComm control to “2-comRTS”
  • On-the-fly parameters sent by the VSP reach the Device Server. This may be verified using the Port Monitor. The Port Monitor run in the system tray. Double-click on it to open, then push the “Clear log” button to clear the window. Launch your application software on the PC and perform some port-related activity so that the VSP is opened. The VSP will send the Flow Control Parameter (among others) to the Device Server. A “green” record will appear in the Port Monitor window if the parameter was sent successfully (and do make sure that RTS/CTS gets enabled!). Errors will be highlighted in different color. Investigate the problem when errors happen.

The Problem May Be in Your Serial Device

If you have made sure that the DS100 is operating with the RTS/CTS Flow Control enabled but you are still losing data then this may be because your serial device is running with RTS/CTS disabled.

The Problem May Be in The Serial Cable

The problem may also be in an incorrect (incompatible) wiring of the serial cable that connects the DS100 to your serial device. The serial cable is a “simple thing” yet its wiring is at the heart of a problem in many cases.

The problem stems from unclear definition of what is the RTS and what is the CTS signal. Many know that these two are at pins #7 and #8 (for 9-pin serial cable) and that one of them is supposed to be an input and another one- an output. But which one is which? Some manufacturers define the input and output with respect to the PC (to which the serial device is supposed to be attached). Some manufacturers define the input and output with respect to the serial device itself.

The net result is that there are serial devices on the market with exactly opposite wiring. You may think that RTS pin on your serial device's connector is an output while, in fact, it is an input (or vice versa). The whole thing is so cumbersome that here at Tibbo we have completely abandoned calling the wires RTS or CTS but instead refer to them as “handshaking input and output” (always with respect to the serial device itself).

As a result of all this, your serial cable might be connecting the “handshaking output” of the DS100 to the “handshaking output” of your serial device (and “input” to an “input”). Obviously, this is wrong! The “output” on one side must be connected to the “input” on another side and vise versa!

The ONLY Way to Know For Sure

Now we will tell you the only 100% error-proof method of finding out if your wiring is correct. Don't just “check the manual”, do as we advise!

Take any kind of meter that is capable of measuring voltage, and measure the voltage on both RTS and CTS lines (with respect to the ground). You need to perform this test with both the DS100 and your serial device powered and the serial cable connected to both of them at the same time (yes, finding a way to measure the voltage may be tricky but you will defeat the purpose of this test if you disconnect the cable on either side to make the measurement on the connector pins). The measurement arrangement is shown on Figure 2.

Figure 2. Making sure that RTS/CTS lines are wired correctly

When the cable wiring is correct (compatible with your serial device) then there will be some potential (about 5-12V, doesn't matter positive or negative) on both lines. If the wiring is incorrect then there will be a potential on one of the lines and nothing (i.e. just some “millivolts”, definitely <1V) on another line. If you discover then this is so then you must “swap” the CTS and RTS lines. That is, if you had a connection like this (“cross”):

#7 –> #8

#8 –> #7

then you will need to change it to this (“direct”):

#7 –> #7

#8 –> #8

And if you had the “direct” connection then you will have to change it to “cross”.

After you have rewired the cable please check the voltage again. Now you should have a “sizeable” voltage of 5-12V on both RTS and CTS lines!

Conclusion

We hope that the above has helped you sort out the problem with the handshaking. If the problem is still there please let us know- we will try to help you find out the solution!

 
general/networking/flow_control.txt · Last modified: 2008/09/09 14:03 by wikisu