Difference between revisions of "Scanserial"

From wiki.emacinc.com
Jump to: navigation, search
m (Initial Content.)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{todo| InProgress (11.04.2015-12:17->MD+)|Mike Dean| project=OE 5.0,MD,InProgress }}
+
{{todo| Complete (11.04.2015-12:17->MD+);(11.05.2015-11:05->MD+);(11.05.2015-17:15->KY+);(11.06.2015-13:50->MG+)|Mike Dean| project=OE 5.0,MD,KY,Complete }}
 
{{#seo:
 
{{#seo:
 
|title=scanserial
 
|title=scanserial
Line 10: Line 10:
 
<!-- /****************************************  Page Description Text  ****************************************/ -->
 
<!-- /****************************************  Page Description Text  ****************************************/ -->
 
<!-- /*********************************************************************************************************/ -->
 
<!-- /*********************************************************************************************************/ -->
EMAC provides a tool named <code>scanserial</code> 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 <code>scanserial</code> 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.
+
EMAC provides a tool named <code>scanserial</code> 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 <code>scanserial</code> 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 <code>scanserial</code> tool.
 
This guide walks the reader through the steps required to perform these tasks using the EMAC <code>scanserial</code> tool.
  
 
__TOC__
 
__TOC__
 
 
<!-- /*********************************************************************************************************/ -->
 
<!-- /*********************************************************************************************************/ -->
 
<!-- /***************************************** Background Information ****************************************/ -->
 
<!-- /***************************************** Background Information ****************************************/ -->
Line 22: Line 21:
  
 
Linux systems use virtual files to provide device nodes which represent hardware devices attached to a system.  These device nodes reside in the <code>/dev</code> directory.  Each device node corresponds to one device, or to one endpoint within a device.
 
Linux systems use virtual files to provide device nodes which represent hardware devices attached to a system.  These device nodes reside in the <code>/dev</code> directory.  Each device node corresponds to one device, or to one endpoint within a device.
 +
 +
Software which wishes to use a hardware device will <code>open()</code> the virtual file, call <code>ioctl()</code> on it to control aspects of the I/O operations, and <code>read()</code> and <code>write()</code> data through the file descriptor acquired in the <code>open()</code> 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:
 
The serial ports typically are represented by device nodes with one of the two following naming schemes:
Line 32: Line 33:
 
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.
 
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.
+
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.
  
 
<!-- /*********************************************************************************************************/ -->
 
<!-- /*********************************************************************************************************/ -->
Line 41: Line 42:
 
The <code>scanserial</code> tool is provided by EMAC to assist customers in getting a development environment set up.  Since <code>scanserial</code> is an EMAC provided tool, you will need to install it unless you are using an EMAC LDC (which has it pre-installed).
 
The <code>scanserial</code> tool is provided by EMAC to assist customers in getting a development environment set up.  Since <code>scanserial</code> 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 [[Getting_Started_with_the_EMAC_OE_SDK| follow this guide]] on how to do so.  When your system is configured for the EMAC apt repository, you can install the <code>scanserial</code> tool by installing the <code>emac-tools-util</code> project.  To install it with <code>apt-get</code> on the command line, run:
+
If your Ubuntu machine isn't already configured to use the EMAC apt repository for installing software, you will need to [[Install_the_EMAC_SDK#Install_Using_apt_.28Recommended.29| follow this guide]] on how to do so.  When your system is configured for the EMAC apt repository, you can install the <code>scanserial</code> tool by installing the <code>emac-tools-util</code> package.  To install it with <code>apt-get</code> on the command line, run:
  
{{cli|username=developer|hostname=developerpc| sudo apt-get install emac-tools-util}}
+
{{cli|username=developer|hostname=developerpc|sudo apt-get install emac-tools-util}}
  
 
Alternatively, you may open the Ubuntu Software Center and search for the <code>emac-tools-util</code> project.  Clicking on the search result will provide you with an option to install the package.  Click the <b>Install</b> button to install it.
 
Alternatively, you may open the Ubuntu Software Center and search for the <code>emac-tools-util</code> project.  Clicking on the search result will provide you with an option to install the package.  Click the <b>Install</b> button to install it.
Line 67: Line 68:
  
 
;-l, --list-serials
 
;-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.
+
: Lists the serial device nodes found in <code>/dev</code> 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
 
;--version
Line 83: Line 84:
 
====Listing Available Serial Ports====
 
====Listing Available Serial Ports====
  
Use the <code>-l</code> (lowercase L) option to list available serial ports.  Here, there are 8 standard serial ports and 8 USB serial ports available.
+
Use the <code>-l</code> (lowercase L) option to list available serial ports.  Here, there are 6 standard serial ports and 8 USB serial ports available.
  
{{clo}}
+
{{clop}}
{{clio|username=developer|hostname=developerpc|scanserial -l}}
+
{{cliop|username=developer|hostname=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
+
/dev/ttyS0
{{clos}}
+
/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
 +
{{cliop | username=developer | hostname=developerpc |}}
 +
{{closp}}
 +
 
 +
<br />
  
 
====Listing Detailed Information About Serial Ports====
 
====Listing Detailed Information About Serial Ports====
Line 95: Line 112:
  
 
{{clop}}
 
{{clop}}
{{cliop | username=developer | hostname=developerpc | scanserial -lv }}
+
{{cliop | username=developer | hostname=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
 +
{{cliop | username=developer | hostname=developerpc |}}
 
{{closp}}
 
{{closp}}
 +
<br />
 +
''Further output, in this example, was truncated for the sake of brevity.''
  
''Further output was truncated for the sake of brevity in this example.''
+
====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 <code>scanserial</code> command with the <code>--find-loopback</code> or <code>-f</code> (the shortened abbreviated version) argument:
 +
 +
{{clop}}
 +
{{cliop | username=developer | hostname=developerpc |scanserial -f}}
 +
/dev/ttyUSB6 : Found!
 +
{{cliop | username=developer | hostname=developerpc |}}
 +
{{closp}}
 +
<br />
 +
If you have multiple loopbacks attached, they will all show up in the output list.  If you wish to ensure that <code>scanserial</code> is checking every device node you're expecting it to check, you can add the verbose flag (<code>--verbose</code> or <code>-v</code> for short) when you call <code>scanserial</code>.  For example, if you have two loopbacks attached and call <code>scanserial</code> with the verbose flag set, it might look like this:
 +
 +
{{clop}}
 +
{{cliop | username=developer | hostname=developerpc |scanserial -fv }}
 +
/dev/ttyS0 : no
 +
/dev/ttyS1 : no
 +
/dev/ttyS4 : no
 +
/dev/ttyS5 : no
 +
/dev/ttyS6 : no
 +
/dev/ttyS7 : no
 +
/dev/ttyUSB0 : no
 +
/dev/ttyUSB1 : no
 +
/dev/ttyUSB2 : Found!
 +
/dev/ttyUSB3 : no
 +
/dev/ttyUSB4 : no
 +
/dev/ttyUSB5 : no
 +
/dev/ttyUSB6 : Found!
 +
/dev/ttyUSB7 : no
 +
{{cliop | username=developer | hostname=developerpc | }}
 +
{{closp}}
  
  
Line 107: Line 171:
 
<!-- /*********************************************************************************************************/ -->
 
<!-- /*********************************************************************************************************/ -->
 
{{:Templateimpl:conclusion | initials=MD | title=scanserial | desc=Using scanserial to find your serial ports. | project=OE 5.0 }}
 
{{:Templateimpl:conclusion | initials=MD | title=scanserial | desc=Using scanserial to find your serial ports. | project=OE 5.0 }}
 +
 +
The <code>scanserial</code> 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.
  
 
<!-- /*********************************************************************************************************/ -->
 
<!-- /*********************************************************************************************************/ -->
Line 112: Line 178:
 
<!-- /*********************************************************************************************************/ -->
 
<!-- /*********************************************************************************************************/ -->
 
{{:Templateimpl:moreinfo | initials=MD | title=scanserial | desc=Using scanserial to find your serial ports. | project=OE 5.0 }}
 
{{:Templateimpl:moreinfo | initials=MD | title=scanserial | desc=Using scanserial to find your serial ports. | project=OE 5.0 }}
*  
+
* [[Serial_Connections | Making Serial Connections to EMAC OE Linux 5.x Machines]]
 +
* [[System_Log_In | Logging Into an EMAC OE Linux 5.x Machine]]
 +
* [[Network_Connections | Connecting an EMAC OE Linux 5.x Machine to a Network]]
 +
* [[Network_Configuration | Configuring Networking]]
  
 
{{:Templateimpl:whatnext | initials=MD | title=scanserial | desc=Using scanserial to find your serial ports. | project=OE 5.0 }}
 
{{:Templateimpl:whatnext | initials=MD | title=scanserial | desc=Using scanserial to find your serial ports. | project=OE 5.0 }}
*
+
* [[Example_serial_test | Example Serial Communications Program]]
 +
* [[Quick_Reference | EMAC Quick Reference]]

Latest revision as of 13:51, 6 November 2015

TODO: {{#todo: Complete (11.04.2015-12:17->MD+);(11.05.2015-11:05->MD+);(11.05.2015-17:15->KY+);(11.06.2015-13:50->MG+)|Mike Dean|OE 5.0,MD,KY,Complete}}

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 scanserial tool.

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.

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 read() 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
/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.

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.

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 package. 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 or jumper.

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

/dev/ttyUSB6 : Found!

developer@developerpc:~#


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 (--verbose or -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:

developer@developerpc:~# scanserial -fv

/dev/ttyS0 : no /dev/ttyS1 : no /dev/ttyS4 : no /dev/ttyS5 : no /dev/ttyS6 : no /dev/ttyS7 : no /dev/ttyUSB0 : no /dev/ttyUSB1 : no /dev/ttyUSB2 : Found! /dev/ttyUSB3 : no /dev/ttyUSB4 : no /dev/ttyUSB5 : no /dev/ttyUSB6 : Found! /dev/ttyUSB7 : no

developer@developerpc:~#


Conclusion

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

Further Information

Where to Go Next
Pages with Related Content