[Cialug] tornado-proofing your data?
Matthew Nuzum
newz at bearfruit.org
Thu May 29 12:23:41 CDT 2008
On Thu, May 29, 2008 at 9:58 AM, Dave J. Hala Jr. <dave at 58ghz.net> wrote:
> I still have yet to figure how to collect wind speed data using a linux
> box. Anyone know of some Linux software that collects data from a serial
> port and dumps it into a .csv file? At the moment, I take the .csv file
> from a windows box, copy it onto a thumb drive, carry it over to a linux
> box and import the data into a Mysql database.
I use python. For example:
import serial
ser = serial.Serial('/dev/ttyUSB0',115200)
# my application won't start sending until prompted to do so
ser.write('1')
try:
while (1):
data = ser.readline().strip()
try:
T,X,Y,Z = data.split(',')
do_something()
except(ValueError):
print data
pass
except(KeyboardInterrupt):
print "closing serial port..."
ser.close()
I use this to read data from a microcontroller connected via USB
serial port. The data in my application comes in a somewhat CSV format
so I just split it using a comma.
do_something() for you could be insert the data into mysql directly.
If you decide to play with it and get stuck you should ask for help on
the list because I know there are a couple of us here that are into
this kind of thing. And because it's python you could start out
experimenting in Windows/sqlite and migrate to Linux/mysql pretty
easily.
Look into the timeout property for Serial if you have problems with it
hanging. (Thanks to Nathan Stein for that tip)
--
Matthew Nuzum
newz2000 on freenode
More information about the Cialug
mailing list