Advertisement
tomearp

simple python script to pull data from a USB GPS stick

Jul 30th, 2012
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. import serial
  2.  
  3. def getdata(port):
  4. # open the serial port
  5.     port.open()
  6. # check that the port is open
  7.     if port.isOpen():
  8. # read 16 lines
  9.         line = []
  10.         for i in range(1,16):
  11.             line.append(port.readline())
  12. # close the serial port
  13.     port.close()
  14. # discard the first line (sometimes it contains rubbish, so just always discard it)
  15.     del line[0]
  16. # return the list of lines
  17.     return line
  18.  
  19. def outputdata(data):
  20. # print the list of lines
  21.     for i in range(0,len(data)):
  22.         print data[i]
  23.  
  24. def initialise():
  25. # initialise serial port settings
  26.     Port = serial.Serial()
  27.     Port.baudrate = 4800
  28.     Port.port = '/dev/ttyUSB0'
  29.     Port.xonxoff = 1
  30. # return the port as an object we can use
  31.     return Port
  32.  
  33. # main program starts here
  34. sPort = initialise()
  35. data = getdata(sPort)
  36. outputdata(data)
  37. # end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement