58 LXF249 May 2019 http://www.linuxformat.com
TUTORIALS Debug serial comms
Theeasiestwaytodetermineif theoperating system
detectstheUSBcable/adaptordeviceistoinstall the
deviceaftera reboot.Installingit beforea reboot
causesthedevicedetailstobeconsolidatedinside
otherbootmessagecontent.
Froma commandlineinterfacetype dmesg. If the
cable/adapterwaspluggedintothePCbefore bootup,
thedetailswewantareembeddedinthedmesg listing.
Forthenoviceit’smucheasiertopluginthecable/
adapteraftera rebootandthenrundmesg. The new
devicedetailswillbeattheendofthelisting.
Fromtheinformationreturnedyoucanextract
whichchipset/UARTisinthecable/adapter.The
detailswillalsoidentifywhichcommunication port
hasbeenassigned.Youarelookingforsomething
like‘ttyUSB’,suffixedwithanassignmentnumber –
forexample,ttyUSB0.
Forthenextstepintroubleshootingweare going to
useanapplicationcalledPutty– itsUImakesit easy to
configuretheports.Thegoalistoconfirmthat software
onthehostPCcancommunicatethrougha USB-to-
serialadapter.OncePuttyisinstalled,openthe
application. Select ‘Serial’ in the ‘Connection type’
choices. In the ‘Serial line’ field, enter the COM port
details you have recorded previously. Proceed to the
serial connection screen. The most common, default
setup is 9600baud 8N1. The number sequence
translation means: eight bits of data, no stop bits, one
parity bit.
Give the session configuration a name and save it.
The session configuration is not saved by default when
you leave the application; if you don’t save the session,
you’ll need to input the configuration again next time.
heitchforanarticleontroubleshootingUSB-
to-serialconnectionsneededtobescratched,
afterworkingona requestforassistancefrom
a localmodelrailroadgroup(seeLXF239). Thistutorial
willprovidetheknowledgetotroubleshoot
communication(comms)issuesfromanappona PC
toa serialdevice,usinga USB-to-serialcable/interface.
Inthediagramshownbelow,thereisa PCrunning
anapplicationthatrequiresa serialinterface.ThePC
isconnectedtotheserialdevice,shownonthefarright
sideofthedrawing,usinga USB-to-serialcable/
interface.Thedrawingcontainsa fewadditionaldetails
thatwillbeintroducedasourdiscussionexpands.
HardwareinthePCsupportedserialcomms;atone
pointduringtheevolutionofthePC,a minimumoftwo
DB9ports(the9-pinCOMport)wasconsidered
standard.Theredhighlightedtextinthediagramare
someexamplesofCOMportcommunicationneeds.
Butallthingscometoanend,andtheubiquitousUSB
portsoonreplacedCOMports.Toconsolidateallthe
differentserialdevicecommsrequirements,a USB-to-
serialcable/adaptorcameintoplay.Unfortunately,this
generic serial comms doesn’t always work, and it can be
frustrating trying to isolate the root cause of serial
communication failure.
After connecting the USB-to-serial cable to the host
PC, the first step is to determine if the OS recognises
the USB-to-serial adaptor. In Linux, the dmesg
command reveals information regarding hardware
detection, driver assignments and communication port
allocation. It is important to take note of what COM port
(COM1, 2, 4 or so on) is used – this will be needed to
support our efforts, as well as set up the application.
Serial connection
path mapping,
with additional
landmarks shown.
Debug serial comms
SeanD.Conway
is a retired IT
security specialist
who now
exercises
his brain by
mining knowledge
through
Raspberry Pi
projects.
T
COMMS
OUR
EXPERT
Sean Conway walks you through the process of troubleshooting
communication problems between a PC application and a serial device.
Serial Application
(Putty)
Data
Data
DB9Connector
(jumperfortesting)
+
PC
CH341 Chip
USB Connector Device Connector
Serial Connection
(USB to Serial cable/adapter)
CD 11 CD
RxD 22 RxD
TxD^33 TxD
DTR^44 DTR
SG^55 SG
DSR^66 DSR
RTS 77 RTS
CTS 88 CTS
RI 99 RI
Serial Device
NULL Modem (DCC)
(Optional)
UART/RS232/
RS485/RS422
Parallel printer to
USB printer
EPP parallel and
MEM parallel
synchronous serial2wire/4wire
6915