Scanserial
EMAC provides a tool named scanserial
to assist a user in finding out which device nodes on a computer correspond to its serial ports, and in finding out which particular device node corresponds to a particular serial port. The scanserial
tool was created because no existing tool provides this functionality in a convenient way. Other methods for determining this all require a slow trial and error approach.
This guide walks the reader through the steps required to perform these tasks using the EMAC scanserial
tool.
Contents
Background
Linux systems use virtual files to provide device nodes which represent hardware devices attached to a system. These device nodes reside in the /dev
directory. Each device node corresponds to one device, or to one endpoint within a device.
The serial ports typically are represented by device nodes with one of the two following naming schemes:
- Standard Serial Devices
/dev/ttyS
*- USB Serial Devices
/dev/ttyUSB
*
Any given system may have one or both of these types of serial devices attached to it. Serial ports provided by a motherboard or add-in PCI/PCIe card are classified in this document as Standard Serial Devices. USB to serial devices, including USB devices which provide several serial ports, are classified in this document as USB Serial Devices.
Serial devices normally provide a character device (rather than a block or FIFO). Each device node describes the type of device it is associated with, in this case character, and has an associated major and minor magic number. The magic numbers are used to identify to the operating system kernel the specific device on the system to which the device node corresponds. Further details about device nodes are beyond the scope of this document, but can be found on this site and elsewhere in documentation on Linux device drivers.
General Information
The scanserial
tool is provided by EMAC to assist customers in getting a development environment set up. Since scanserial
is an EMAC provided tool, you will need to install it unless you are using an EMAC LDC (which has it pre-installed).
If your Ubuntu machine isn't already configured to use the EMAC apt repository for installing software, you will need to follow this guide on how to do so. When your system is configured for the EMAC apt repository, you can install the scanserial
tool by installing the emac-tools-util
project. To install it with apt-get
on the command line, run:
developer
@
developerpc
:
~
#
sudo apt-get install emac-tools-util
Alternatively, you may open the Ubuntu Software Center and search for the emac-tools-util
project. Clicking on the search result will provide you with an option to install the package. Click the Install button to install it.
scanserial
The scanserial
utility has a few options which allow you to customize the behavior of scanserial
or find out more about it. The list below describes these options.
- -v, --verbose
- Display verbose output. When displaying a list of devices, this will show metadata associated with each device node.
- -c, --color
- Displays output in color (if available).
- -f, --find-loopback
- Uses the same algorithm which is used to find a list of serial port device nodes, then scans the list of device nodes for loopback devices. Displays every device it finds which appears to have a loopback attached. Note that this can be fooled by connected devices which echo input back to the port, such as a logged in console on a board.
- -h, --help
- Displays help for using the scanserial tool.
- -l, --list-serials
- Lists the serial device nodes found in /dev which appear to be serial ports. If combined with the verbose option, this will also show metadata about each one. Add the color switch to colorize the output to make it easier to read.
- --version
- Displays the version number of the scanserial tool.
Return Value
The return value of scanserial
corresponds to the success of its operation. If the operation succeeded, it returns zero, as is the customary behavior for all *nix software. If it fails, it will return a value greater than zero (which is also the standard behavior for software on Linux systems).
Examples
Listing Available Serial Ports
Use the -l
(lowercase L) option to list available serial ports. Here, there are 6 standard serial ports and 8 USB serial ports available.
developer
@
developerpc
:
~
#
scanserial -l
/dev/ttyS0 /dev/ttyS1 /dev/ttyS4 /dev/ttyS5 /dev/ttyS6 /dev/ttyS7 /dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2 /dev/ttyUSB3 /dev/ttyUSB4 /dev/ttyUSB5 /dev/ttyUSB6 /dev/ttyUSB7
developer
@
developerpc
:
~
#
Listing Detailed Information About Serial Ports
The verbose option, --verbose
or -v
, causes scanserial
to output much more detailed information.
developer
@
developerpc
:
~
#
scanserial -lv
/dev/ttyS0: type: 4 line: 0 port: 1016 irq: 4 flags: 0x10000040 xmit_fifo_sz: 16 custom_divisor: 0 baud_base: 115200 close_delay: 50 closing_wait: 3000
/dev/ttyS1: type: 4 line: 1 port: 760 irq: 3 flags: 0x10000040 xmit_fifo_sz: 16 custom_divisor: 0 baud_base: 115200 close_delay: 50 closing_wait: 3000
developer
@
developerpc
:
~
#
Further output, in this example, was truncated for the sake of brevity.
Finding an Attached Loopback
When you need to figure out which device node corresponds to the specific one you wish to use, which can be especially difficult when you have a lot of serial ports (like the 14 on the system shown above), a loopback is very useful. A loopback is a connection between the Rx and Tx lines on a serial port. Many large vendors sell RS-232 serial loopback dongles. In a pinch, you can make your own loopback by connecting the Rx and Tx lines together with a wire.
Once you have a loopback connected to the desired port, run the scanserial
command with the --find-loopback
or -f
(the shortened abbreviated version) argument:
developer
@
developerpc
:
~
#
scanserial -f
Found loopback on /dev/ttyUSB0
developer
@
developerpc
:
~
#