Collecting Data through the COM Port

COM Port Number | Baud Rate | Data Bits | Parity | Start and Stop Bits | Flow Control (Handshaking) | Most Common Settings


You can connect many different types of industrial and scientific instruments to computers via their COM ports. Doing so lets you automatically transfer data directly into logging, charting, spreadsheet, database and other display and analysis programs. No more transcription errors and huge amounts of time saved.

To achieve this you need some software to collect the data arriving at the port. Windmill offer the comDebug software. You will need to tell this or other software about the communication settings used by your instrument. These include COM port number, baud rate, parity, data bits and stop bits.

com port settings
Com Port Settings

Most Common Settings

The most commonly used settings for serial devices are...
Data Bits: 8
Parity: None
Stop Bit: 1
Flow Control: None

Read on for an explanation of these and other COM port terms.


COM Port Number

Most PCs will have one or more serial COM ports. You need to tell the software into which port you have plugged your instrument. If your computer does not have any COM ports, or you have more devices than you have ports, you can easily add more. Check your PC's hardware manual to discover its communications options: USB, Ethernet, Bluetooth, etc. You can then install an appropriate adaptor. Tips on Using USB-to-Serial Converters gives more information for USB.


Baud Rate

In serial communications - such as through the COM port - messages are sent 1 bit after another. The baud rate specifies how frequently the bits are sent and therefore expresses the maximum speed of data collection. The instrument and the computer must both communicate at the same rate. The driver software will always offer a choice of baud rates: pick the one matching your instrument's. If you can select the baud rate of your instrument it is best to choose a fast rate. This reduces the transmission times when sending and receiving messages. If the instrument is a long way from the computer and transmissions are unreliable, you may need to use a lower baud rate.

No matter how fast your connection - the maximum number of instrument readings per second depends on the software.


Data Bits

The stream of bits received at the COM port is interpreted in groups of (usually) 7 or 8 bits. Each group represents a piece of information. It is obviously important that the instrument and the computer concur on the number of data bits in a group. You will have to consult your instrument's manual to find out how many data bits it uses. If you are unsure, set the driver software to the more commonly used 8 data bits.


Parity

Parity is the state of being either odd or even. In serial communications parity may be used to check for errors in the transmission of data. When performing a parity check, the instrument or PC sending messages counts the number of 1's in a group of data bits. Depending on the result, the value of another bit - the Parity Bit - is set. The device receiving the data also counts the 1's and checks whether the Parity Bit is as it should be.

To perform a parity check the computer and the instrument must obviously agree on how they are calculating the Parity Bit. Are they setting it on for an even or odd number of 1's? When a device uses Even Parity, the data bits and the parity bit will always contain an even number of 1's. The reverse is true for Odd Parity. For example, when Odd Parity is operating and the data bits contain 10010110 - we have four 1's so the parity bit will be on (set to 1) to make an odd number.

Two other parity options often available in driver software are Mark and Space. These aren't effective in error checking. Mark means the device always sets the Parity Bit to 1 and Space always to 0.

Parity is a rudimentary error checking mechanism. It can detect an error in transmitting 1 bit, but if 2 bits happened to be wrong it would not pick this up. It also provides no help as to which bit is wrong. Other error checking mechanisms include the Start and Stop Bits described below, and cyclic redundancy checks which are often used in Modbus communications.

Consult your instrument's manual to determine its parity settings - if in doubt start by setting parity to "none". No Parity Bit will be sent.


Start and Stop Bits

Communication through the COM port is asynchronous. This means that data is sent intermittently and not at predetermined intervals. A device must therefore be able to determine the start and end of a message. It accomplishes this by Start and Stop Bits. The start bit precedes the data bits. The stop bit follows either the parity bit if present, or the data bits.

The data line has two states - on and off. An idle line is always on. When the instrument or computer wants to send data it sets the line to off - this is the Start Bit. The bits immediately after the start bit are therefore the data bits.

The Stop Bit is present to allow the instrument and computer to re-synchronise should anything go wrong: noise on the line masking the start bit for example. The period of time between the start and stop bit is constant, according to the baud rate and number of data and parity bits. The stop bit is always on. If the receiver detects an off value when the stop bit should be present, it knows there has been an error.

The stop bit is not actually 1 bit but a minimum length of time the line must be on at the end of each data transmission. On PCs this is normally equal to 1 or 2 bits, and you must specify this in the driver software. Although 1 stop bit is most common, selecting 2 will at worst slow the message down slightly. (You might see an option to set the stop bit to 1.5. This is only used when the number of Data Bits is less than 7. If this is the case then ASCII characters cannot be transmitted and so 1.5 is rarely used.)


Flow Control (Handshaking)

Unless you know differently, when connecting the instrument to the PC it is best to start with the assumption that flow control is not required.

If you start with no flow control what symptoms might indicate that it really is needed?. One possibility is that the instrument misses part of a message sent by the computer. This will probably cause the instrument not to work properly.

If flow control is required it will most commonly be Xon \ Xoff (software). More details of hardware and software flow control...


Related Topics:


Learn More

To find out more - or to ask our advice on your project - enter your details below.