Advertisement
Guest User

whatever and ever amen

a guest
Dec 29th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. import serial
  2. import time
  3. import datetime
  4. import sys
  5.  
  6. class UARTGet:
  7.  
  8.   def getData(self):
  9.     return serialD.readline().rstrip()
  10.  
  11.  
  12.   #device is full devfs path /dev/ttyX
  13.   def __init__(self,device,baud):
  14.     try:
  15.       self.serialD = serial.Serial(device,baud)
  16.  
  17.     except:
  18.       print "Error connecting to %s" % device
  19.       sys.exit(9)
  20.  
  21. uarty = UARTGet("/dev/ttyUSB0",115200)
  22. filedump = "/tmp/rawdata"
  23.  
  24. while True:
  25.   with open(filedump, 'a') as wFD:
  26.     stringy = "%s,%s\n" % ( str(datetime.datetime.now().strftime("%y-%m-%d-%H:%M"), str(uarty.getData()) )
  27.     wFD.write(stringy)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement