What does dataBits option do in the node-serialport Serialport contructor?

Viewed 561

I am using the node-serialport package, and I came across the set of options available to be passed to the constructor of a SerialPort. One of them is called dataBits. The only thing I can find in the documentation is that it can take on values 5, 6, 7, or 8 (default). What does this mean?

Also, more generally, I find the documentation for this package to be lacking many important details. Does anyone know of any great tutorial resources that may be more helpful?

1 Answers

You can usually ignore this option unless you need it. The default is the most common.

The linux documentaiton project has an overview on serialports which has this excerpt.

In serial transmission of bytes via RS-232 ports, the low-order bit is always sent first (the bit-order). Serial ports on PC's use asynchronous communication where there is a start bit and a stop bit to mark the beginning and end of a byte. This is called framing and the framed byte is sometimes called a frame. As a result a total of 9, 10, or 11 bits are sent per byte with 10 being the most common. 8-N-1 means 8 data bits, No parity, 1 stop bit. This adds up to 10 bits total when one counts the start bit. One stop bit is almost universally used.

I highly recommend them for an overview of how serial ports function. Node SerialPort's website is more about how to use node SerialPort.

I'll summarize however as it might be useful.

While modern equipment expect most bytes to have 8 bits, older devices often only could handle 7 (or 6 or 5) bits at a time. They would in turn expect the "packet" of a serial transmission to only include those numbers of bits. A good example of this is the first Microsoft serial mouse. It's hardware, the serial mouse protocol and it's drivers only expected 7 bits a packet. This would be 7 dataBits in serial port's terminology. So instead of waiting for an 8th bit, the OS would make a "7 bit byte" and pass it back to the application. If you didn't have this setting, it would wait around for an 8th bit that would be part of the next packet and nothing would look right.

Related