Example #1
0
   def write_4byte_data(self, data):
      """write all floats/ints to the serial port"""

      if not self.data_port: return
      if not self.data_port.isOpen(): return

      if self.verb > 4: print '++ writing data to serial port:', data

      dstring = struct.pack('f'*len(data), *data)
      if self.swap: UTIL.swap4(dstring)

      if self.verb > 5: print '++ hex data to serial port:',    \
                        UTIL.data_to_hex_str([ord(v) for v in dstring])

      self.data_port.write(dstring)

      del(dstring)

      return 0
Example #2
0
    def write_4byte_data(self, data):
        """write all floats/ints to the serial port"""

        if not self.data_port: return
        if not self.data_port.isOpen(): return

        if self.verb > 4: print '++ writing data to serial port:', data

        dstring = struct.pack('f' * len(data), *data)
        if self.swap: UTIL.swap4(dstring)

        if self.verb > 5:            print '++ hex data to serial port:',    \
            UTIL.data_to_hex_str([ord(v) for v in dstring])

        self.data_port.write(dstring)

        del (dstring)

        return 0
Example #3
0
   def read_ints_from_socket(self, nvals):
      """try to read nvals (4-byte) integers from data socket,
         possibly byte-swapping

         return a list of integers (None on error)"""

      if nvals <= 0: return []

      data = self.read_nbytes_from_data_socket(nvals*4)  # read all bytes
      if not data:
         if self.verb > 0: print "** failed to read %d int(s)" % nvals
         return None

      # swap one value at a time
      vals = []
      if self.swap: UTIL.swap4(data)

      vals = list(struct.unpack('i'*nvals,data))
      del(data)

      if self.verb > 3: print "++ read %d ints: %s" % (nvals, vals)

      return vals
Example #4
0
    def read_ints_from_socket(self, nvals):
        """try to read nvals (4-byte) integers from data socket,
         possibly byte-swapping

         return a list of integers (None on error)"""

        if nvals <= 0: return []

        data = self.read_nbytes_from_data_socket(nvals * 4)  # read all bytes
        if not data:
            if self.verb > 0: print "** failed to read %d int(s)" % nvals
            return None

        # swap one value at a time
        vals = []
        if self.swap: UTIL.swap4(data)

        vals = list(struct.unpack('i' * nvals, data))
        del (data)

        if self.verb > 3: print "++ read %d ints: %s" % (nvals, vals)

        return vals