1) cat /dev/ttyS0
2) while 1; do
read ID < /dev/ttyS0
echo ID
done
Plese, help, I don't know what to do. This script is for embbed device
http://www.atmel.com/dyn/products/tools_card.asp?tool_id=4057.
Consult documentation "man stty" or "info stty" regarding "raw" mode.
Probably something like this is necessary:
< /dev/ttyS0 ( stty raw; read ID; echo ID )
--
Don't you mean LF? That's what should end a line.
> so I'm not able to use anything from this:
> 1) cat /dev/ttyS0
> 2) while 1; do
> read ID < /dev/ttyS0
Do you know how many characters you must read? In that case using
the '-n' option for read should do the trick, e.g. if it's 8 use
read -n 8 ID < /dev/ttyS0
I guess that you also have to specify the number of chars to read
with pySerial's read() method (the readline() method would require
a '\n' at the end which doesn't seem to exist).
Just out of curiosity: how do you set up the communication para-
meters (baud rate, parity, number of stop bits etc.) for the
serial port using bash?
Regards, Jens
--
\ Jens Thoms Toerring ___ j...@toerring.de
\__________________________ http://toerring.de
"The big key on the right" of a keyboard (perhaps labeled as Enter
or Return) sends '\r'. By default, the input canonicalization software
of a UNIX-like system changes '\r' to '\n' on tty connections.
This is the same software which echoes characters from stdin to stdout
(so that a typist can see them), and processes Backspace (erase previous
character), Ctrl-C (generate SIGINT), etc. The documentation refers
to this as "cooked" mode; the other mode is "raw" mode, which does
almost no processing at all (no echo, no erase, no signals, etc.)
The programming interface to this is through ioctl(); the command-line
interface is through /bin/stty.
> Just out of curiosity: how do you set up the communication para-
> meters (baud rate, parity, number of stop bits etc.) for the
> serial port using bash?
Use /bin/stty on an open fd (such as stdin), then don't close
that fd before using it (because the parameters will be reset
to the defaults by the operating system at the next open().)
Thus the usage
< /dev/ttyS0 ( stty ...; <commands>... )
where the shell opens /dev/ttyS0 once, the stty sets the parameters
for stdin, and the following commands use stdin without re-opening it.
--
Tomáš Kavalek wrote:
> I have one big problem with reading serial port in BASH only. If I
Took me about one hour to get it working ;-) OK, lets start by setting
the port's parameters:
stty -F /dev/ttyS0 ispeed 9600 ospeed 9600 -ignpar cs8
-cstopb -echo
In my case 9600 baud, no parity, one stop bit.
Then I wrote the data I need to send into a file (using hexedit) and
send the file's contents:
cat commando0.dat > /dev/ttyS0
For reading, I must refer you to the other posts ;-)
Have fun!
> Tom???? Kavalek wrote:
>> I have one big problem with reading serial port in BASH only. If I
>
> Took me about one hour to get it working ;-) OK, lets start by setting
> the port's parameters:
>
> stty -F /dev/ttyS0 ispeed 9600 ospeed 9600 -ignpar cs8
> -cstopb -echo
>
> In my case 9600 baud, no parity, one stop bit.
>
> Then I wrote the data I need to send into a file (using hexedit) and
> send the file's contents:
>
> cat commando0.dat > /dev/ttyS0
One thing you might want to be aware of is that closing/opening
the serial port device has side effects (e.g. DTR changing
state). Depending on the connected device, you _may_ need to
avoid things like DTR toggling in the midst of the
conversation. There are a couple ways to do that:
* You can run all the command within a shell with stdin/stdout
redirected to the serial port:
(stty -F /dev/ttyS0 ispeed 9600 ospeed 9600 -ignpar cs8 -cstopb -echo
[shell read/write commands]
) </dev/ttyS0 >/dev/ttyS0
* You can write a small program that opens the serial port and
holds it open (without doing an read/write calls on it). As
long as at least one process has the device open, others can
open/close it without causing side effects like DTR
toggling.
--
Grant Edwards grante Yow! I'm in direct contact
at with many advanced fun
visi.com CONCEPTS.
#!/bin/bash
# Port setting
stty -F /dev/ttyS1 raw speed 9600
# Loop
while [ 1 ]; do
READ=`dd if=/dev/ttyS1 count=1`
echo $READ
done