def _send_and_read(self, message): ''' Send <message> to the device and read answer. Raises an error if one occurred Returns a list of bytes Input: message (string) : string conform the IVVI protocol Output: data_out_numbers (int[]) : return message ''' logging.debug('Sending %r', message) # clear input buffer visafunc.read_all(self._vi) vpp43.write(self._vi, message) # In stead of blocking, we could also poll, but it's a bit slower # print visafunc.get_navail(self._vi) # if not visafunc.wait_data(self._vi, 2, 0.5): # logging.error('Failed to receive reply from IVVI rack') # return False data1 = visafunc.readn(self._vi, 2) data1 = [ord(s) for s in data1] # 0 = no error, 32 = watchdog reset if data1[1] not in (0, 32): logging.error('Error while reading: %s', data1) data2 = visafunc.readn(self._vi, data1[0] - 2) data2 = [ord(s) for s in data2] return data1 + data2
def read(self): data = visafunc.read_all(self._vi) ret = '' for c in data: ret += '%02x,' % c print 'Read %d bytes' % (len(data), ) print 'Data: %s' % (ret, )