Table of Contents > QUARC > User's Guide > QUARC Communications Protocols
Serial Protocol
The serial communications protocol supports communications over a standard serial port.
Syntax
serial://hostname:port?option=value,... % Access serial port "port" using specified options
Description
The serial communications protocol supports communications over a standard serial
port, such as COM1
in Windows or /dev/ser1
in QNX. It is identified by using serial
as the protocol
name in a URI.
The hostname in the URI is ignored. However, to have a properly formed URI the hostname must be specified. It is best to specify the "remote" host or device with which communications is being performed as a reminder of what is connected to the serial port.
The port in the URI determines the serial port used for communications. In Windows,
the port number is appended to the string "COM" to form the name of the port. For
example, the URI serial://gps-sensor:2 refers to a GPS
sensor connected to COM2
. In QNX, the port number is
appended to the string "/dev/ser" to form the path of the port. For example, the
URI serial://proximity-sensor:1 refers to a proximity sensor
connected to /dev/ser1
.
The ports available depend on the target. The following table outlines the serial ports available on each QUARC target.
Target |
Serial Ports |
---|---|
QUARC Target for Windows |
Match port number in URI to COM port. More than 9 COM ports are supported. |
QUARC Target for Win64 |
Match port number in URI to COM port. More than 9 COM ports are supported. |
QUARC Target for Linux DuoVero |
Only serial port 1 is supported. Hardware flow control is not supported. |
QUARC Target for QNX x86 |
Match port number in URI to /dev/ser<n> port number. |
Heavy serial port traffic can be very taxing on some targets. For fast baud rates, it may be
necessary to change the serial driver options. For example, the QNX serial driver triggers
an interrupt for each character transmitted or received by default. To reduce the number of
interrupts, use the -t
and -T
options on the serial driver (see devc-ser8250)
to enable the receive and transmit FIFOs respectively. Note that each of these arguments
requires an additional parameter specifying the number of characters before an interrupt
is trigged, and must be 1, 4, 8 or 14.
When communicating between two different targets via the serial port, be aware that timers on the two targets may differ ever so slightly due to crystal oscillator or operating system discrepancies. To ensure reliable communications, it may be necessary to ensure the receiving system is operating at a slightly higher sampling period than the transmitter.
Limitations
Serial device reliability
On Windows, many extension serial devices such as USB-to-serial cables and PCI-Express multi-I/O cards do not perform as expected. For example, some USB-to-serial cables have been known to replicate transmitted data if the number of bytes sent at one time exceeds 64 bytes. Other serial devices are known to send a small number of illegal characters as soon as the serial device is opened, before any data is supposed to be transmitted. Serial ports on the motherboard are generally much more reliable. Quanser has had good success with the TrendNet TU-S9 USB-to-serial cable (primarily because our serial API has workarounds to deal with its inconsistencies).
Gumstix Verdex
On the gumstix Verdex, the full function serial port (FF RXD/TXD) is used by the Linux kernel during boot and should not be connected during boot. It may also run getty automatically on the full function serial port (/dev/ttyS0). List running processes by entering the 'ps' command in a shell connected to the gumstix (using PuTTy for example with the ssh protocol over TCP/IP). If getty shows up in the process list, as given in the example below:
845 root 516 S /sbin/getty 115200 ttyS0 vt100
then it is using /dev/ttyS0 and a different serial port should be used for communications. Quanser recommends using the bluetooth (BT RXD/TXD) and/or IrDA (IR RXD/TXD) serial ports instead.
Gumstix DuoVero
Hardware flow control is not supported on the Gumstix DuoVero targets. Do not use the flow=hardware option as it will cause unpredictable results.
Performance
Note that the number of bytes per second that may be transferred over a serial connection is generally less than 1/10 of the baud rate. For example, transfer rates of more than 5.7 kB/sec should not be expected from a 57600 baud connection. Furthermore, the data type being transmitted must also be taken into account. Since a double value is 8 bytes, no more than 720 doubles/sec may be transferred using a 57600 baud connection. For a 1KHz model, that's less than one double value per sampling instant!
QUARC Target Manager
The serial protocol cannot be used for communicating with the target (via a target URI) because the serial protocol does not allow multiple connections on the same port. Hence, qc_set_default_model_uri cannot be used to set a default serial protocol for models. Instead, the model URI must be specified explicitly in the Code Generation/Interface/MEX file arguments option of the Configuration Parameters of the model as well as the target URI.
Multiple client connections
The serial protocol will only accept a single client connection at a time on a given port. It does not support time-division multiplexing of multiple client connections over a single serial port because doing so would require adding a header to the information packets sent over the port. QUARC communication protocols never add extra information to the data sent over the communication channel in order to allow QUARC to communicate with user applications, sensors and other devices which would not support QUARC-specific data packets.
Options
baud
Set this option to the baud rate desired. If the baud rate is not supported by the serial port then an error will be issued at runtime when an attempt is made to use the serial port. Standard baud rates are shown in the table below. Baud rates over 115200 are typically not supported by serial drivers. The default baud rate is 115200.
75 | 150 | 1200 | 4800 | 14400 | 57600 | 230400 |
110 | 300 | 1800 | 7200 | 19200 | 115200 | 960800 |
134 | 600 | 2400 | 9600 | 38400 | 128000 | 921600 |
word
Set this option to the word length desired. Word lengths of 5, 6, 7 or 8 bits are supported. The default word length is 8 bits.
stop
Set this option to the number of stop bits desired. Values of 1, 1.5 or 2 bits are supported. Note that 1.5 stop bits is only supported with a word length of 5 bits. A word length of 5 bits does not support 2 stop bits. One stop bit may be used with any word length and two stop bits may be used with word lengths of 6-8 bits. The default number of stop bits is 1.
parity
Set this option to the parity setting desired. Parity values of none
,
even
, odd
, mark
and space
are
supported. The first letter may also be used as an abbreviation. The default
parity value is none
.
flow
Set this option to the flow control desired. Valid values are
none
, hardware
and software
.
The abbreviations hw
and sw
may be used instead.
The default flow control is none
.
memsize
Set this option to set the size of the serial send and receive buffers. The default buffer size is 1200 bytes. Setting this option is equivalent to setting both the sndsize and rcvsize options to this value.
sndsize
Set this option to set the size of the serial send buffer. The default buffer size is 1200 bytes.
rcvsize
Set this option to set the size of the serial receive buffer. The default buffer size is 1200 bytes.
device
Set this option to the prefix to use for the device name for the serial device. This option is typically
used on QNX to make use of USB-to-serial devices. In that case, the device option would be device='/dev/serusb'
.
polarity
Set this option to invert the polarity of the transmit and receive serial lines. This option is not
supported by most serial devices. However, it is useful for supporting protocols like S.BUS which
require inverted serial lines. To invert the serial lines, set this option to on
. The
default is off
.
Driver
The driver supporting serial communications is called qrt_serial
.
Targets
Target |
Supported |
Comments |
---|---|---|
Yes |
Fully supported. |
|
Yes |
Fully supported. |
|
Yes |
Fully supported. |
|
Yes |
Fully supported. |
|
Yes |
Fully supported. |
|
Yes |
Fully supported. |
|
Yes |
Fully supported. |
|
Yes |
Fully supported. |
|
Yes |
Fully supported. |
|
Yes |
Fully supported. |
|
Yes |
Fully supported. |
|
Yes |
Fully supported. |
|
Yes |
Fully supported. |
|
Yes |
Last fully supported in QUARC 2018. |
See Also
Copyright ©2024 Quanser Inc. This page was generated 2024-10-17. Submit feedback to Quanser about this page.
Link to this page.