[SOLVED] Problem testing serial program I am writing in C
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a small program that opens and listens to serial ports. I developed it on a virtual machine and to test it I opened terminal windows using \\.\pipe\com1 (/dev/ttyS0) etc. All this works flawlessly in my VM but when I moved my code over to raspian (Stretch) I am unable to send data using
Code:
screen /dev/ttyUSB1 19200.
My program sets /dev/ttyUSB1 to 19200 but stty reports it as 9600 even when my program is running.
Your error-checks are broken: open(2) returns -1 on error; read(2) returns -1 on error, 0 on end-of-file, positive value means length of the data read in.
Also you left out the switch to raw mode https://www.systutorials.com/docs/li...n/3-cfmakeraw/
Nonethess, you still read 4 bytes, but they might be non-printable characters. Use printf's %x in a loop.
Your error-checks are broken: open(2) returns -1 on error; read(2) returns -1 on error, 0 on end-of-file, positive value means length of the data read in.
Also you left out the switch to raw mode https://www.systutorials.com/docs/li...n/3-cfmakeraw/
Nonethess, you still read 4 bytes, but they might be non-printable characters. Use printf's %x in a loop.
I corrected the error check and there is no error opening /dev/ttyUSB1.
the write returned that 4 bytes where written.
the read returned 0 bytes where read.
no error with either write or read.
the stty is for /dev/ttyUSB1 after cfmakeraw()
I am getting some more serial cables and null modem adapters to test this using a seperate system rather than screen() or a test program running on the same system.
I corrected the error check and there is no error opening /dev/ttyUSB1.
the write returned that 4 bytes where written.
the read returned 0 bytes where read.
no error with either write or read.
the stty is for /dev/ttyUSB1 after cfmakeraw()
I am getting some more serial cables and null modem adapters to test this using a seperate system rather than screen() or a test program running on the same system.
Once I connected my laptop to the PI I was able to sucessfully test my program. I suspect that however you write to /dev/ttyUSBx you cannot read "that" data back unless the port is set up for loop back because all programs are running on the host side of the UART.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.