I have a device which is /dev/ttyACM0. I can "screen" to this device screen /dev/ttyACM0
and interact with the device. I need to be able to script the sending of a simple command and capture the response. The command is simple, like type "ver" and hit return, the device responds with a numerical version value. It works in screen.
I am trying to script this in bash, and cannot seem to figure out how to make it work. stuff like echo "ver" > /dev/ttyACM0
produces nothing. I have tried print, same thing. Can someone point me at how to do this?
In Unix/Linux everything is a file. Every time you echo to a device (/dev) you are opening for writing, then writing an the closing. A simple way to catch the output of a device is as simple as
this will cat the output and keep the device open.
As an example, in my case, I have one project that read sensors in an Arduino and in parallel send the information to a server and also the serial port.
Now, serial ttys need to match speed on the os and the device. So sometimes you do not get the output unless you have the right speed and setting. if you type in a terminal
you will get the current speed configuration.
So, you could try something like this (but not always work)
updated ++
in my case that shell output this (it will no take the ver command as it is not implemented, but after that reads from the tty whatever the tty is sending). With the change tail stops earlier and output gets truncated at 2 seconds
Again, the -f flag keeps the terminal open but, if I take it off I get nothing (I lost the buffer output)
That is why I think a small c program will do better.
Hope this helps.
Many device access problems can be resolved through group membership changes.
Specifically, if
ls -l
shows that the group permissions (the second "rwx
" triplet) is "rw
" (e.g."-rw-rw----
"), then, adding oneself to the group that owns the device will grantrw
access.Here's how:
This allows you membership in the group that can
rw
the device, but there is one more step.To make all your processes members of the new group, logout and login. Group memberships are set up at
login
time.To create a single process in the new group (for testing, prior to logout/login):
or, just type the group name. See
man newgrp
.