LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 07-15-2018, 06:17 AM   #1
Irbis
Member
 
Registered: Jul 2018
Posts: 34

Rep: Reputation: Disabled
reading/writing to serial port doesn't work


Hi. I use Ubuntu 16.04. In the first terminal I wait for data:
Code:
cat </dev/ttyS0
Then in the second terminal I try to send data to the serial port:
Code:
echo -e '123' > /dev/ttyS0
but data is not visible in the first terminal. I have added myself to the group dialout for /dev/ttyS0.

Additional info:
dmesg | grep ttyS
Code:
[    0.684920] 00:06: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
stty -F /dev/ttyS0 -a
Code:
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O;
min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc
ifconfig -a
Code:
enp0s25   Link encap:Ethernet  HWaddr d0:50:99:5e:47:a7  
          inet addr:192.168.0.164  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: 2a02:a31a:a043:6d80:8f91:68c2:9a1d:1b86/64 Scope:Global
          inet6 addr: 2a02:a31a:a043:6d80:81a4:6233:ff1f:6b9a/64 Scope:Global
          inet6 addr: fe80::1942:8c1c:9235:bbe7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9231 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6295 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:9029350 (9.0 MB)  TX bytes:809689 (809.6 KB)
          Interrupt:20 Memory:f7300000-f7320000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:966 errors:0 dropped:0 overruns:0 frame:0
          TX packets:966 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:90014 (90.0 KB)  TX bytes:90014 (90.0 KB)
Why reading/writing to the serial port doesn't work ?

Last edited by Irbis; 07-15-2018 at 06:18 AM.
 
Old 07-15-2018, 06:41 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Welcome to LinuxQuestions.

You need a physical loopback plug attached to the serial port connector to see data. Here is a pin out of the plug wiring.

http://www.bb-elec.com/Learning-Cent...-DB9-DB25.aspx

It is also easier to use a terminal program like minicom to test the serial port. With a loopback plug the characters are displayed as soon as they are typed on the keyboard.
 
Old 07-15-2018, 09:32 AM   #3
Irbis
Member
 
Registered: Jul 2018
Posts: 34

Original Poster
Rep: Reputation: Disabled
Is it possible to buy such connector ? My PC has a female com port so I need a male connector.

Last edited by Irbis; 07-15-2018 at 09:36 AM.
 
Old 07-15-2018, 09:50 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Since the IBM standard uses a male connector I think it would be difficult to find a male loopback to purchase. You probably need to purchase a female connect and a gender changer.

It depends on what you are actually trying to accomplish. If you disable hardware control you can jumper pins 2-3 to see characters as they are typed.
 
Old 07-15-2018, 12:20 PM   #5
Irbis
Member
 
Registered: Jul 2018
Posts: 34

Original Poster
Rep: Reputation: Disabled
Gender changer is easy to get, I have also found the following connector. Is it what I need ?

What do you mean by "disable hardware control"? Could you explain it ?
 
Old 07-15-2018, 12:50 PM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
probably this helps: http://tldp.org/HOWTO/Serial-HOWTO-9.html
I think that is the right connector, but you can find an interesting comment there (probably a damaged one only)
 
Old 07-15-2018, 01:09 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Yes, however one of the comments shows this particular model using a strange wiring layout out which may be ok.

The RS-232 uses several wires to control data flow over the data pins. Since suggested just using a jumper to connect the RX to TX pins you need to disable hardware flow control since those pins are unused and you will be able to transmit data.

https://en.wikipedia.org/wiki/RS-232
 
Old 07-19-2018, 03:42 PM   #8
Irbis
Member
 
Registered: Jul 2018
Posts: 34

Original Poster
Rep: Reputation: Disabled
I have performed another test: I have connected to my pc usb to serial adapter which is connected with mentioned above loopback connector. Instead of ttyS0 I use ttyUSB0. It works but when I send some message:
Code:
echo -e '123' > /dev/ttyUSB0
on reading terminal
Code:
cat </dev/ttyUSBO
message is displayed multiple times and it looks like I get white spaces in a loop (infinitely). What is going on ?

Last edited by Irbis; 07-19-2018 at 03:58 PM.
 
Old 07-19-2018, 03:48 PM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Yes it should work in theory.

How are you reading/writing to the serial port. Have you given permission to your regular user to read/write to the USB adapter which is typically /dev/ttyUSB0?
 
Old 07-19-2018, 03:53 PM   #10
Irbis
Member
 
Registered: Jul 2018
Posts: 34

Original Poster
Rep: Reputation: Disabled
Please see my answer update. I have forgotten to use ttyUSB0 instead of ttyS0
 
Old 07-19-2018, 03:59 PM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
using echo and cat in the terminal is not very reliable for testing serial ports in my opinion. As suggested earlier use minicom. You need to configure the serial port but it will show characters as they are typed.
 
Old 07-19-2018, 04:26 PM   #12
Irbis
Member
 
Registered: Jul 2018
Posts: 34

Original Poster
Rep: Reputation: Disabled
minicom with echo works fine.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
writing to /reading from serial port abd_bela Programming 1 07-26-2012 09:09 AM
[SOLVED] Writing ok on a serial port, reading garbage JeToMad Programming 12 03-28-2012 02:11 AM
Darn serial port doesn't work with minicom jblc Linux - Hardware 1 07-08-2010 01:59 AM
Reading and Writing to a Serial Port without SU Steef223 Programming 2 06-16-2008 09:16 AM
Facing problems in reading from and writing to serial port. vineel Linux - Hardware 2 02-27-2008 02:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 01:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration