[WindyCity-pm] Trapping data from the a serial port.
Jonathan Rockway
jon at jrock.us
Thu Dec 20 15:12:21 PST 2007
On Thu, 2007-12-20 at 07:58 -0800, Richard Reina wrote:
> I am trying to find a way to continuously transfer files over a serial
> port. Thanks to Eric and Jonathon yesterday I learened how to send
> and receive files through a serial port. Many thanks. However, due
> to my inability to interpolate variables at the bash command line I
> decided to try:
>
> #!/usr/bin/perl5 -w
>
> use strict;
> while(1) {
>
> my ($yr, $mo, $day, $hr, $min, $sec) = (localtime)[5,4,3,2,1,0];
> my $date = $sec . $min . $hr . $day . ($mo + 1) . ($yr + 1900);
> system("cat /dev/ttyS0 > $date");
>
> }
Two things. First, localtime in scalar context returns a formatted date
string. Secondly, try this in bash:
something > "filename.$(date)"
That will put the output of something into a file named like
"filename.Thu Dec 20 17:10:50 CST 2007". Spaces are irritating, though,
so I do this:
something > "filename.$(date +%s)"
Which yields "filename.1198192282".
Regards,
Jonathan Rockway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://mail.pm.org/pipermail/windycity-pm/attachments/20071220/5c18db88/attachment.bin
More information about the WindyCity-pm
mailing list