def _send_and_read(self, message): ''' Performs the communication with the device 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(__name__ + ' : do communication with instrument') vpp43.write(self._vi, message) sleep(0.1) data_out_string = vpp43.read( self._vi, vpp43.get_attribute(self._vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM)) sleep(0.1) data_out_numbers = [ord(s) for s in data_out_string] if (data_out_numbers[1] != 0) or (len(data_out_numbers) != data_out_numbers[0]): logging.error(__name__ + ' : Error while reading : %s', data_out_numbers) return data_out_numbers
def _empty_buffer(self): ''' empty buffer of COM port ''' logging.debug(__name__ + ' : do communication with instrument') data_out_string = vpp43.read(self._vi, vpp43.get_attribute(self._vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM)) return data_out_string
def _empty_buffer(self): ''' empty buffer of COM port ''' logging.debug(__name__ + ' : do communication with instrument') data_out_string = vpp43.read( self._vi, vpp43.get_attribute(self._vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM)) return data_out_string
def __init__(self, resource_name, timeout=10000): """ @timeout in milliseconds """ self._resource_name = resource_name self._timeout = timeout # Check model code to make sure we are using the right command language vi = vpp43.open(visa.resource_manager.session, resource_name) model_code = vpp43.get_attribute(vi, vpp43.VI_ATTR_MODEL_CODE) vpp43.close(vi) if model_code != self._model_code: raise OceanOpticsError('The spectrometer reported a different ' 'model code ({}) than the driver expected ' '({}).'.format(model_code, self._model_code)) self._vi = None # connection not currently open
def _read_reply(self, max_sleeps=100): ''' Read reply from the Zaber. <max_sleeps> is the maximum number of 50msec sleeps. The default is 100 for a maximum delay of 5 seconds. ''' i = 0 while i < max_sleeps: navail = vpp43.get_attribute(self._visa.vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM) if navail >= 6: reply = vpp43.read(self._visa.vi, navail) reply = [ord(ch) for ch in reply] return reply i += 1 time.sleep(0.05) return None
def _read_buffer(self): ''' Returns a string containing the content of the buffer Input: None Output: buffer (string) : data in buffer ''' logging.debug(__name__ + ' : Reading buffer') tekst = vpp43.read(self._vi,vpp43.get_attribute(self._vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM)) sleep(0.05) if (tekst==''): return tekst elif (tekst[0]=='E'): logging.error(__name__ + ' : An error occurred during \ readout of instrument : ' + tekst) else: return tekst
def _read_buffer(self): ''' Returns a string containing the content of the buffer Input: None Output: buffer (string) : data in buffer ''' logging.debug(__name__ + ' : Reading buffer') tekst = vpp43.read( self._vi, vpp43.get_attribute(self._vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM)) sleep(0.05) if (tekst == ''): return tekst elif (tekst[0] == 'E'): logging.error(__name__ + ' : An error occurred during \ readout of instrument : ' + tekst) else: return tekst
def _send_and_read(self, message): ''' Performs the communication with the device 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(__name__ + ' : do communication with instrument') vpp43.write(self._vi, message) sleep(0.1) data_out_string = vpp43.read(self._vi, vpp43.get_attribute(self._vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM)) sleep(0.1) data_out_numbers = [ord(s) for s in data_out_string] if (data_out_numbers[1] != 0) or (len(data_out_numbers) != data_out_numbers[0]): logging.error(__name__ + ' : Error while reading : %s', data_out_numbers) return data_out_numbers
def autodetect_spectrometer(resource_name, *args, **kwargs): """ Factory method which creates an appropriate instrument object, depending on the model code that the unit identifies itself with. """ vi = vpp43.open(visa.resource_manager.session, resource_name) model_code = vpp43.get_attribute(vi, vpp43.VI_ATTR_MODEL_CODE) vpp43.close(vi) if model_code == 4098: return USB2000(resource_name, *args, **kwargs) if model_code == 4100: return ADC1000(resource_name, *args, **kwargs) if model_code == 4106: return HR2000(resource_name, *args, **kwargs) if model_code == 4114: return HR4000(resource_name, *args, **kwargs) if model_code == 4118: return HR2000Plus(resource_name, *args, **kwargs) if model_code == 4120: return QE65000(resource_name, *args, **kwargs) if model_code == 4126: return USB2000Plus(resource_name, *args, **kwargs) if model_code == 4130: return USB4000(resource_name, *args, **kwargs) if model_code == 4134: return NIRQuest512(resource_name, *args, **kwargs) if model_code == 4136: return NIRQuest256(resource_name, *args, **kwargs) if model_code == 4138: return MayaPro(resource_name, *args, **kwargs) if model_code == 4140: return Maya(resource_name, *args, **kwargs) if model_code == 4160: return Torus(resource_name, *args, **kwargs) raise visa.VisaIOError(OO_ERROR_MODEL_NOT_FOUND)
def _clear_buffer(self): navail = vpp43.get_attribute(self._visa.vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM) if navail > 0: reply = vpp43.read(self._visa.vi, navail)
def _read_buffer(self): response=vpp43.read(self._vi, vpp43.get_attribute(self._vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM)) sleep(self._sleeptime) return response
def get_navail(visains): ''' Return number of bytes available to read from visains. ''' return vpp43.get_attribute(visains, vpp43.VI_ATTR_ASRL_AVAIL_NUM)
def _read_buffer(self): response = vpp43.read( self._vi, vpp43.get_attribute(self._vi, vpp43.VI_ATTR_ASRL_AVAIL_NUM)) sleep(self._sleeptime) return response