* Problem with redirecting from serial device
@ 2013-07-18 5:59 Ian Petts
2013-07-18 22:11 ` Phil Pennock
0 siblings, 1 reply; 3+ messages in thread
From: Ian Petts @ 2013-07-18 5:59 UTC (permalink / raw)
To: zsh-users
I have been playing around with weather station receiver software on the
Arduino. The Arduino outputs serial data over USB on device ttyACM0.
The incoming data is not timestamped, so I have a small awk script to add this
as the data is received:
#!/usr/bin/awk -f
{
dt = strftime("%Y-%m-%d %H:%M:%S", systime(), 0)
print dt " " $0
}
When I run the script with output going to the terminal, everything looks to
be working just fine:
ian@nibbler[1568]~% ./dt-add.awk < /dev/ttyACM0
2013-07-18 15:34:18 [OS V3 Sensor Capture/Decode]
2013-07-18 15:35:16 Wind Gust: 2.33 Wind Avg: 2.42 Dir: NW
2013-07-18 15:36:02 Temp: 17.11 Humidity: 61
2013-07-18 15:36:55 Temp: 17.01 Humidity: 61
As soon as I add a redirect or pipe to the above (to save the data to a file
or for further processing) no data appears:
ian@nibbler[1570]~% ./dt-add.awk < /dev/ttyACM0 > weather.out
# A few minutes later
^C
ian@nibbler[1571]~% ls -lh weather.out
-rw-rw-r-- 1 ian ian 0 Jul 18 15:47 weather.out
I don't think it's a file buffering issue, I've left it go for several hours
with the same results. Even if I try 'more'ing the data I seem to get no
output.
Dumping the raw data to a file seems to be fine.
< /dev/ttyACM0 > foo
works as expected.
Can anyone please explain where the issue is?
--
All computers run at the same speed...with the power off.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Problem with redirecting from serial device
2013-07-18 5:59 Problem with redirecting from serial device Ian Petts
@ 2013-07-18 22:11 ` Phil Pennock
2013-07-19 7:34 ` Ian Petts
0 siblings, 1 reply; 3+ messages in thread
From: Phil Pennock @ 2013-07-18 22:11 UTC (permalink / raw)
To: zsh-users
On 2013-07-18 at 15:59 +1000, Ian Petts wrote:
> As soon as I add a redirect or pipe to the above (to save the data to a file
> or for further processing) no data appears:
> I don't think it's a file buffering issue, I've left it go for several hours
> with the same results. Even if I try 'more'ing the data I seem to get no
> output.
To rule it out, could you try gawk explicitly if awk is not gawk?
http://www.perkin.org.uk/posts/how-to-fix-stdio-buffering.html
I hadn't heard of stdbuf before, but like the idea, using an LD_PRELOAD
hack to be able to fix what is a userland problem.
-Phil
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Problem with redirecting from serial device
2013-07-18 22:11 ` Phil Pennock
@ 2013-07-19 7:34 ` Ian Petts
0 siblings, 0 replies; 3+ messages in thread
From: Ian Petts @ 2013-07-19 7:34 UTC (permalink / raw)
To: zsh-users
> > As soon as I add a redirect or pipe to the above (to save the data to a file
> > or for further processing) no data appears:
>
> > I don't think it's a file buffering issue, I've left it go for several hours
> > with the same results. Even if I try 'more'ing the data I seem to get no
> > output.
>
> To rule it out, could you try gawk explicitly if awk is not gawk?
Thanks for the info, Phil. My awk is indeed gawk and I also tried the stdbuf
command per the link you supplied. Unfortunately I am still seeing the same
results.
It is starting to look like a buffering problem, however, because using perl
with output buffering on (the default), does not appear to work
< /dev/ttyACM0 perl -MPOSIX -e '$| = 0;' -pe 'print strftime("%F %T ", localtime)' > weather.out
Turn output buffering off, data is written to the weather.out file
< /dev/ttyACM0 perl -MPOSIX -e '$| = 1;' -pe 'print strftime("%F %T ", localtime)' > weather.out
Either case above without the redirect displays the data to the screen.
--
Who is General Failure and why is he reading my disk?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-07-19 7:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-18 5:59 Problem with redirecting from serial device Ian Petts
2013-07-18 22:11 ` Phil Pennock
2013-07-19 7:34 ` Ian Petts
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).