OpenWrt Forum Archive

Topic: How to read data from the serial port and write it to a text file

The content of this topic has been archived on 27 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello all,

We are using SOM9331 module and we need to read data from the serial port and write it to a text file.We have written script in /etc/hotplug.d/tty to read data.

Script:
#!/bin/sh
stty -F /dev/ttyATH0 9600
cat /dev/ttyATH0 > /status.txt

When it receives serial data it appending the data at the end of the file instead of overwriting the content of the file.can anyone let me know how to overwrite the content of file instead of appending to it.

Thanks!!

The script you have will overwrite each time it stops and then restarts.  As long as the cat is active it will continue to append unless it is stopped.   It will take something much more complex if you want each occurrence of data that appears on the serial port in its own file.

The discussion might have continued from here.