Things in the /etc/inittab are automatically
respawned when they fail.  That's its main job.

Your script closes the file between the stty and
the read loop.  You are counting on the settings
being persistent.  That's why I used the exec in
my last example.

Alternately, the last "done" could be "done </dev/ttyUSB0",
and take out the other input redirections.  What you
want is a single program entity that's operating on
the intended device.

I think your 10-second retry would work, but be sure
that the USB device doesn't end up as your controlling
terminal, giving your script a SIGHUP when it's disconnected.

You need to read up on the TTY driver, a ^D will likely
also end the read loop.

-- Jim



-----Original Message-----
From: Michael Hagedorn [mailto:[email protected]] 
Sent: Thursday, March 25, 2010 2:00 PM
To: [email protected]
Cc: Cathey, Jim; Michael Abbott; [email protected]
Subject: Re: Logging serial port data to file

Thanks a lot for your input, I will try them tonight and report back
which one works the best.

Another thing is that if somebody pulls out the usb 2 serial adapter
the script fails and exits.
I want it to continue or restart if the device has been put back.

I have come up with this (but haven't tried it yet):

while true; do

    # Make sure the boudrate is set correctly
    stty -F /dev/ttyUSB0 57600

    while read -r; do
        echo "[$(date)]: $REPLY"
    done </dev/ttyUSB0 >>/usb/BigDrive/CurrentCost/CurrentCost.log

    # Try again in 10 seconds
    sleep 10
done


Rather than trying to read from /dev/ttyUSB0 is there a way to check whether
it is connected?


Regards

On 26 March 2010 06:34, Doug Clapp <[email protected]> wrote:
>
>
> Cathey, Jim wrote:
>>>
>>> Is there an easy way to disregard lines that contain only control
>>> characters or filter the text?
>>>
>>
>> Not trivially.  As you've been shown, "tr -d" is your
>> buddy.
>
> Another possibility is to pipe through dos2unix (rather than tr) to remove 
> the CR characters. Ultimately you have to decide which method works best for 
> you.
>
> Doug Clapp

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to