• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Get output from serial connection

Red Squirrel

No Lifer
I can write a C++ app for this, but I'm just wondering if there is a native way with the command line to send a command to a serial interface (arduino in this case) and get a response?

I've actually used echo and cat before with other devices but it does not seem to work with this one. Probably because of the way the data is sent. (baud rate etc)

I also have picocom installed and I can always install another terminal emulator so if one of those tools has the option that will do too. Just thought I'd check before I code an app.
 
From a shell script I would say that echo/cat are the native ways to interact with a serial device. If you need to set specific parameters before them then use setserial to do that, but there should be no reason that echo/cat don't work as long as you can encode/decode the data to whatever format the device needs within a script.
 
I noticed if I do cat /dev/port and then echo stuff to it from another window, it works. But if I echo stuff and then do cat after, it does not. Think I'll just end up coding it into my app, I already have a serial library I wrote so may as well just use that.
 
GNU screen... one of the many things it does.

screen /dev/someport <speed> <otherstuffifneeded (handshaking, parity, etc)>


edit: picocom does this too, does it not? and you mention it in your first post, so I'm not sure what you actually want. Care to elaborate?


edit2:.. ah, saw later post. presuming you don't want interactive. like in a shell script? then yeah, echo/cat is it man.

Played with it a bit with loopback.. if I echo something to the port and have cat running, works fine. if I try to cat it after the fact (or read, or dd)... there's nothing there. Guess it doesn't buffer if the file isn't open..?

so i guess you'd have to have cat open, backgrounded, writing to a temp file, and cat from it later.


like this:

Code:
% cat /dev/ttyUSB0 > /tmp/serial.tmp&

% echo "anandtech" > /dev/ttyUSB0
% cat /tmp/serial.tmp
anandtech

My bashfu is shit, so there is probably a better way. I'd just do it in C :awe:
 
Last edited:
I noticed if I do cat /dev/port and then echo stuff to it from another window, it works. But if I echo stuff and then do cat after, it does not. Think I'll just end up coding it into my app, I already have a serial library I wrote so may as well just use that.

Of course it doesn't work if cat isn't running, the serial driver doesn't hold the data indefinitely until you read it. Think of it as a FIFO or pipe, if the other end isn't listening when the data's sent it misses it.
 
Back
Top