LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 03-12-2019, 05:16 AM   #1
Mantabit
LQ Newbie
 
Registered: Jan 2019
Location: Europe
Distribution: Ubuntu
Posts: 9

Rep: Reputation: Disabled
Reading serial data from ttyACM0


Hello everyone

I am trying to read data from a sensor which appears as /dev/ttyACM0. One my first laptop, I am able to read data via:

Code:
cat /dev/ttyACM0
If I run this command, I get an output like this (the sensor basically outputs comma seperated values seperated by newline characters):

Quote:
1,0,0,200,200,200
2,0,0,300,400,200
3,0,0,200,200,200
However, when I try the same command on another laptop, I am unable to read anything from the device, the cat command will simply get stuck and not return anything.

I setup the device in the following way on the first computer (the one where it works):

Code:
user@laptop:~$ stty -F /dev/ttyACM0
speed 3000000 baud; line = 0;
min = 0; time = 0;
-brkint -icrnl -imaxbel
-opost
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

On the second computer, I basically set the baudrate to 3000000 and didn't change any other settings:

Code:
user@ThinkPad-T550:~$ stty -F /dev/ttyACM0
speed 3000000 baud; line = 0;
eof = ^A; min = 1; time = 0;
-brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
I guess I have to use stty to change the settings for the port on the computer on which I can't read the data?
 
Old 03-14-2019, 06:32 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,801

Rep: Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002Reputation: 8002
Quote:
Originally Posted by Mantabit View Post
Hello everyone
I am trying to read data from a sensor which appears as /dev/ttyACM0. One my first laptop, I am able to read data via:
Code:
cat /dev/ttyACM0
If I run this command, I get an output like this (the sensor basically outputs comma seperated values seperated by newline characters):
Code:
1,0,0,200,200,200
2,0,0,300,400,200
3,0,0,200,200,200
However, when I try the same command on another laptop, I am unable to read anything from the device, the cat command will simply get stuck and not return anything. I setup the device in the following way on the first computer (the one where it works):
Code:
user@laptop:~$ stty -F /dev/ttyACM0
speed 3000000 baud; line = 0;
min = 0; time = 0;
-brkint -icrnl -imaxbel
-opost
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
On the second computer, I basically set the baudrate to 3000000 and didn't change any other settings:
Code:
user@ThinkPad-T550:~$ stty -F /dev/ttyACM0
speed 3000000 baud; line = 0;
eof = ^A; min = 1; time = 0;
-brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
I guess I have to use stty to change the settings for the port on the computer on which I can't read the data?
Yes, you have to get those settings correct, but there may be other issues. First, what version/distro of Linux are you using on both of those systems? What kind of device? Assuming it's a USB connected serial device. Does the output of dmesg tell you anything different between the systems? (run "sudo dmesg -c" on both systems with the device unplugged, then insert the device and run "dmesg" again). And what program is talking to this device?

Might want to install minicom since it was created to talk to serial devices. You can play with the settings, and at least see what you're getting in real-time, without the 'cat' statement.
 
1 members found this post helpful.
Old 03-14-2019, 06:46 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,885
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Both of the different settings are output settings, so I'm not sure they're going to make much of a difference.

For instance, on the system where it works, you could add an EOF character and add the -onlcr attribute, and I bet it will continue to work.

Use the "raw" setting for stty to make the terminal go to raw mode, this is fairly common and in the library functions, there is a cfmakeraw() call. Look under the termios.h library functions.

Overall, I agree with TB0ne.

First: Do you know that it is identified as /dev/ttyACM0 on both machines? There may be other devices using that same device ID, so therefore check your system logs to verify that this device is exactly that designation on both systems.
 
1 members found this post helpful.
  


Reply



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
read serial file /dev/ttyACM0 best way g_paschoal Programming 1 09-16-2013 11:16 AM
[SOLVED] Serial port : Read data problem, not reading complete data anujmehta Linux - Networking 5 09-06-2010 06:10 AM
/dev/ttyACM0 in Hardware Info, but not present in /dev list linuxdreamz Linux - Newbie 4 08-17-2006 02:29 PM
kernel 2.6.x udev and missing /dev/input/ttyACM0 prefas Linux - General 2 03-17-2005 09:13 AM
/dev/ttyACM0 ankscorek Slackware 3 02-27-2005 01:14 AM

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

All times are GMT -5. The time now is 09:41 PM.

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