title: How can I read GPS data under Linux?
body: <p>I used win7 before to read the GPS data from the com port. From now on I would like to read the data under Ubuntu but the same code is not working. Here is my code:</p>
  
  <pre><code>import serial, sys, time, threading
  from datetime import datetime, timedelta    
  
  class MeasureModule():
      def __init__(self, port, baudrate, sync_time=0, sync_nr=0):
          self.port = port;
          self.baudrate = baudrate;
  
      def start(self):
          try:
              self.serial = serial.serial_for_url(self.port, self.baudrate, timeout=1)
          except AttributeError:            
              self.serial = serial.Serial(self.port, self.baudrate, timeout=1)
          start = time.clock()
          while(time.clock()-start&lt;11):     
              data  = self.readline()        
              print(data)
  
          self.stop();                    
  
      def stop(self):
          self.serial.close()   
  
      def readline(self, timeout=1, endline='\n'):
          buff='';
          try:            
              tic = time.clock()
              ch = self.character(self.serial.read(1))
  
              # you can use if not ('\n' in buff) too if you don't like re
              while ((time.clock() - tic) &lt; timeout) and (not ch in endline):
                  buff += ch                
                  ch = self.character(self.serial.read(1))
  
          except serial.SerialException, e:
              return buff
  
          return buff
  
      def character(self,b):
          if sys.version_info &gt;= (3, 0):
              return b.decode('latin1')
          else:
              return b
  </code></pre>
  
  <p>I called the function in the following way:</p>
  
  <pre><code>for i in range (0,4):
      try:    
          print "Starting measurement /dev/ttyACM%d" % i
          gs = GPSModule('/dev/ttyACM%d' % i, 4800, 1, 1)
          gs.start()
      except:
          print "Unable to connect"
  
  run@FXR:/dev$ dmesg  | grep tty
  [    0.000000] console [tty0] enabled
  [    4.764464] cdc_acm 2-1.6:1.1: ttyACM0: USB ACM device
  [    4.767620] cdc_acm 2-1.6:1.3: ttyACM1: USB ACM device
  [    4.771525] cdc_acm 2-1.6:1.9: ttyACM2: USB ACM device
  [    4.808622] usb 2-1.4.4: pl2303 converter now attached to ttyUSB0
  </code></pre>
  
  <p>But I'm not receiving anything. </p>
  
  <p>How can I do the same things under Ubuntu? How can I read the GPS data from com port?</p>