COM Port Settings
May 2002


------------------------Monitor-------------------------
The Newsletter for PC-Based Data Acquisition and Control
Issue 46          www.windmill.co.uk            May 2002
--------------------ISSN 1472-0221----------------------

Welcome to Issue 46 of Monitor. This month we discuss 
COM port settings: what they mean and which to 
choose.

We only send this newsletter to people who have 
subscribed - should you wish to cancel your free 
subscription please do so at
https://www.windmill.co.uk/newsletter.html

CONTENTS
========
* Windmill News: Full Data Acquisition Index
* Making Measurements through the COM Port
________________________________________________________
________________________________________________________

Windmill News: Full Data Acquisition Index
________________________________________________________

In your answers to our recent survey, you requested a 
comprehensive subject index of previous newsletters. As 
Monitor is now in its 45th issue, this proved too long 
to include in the e-newsletter. Instead, we've made it 
web based, and included extra material which is on the 
web site but not in any of the Monitor issues. We hope 
you find the index useful. If you think there are terms 
we've missed - please let us know. E-mail: 
monitor@windmillsoft.com

To view the index go to 
https://www.windmill.co.uk/subjects.html

If you didn't take part in our survey but would like to 
do so, fill in the form at 
https://www.windmill.co.uk/monitor42.html
________________________________________________________
________________________________________________________

Making Measurements through the COM Port
________________________________________________________

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 driver software to read 
the data arriving at the port. Windmill, for example, 
offers a choice of two drivers - COMIML and the older LabIML. When using any 
serial driver you will need to tell the software about 
the communication settings used by your instrument. These 
include COM port number, baud rate, parity, data bits and 
stop bits.

                            *

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, PCMCIA, ISA-bus, etc. You can then 
install an appropriate adaptor.

                            *

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.)

                            *

Most Common Settings

To summarise, the most commonly used settings for serial 
devices are...
Data Bits: 8
Parity: None
Stop Bit: 1

                            *

More Information

You can find out more about the Windmill COMIML serial 
driver at 
http//www.windmillsoft.com/

Further Reading: Web Pages
Monitor Issue 42: The Ins and Outs of RS232 COM Ports
Monitor Issue 15: What is RS232?
Lammert Bies, RS232 Specifications

Further Reading: Books
Serial Port Complete by Jan Axelson. Published by 
Lakeview Research, 1998.
Available from Amazon.co.uk and Amazon.com
________________________________________________________
________________________________________________________

* Copyright Windmill Software Ltd
* Reprinting permitted with this notice included
* For more articles see https://www.windmill.co.uk

We are happy for you to copy and distribute this 
newsletter, and use extracts from it on your own web site 
or publication, providing the above notice is 
included and a link back to our website is in place.


An archive of previous issues is at 
https://www.windmill.co.uk/newsletter.html
and an index of articles at 
https://www.windmill.co.uk/newsletter.html

Windmill Software Ltd, PO Box 58, North District Office,
Manchester, M8 8QR, UK
Telephone: +44 (0)161 834 6688
Facsimile: +44 (0)161 833 2190
E-mail: monitor@windmillsoft.com

https://www.windmill.co.uk/

https://www.windmillsoft.com/



Subscribing

To receive Monitor every month please fill in your e-mail address below. We will not pass your address to any third parties, nor send you any unsolicited e-mail.

You will receive an e-mail asking you to confirm your subscription. On doing so you will be sent details of how to download the free software. If you don't receive this e-mail please contact monitor@windmillsoft.com.

You can read an archive of previous issues on our Data Acquisition Intelligence site.

Cancel Subscription

You can cancel your free subscription at any time - just return to this page or follow the instructions in the newsletter.

Previous Issue Next Issue