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 to assist 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
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.
Software which wishes to use a hardware device will
open() the virtual file, call
ioctl() on it to control aspects of the I/O operations, and
write() data through the file descriptor acquired in the
open() call. The Pages with Related Content section provides a link to an example program which does this, but many more can be found online via your favorite search engine.
The serial ports typically are represented by device nodes with one of the two following naming schemes:
- Standard Serial Devices
- USB Serial Devices
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.
Each device node describes the class of device it is associated with, and has an associated major and minor magic number. Serial devices normally provide a character device, rather than a block or FIFO class device. 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.
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 package. To install it with
apt-get on the command line, run:
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 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
/devwhich 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.
- Displays the version number of the scanserial tool.
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).
Listing Available Serial Ports
-l (lowercase L) option to list available serial ports. Here, there are 6 standard serial ports and 8 USB serial ports available.
Listing Detailed Information About Serial Ports
The verbose option,
scanserial to output much more detailed information.
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 or jumper.
Once you have a loopback connected to the desired port, run the
scanserial command with the
-f (the shortened abbreviated version) argument:
If you have multiple loopbacks attached, they will all show up in the output list. If you wish to ensure that
scanserial is checking every device node you're expecting it to check, you can add the verbose flag (
-v for short) when you call
scanserial. For example, if you have two loopbacks attached and call
scanserial with the verbose flag set, it might look like this:
scanserial tool greatly simplifies the once cumbersome, manual, trial-and-error process of figuring out which of the potentially 100+ device nodes have associated physical serial ports, and which of those is/are the one(s) you're looking for. This freely available tool can save you a great deal of time when configuring serial ports. If you don't need to perform this task right now, perhaps because you're using an EMAC LDC, keeping in mind that EMAC provides this tool may help you save time and frustration at a later date.
Where to Go Next
- Making Serial Connections to EMAC OE Linux 5.x Machines
- Logging Into an EMAC OE Linux 5.x Machine
- Connecting an EMAC OE Linux 5.x Machine to a Network
- Configuring Networking