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 08-19-2022, 02:22 PM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 924

Rep: Reputation: 61
Talking Is there a way for me to poll the incoming data on a serial port to a file?


Presently I am getting the weight reported by a large legal for trade scale over the serial port using

Code:
sudo cat /dev/ttyUSB0
The problem is that it seems to be actively updating the screen with the reported weight changes. I intend to create an ajax long polling script that runs every few seconds from apache to check what the current weight on the scale is. The most obviously solution to me is to have the above command continually output the value to a script, continually overwriting it's contents with the latest reported number.

I feel like this should be simple but I don't quite understand why `cat` doesn't terminate like normal when I run it against normal text files.

Any tips in the right direction greatly appreciated.
 
Old 08-19-2022, 02:57 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,905

Rep: Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371
As I posted in your other thread in my follow up post I suspected the serial port was configured for a remote display which always outputs a reading. Since the serial port outputs continuous data there isn't an EOF or the like so it doesn't terminate. Do you know if serial port has other output modes?

Using cat or bash IMHO usually doesn't work very well with serial ports and using a programming language with serial port support is better.
 
1 members found this post helpful.
Old 08-19-2022, 03:02 PM   #3
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 924

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by michaelk View Post
As I posted in your other thread in my follow up post I suspected the serial port was configured for a remote display which always outputs a reading. Since the serial port outputs continuous data there isn't an EOF or the like so it doesn't terminate. Do you know if serial port has other output modes?

Using cat or bash IMHO usually doesn't work very well with serial ports and using a programming language with serial port support is better.
It does have other modes, but when I set it to "stabilize" (as in, once the weight has stabilized, it sends a single weight to the serial port, but it never sends back the zero when the weight is removed from the scale, it will only send the next weight greater than zero which is not optimal for my use case).

I am thinking I may want to just run `cat` command for 5 seconds at a time, log that data to a txt file, and then have apache/php read the latest line. A bit jank, was hoping for something a bit more elegant.

I see in the manual for the scale it can be configured to send a "stop bit". Is that something that can send an End Of File? Manual here: https://www.ohaus.ca/pdf/3000-Series-Indicators-Man.pdf (section 3.8 Print Menu)

Last edited by wh33t; 08-19-2022 at 03:05 PM.
 
Old 08-19-2022, 03:22 PM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,968
Blog Entries: 13

Rep: Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007Reputation: 5007
Memory serves I used to use like tail -f
 
Old 08-19-2022, 03:24 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,905

Rep: Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371
See sections 5.1 and 5.2, looks like there is a way to poll for data. I am guessing if auto print is off you can send commands.

The stop bit is part of the RS-232 protocol that defines how data is sent.
 
1 members found this post helpful.
Old 08-19-2022, 03:28 PM   #6
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 924

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by michaelk View Post
See sections 5.1 and 5.2, looks like there is a way to poll for data. I am guessing if auto print is off you can send commands.

The stop bit is part of the RS-232 protocol that defines how data is sent.
Amazing! I never thought I'd be able to send commands to the scale to request data back.

How would I go about (or what should I search for) sending commands and receiving output from this thing?

Something like

Code:
echo "P" > /dev/ttyUSB0
?
 
Old 08-19-2022, 03:35 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,905

Rep: Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371Reputation: 6371
A suggest a real language because using bash can be unreliable. Using Python should be fairly easy.
 
  


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
How to Communicate Virtual Serial Port on Host(windows) to Communicate with Virtual Serial Port on Guest System(Linux) aquamarine Linux - Newbie 2 09-16-2016 02:48 PM
Fastest method to write incoming serial data to an sd card - data logger jwmueckl Linux - General 11 05-19-2016 10:22 AM
Four-port KVM switch that sends keyboard data to PS2 port and mouse data to USB port Ulysses_ Linux - Hardware 5 06-20-2015 11:16 AM
Is a USBtty (USB serial port) treated the same as tty (normal serial port) in C? spudgunner Programming 1 11-12-2010 01:19 PM
saving incoming serial data to a file mssucks Linux - Networking 1 12-14-2001 10:56 AM

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

All times are GMT -5. The time now is 11:59 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