Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

screen /dev/ttyUSB0 with different options such as databit, parity, etc

I am trying to use

screen /dev/ttyUSB0

to connect to a old computer(s) through a USB-serial interface.

I am hoping that registering on this site I will receive answers to my question. I have searched and searched, but have not figured out to put the correct options in my command line to get a non-gibberish feedback from my computer (the text received is all screwed up).

My operating system is CentOs, Gnome 2.16.0. I see that there is a program called KPPP which has a "Terminal...", but haven't figured that one out either. So I am trying to use CLI with 'screen', but I am having trouble setting the correct parameters (obviously, I do not understand how to put these parameters to use with stty). It is not an option installing applications or doing anything with this computer, so I have to use what's already there. 'screen' seems to do the job, but the text received is gibberish as mentioned earlier ("$$@%idj ldj" etc.)

I need these parameters for computer one:

Baud: 9600 Databit: 8 Parity: No Stopbit: 2 Flow control: Hardware.

For computer two I need:

Baud: 9600 Databit: 7 Parity: Even Stopbit: 1 Flow control: Hardware

The baud rate is easy;

screen /dev/ttyUSB0 9600

But what to do with the rest, I do not know. . I have found the option for stop bits:

cstopb (use two stop bits)

-cstopb (use one stop bits)

But how do I use it correctly?

screen /dev/ttyUSB0 9600 -cstopb

or

screen /dev/ttyUSB0 9600,-cstopb

So if someone could help me out connecting to the other computer through serial interface with all of the listed parameters I would be very thankfull!

Update 22. dec 2016:

I have found this manual for stty: http://osr507doc.sco.com/man/html.C/stty.C.html

Is databit the same as this option?

   cs5 cs6 cs7 cs8
        Select character size (see termio(M)). 

Parity:

   parodd (-parodd)
         Select odd (even) parity. 

Stopbit:

   cstopb (-cstopb)
         Use two (one) stop bits per character. 

But what about hardware control?

Anyways; this is still not working;

screen /dev/ttyUSB0 9600 cs8 oddp cstop 

or

   screen /dev/ttyUSB0 9600 cs7 evenp -cstop
like image 952
Jon-Wilhelm Johansen Schweder Avatar asked Dec 21 '16 15:12

Jon-Wilhelm Johansen Schweder


People also ask

What is serial port parity?

Parity is a method of detecting errors in transmission. When parity is used with a serial port, an extra data bit is sent with each data character, arranged so that the number of 1 bits in each character, including the parity bit, is always odd or always even.

What were serial ports used for?

From Day One of the personal computer, serial ports were used to transfer the data from computers to various external devices, such as modems and input devices like keyboards and mice. These ports are controlled by a UART (Universal Asynchronous Receiver Transmitter) chip.

How do I set baud rate?

In order to change the baud rate of the Serial Monitor, go to Tools -> Serial Monitor (or press Ctrl+Shift+M alternatively). Make sure you have a board connected to your PC/Laptop, or the Serial Monitor won't open. Also, make sure that the Port corresponds to the connected board.


2 Answers

I don't think screen has support for all these different serial port settings, only the most basic parameters are supported. You're already in the correct direction by looking at the stty manual, but you have to use stty as a separate tool from screen: First you configure your serial port, then you connect to it using screen.

To configure your serial port for computer 1:

# stty - change and print terminal line settings
#
#    -F /dev/ttyUSB0      Change the settings of /dev/ttyUSB0
#    cs8                  Use 8 character bits
#    -parenb              Don't use a parity bit (the '-' means 'disable')
#    crtscts              Enable RTS/CTS handshaking (hardware flow control)
stty -F /dev/ttyUSB0 cs8 -parenb cstopb crtscts

After you've configured your port, you can start using it trough screen:

# screen - screen manager with VT100/ANSI terminal emulation
#
#    /dev/ttyUSB0         Use /dev/ttyUSB0 as terminal
#    9600                 Open the serial port using 9600 baud
screen /dev/ttyUSB0 9600

The same applies for your second computer:

# stty - change and print terminal line settings
#
#    -F /dev/ttyUSB0      Change the settings of /dev/ttyUSB0
#    cs7                  Use 7 character bits
#    parenb               Enable the a parity bit
#    -parodd              Don't use ODD, but use EVEN parity
#    -cstopb              Don't use 2 stopbits, but just the regular 1
#    crtscts              Enable RTS/CTS handshaking (hardware flow control)
stty -F /dev/ttyUSB0 cs7 parenb -parodd -cstopb crtscts

Then you can launch screen @9600 baud:

# screen - screen manager with VT100/ANSI terminal emulation
#
#    /dev/ttyUSB0         Use /dev/ttyUSB0 as terminal
#    9600                 Open the serial port using 9600 baud
screen /dev/ttyUSB0 9600

This should do the trick. You can find much more configuration options in the help of stty:

stty --help
like image 100
Jeroen Meulemeester Avatar answered Sep 30 '22 11:09

Jeroen Meulemeester


Comma between options are required!

To enable RTS/CTS flow control use the following:

screen /dev/ttyS0 9600,crtscts

Note: Not all USB to RS232 converters implement the hardware flow control!

like image 42
Gábor Avatar answered Sep 30 '22 12:09

Gábor