Logging serial port data to file

Michael Hagedorn michael at hagedorn.co.nz
Thu Mar 25 20:59:34 UTC 2010


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 <doug.clapp at triad.rr.com> 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


More information about the busybox mailing list