Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _open_serial_connection(self):
'''
Opens the ASRL connection using vpp43
baud=115200, databits=8, stop=one, parity=odd, no end char for reads
Input:
None
Output:
None
'''
logging.debug('Opening serial connection')
self._session = vpp43.open_default_resource_manager()
self._vi = vpp43.open(self._session, self._address)
vpp43.set_attribute(self._vi, vpp43.VI_ATTR_ASRL_BAUD, 115200)
vpp43.set_attribute(self._vi, vpp43.VI_ATTR_ASRL_DATA_BITS, 8)
vpp43.set_attribute(self._vi, vpp43.VI_ATTR_ASRL_STOP_BITS,
vpp43.VI_ASRL_STOP_ONE)
vpp43.set_attribute(self._vi, vpp43.VI_ATTR_ASRL_PARITY,
vpp43.VI_ASRL_PAR_ODD)
vpp43.set_attribute(self._vi, vpp43.VI_ATTR_ASRL_END_IN,
vpp43.VI_ASRL_END_NONE)
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 _open_serial_connection(self):
'''
Opens the ASRL connection using vpp43
baud=19200, databits=8, stop=one, parity=even, no end char for reads
Input:
None
Output:
None
'''
logging.debug(__name__ + ' : opening connection')
self._session = vpp43.open_default_resource_manager()
self._vi = vpp43.open(self._session, self._address)
vpp43.set_attribute(self._vi, vpp43.VI_ATTR_ASRL_BAUD, 19200)
vpp43.set_attribute(self._vi, vpp43.VI_ATTR_ASRL_DATA_BITS, 8)
vpp43.set_attribute(self._vi, vpp43.VI_ATTR_ASRL_STOP_BITS,
vpp43.VI_ASRL_STOP_ONE)
vpp43.set_attribute(self._vi, vpp43.VI_ATTR_ASRL_PARITY,
vpp43.VI_ASRL_PAR_EVEN)
vpp43.set_attribute(self._vi, vpp43.VI_ATTR_ASRL_END_IN,
vpp43.VI_ASRL_END_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 _open_serial_connection(self):
'''
Opens the ASRL connection using vpp43
baud=115200, databits=8, stop=one, parity=odd, no end char for reads
Input:
None
Output:
None
'''
logging.debug('Opening serial connection')
self._session = vpp43.open_default_resource_manager()
self._vi = vpp43.open(self._session, self._address)
vpp43.set_attribute(self._vi, vpp43.VI_ATTR_ASRL_BAUD, 115200)
vpp43.set_attribute(self._vi, vpp43.VI_ATTR_ASRL_DATA_BITS, 8)
vpp43.set_attribute(self._vi, vpp43.VI_ATTR_ASRL_STOP_BITS,
vpp43.VI_ASRL_STOP_ONE)
vpp43.set_attribute(self._vi, vpp43.VI_ATTR_ASRL_PARITY,
vpp43.VI_ASRL_PAR_ODD)
vpp43.set_attribute(self._vi, vpp43.VI_ATTR_ASRL_END_IN,
vpp43.VI_ASRL_END_NONE)
def _doRead(bytes):
if bytes is None:
ans = instr.read()
else:
ans = vpp43.read(instr.vi, bytes)
return ans
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)
Input:
tekst (string) : data to be written to the instrument
Output:
None
'''
logging.debug(__name__ + ' : Start running _write_to_instrument with:' + tekst)
# clear buffer
logging.debug(__name__ + ' : clearing buffer')
restbuffer = self._read_buffer()
sleep(0.05)
if (restbuffer!=''):
logging.error(__name__ + ' : Buffer contained unread data : ' +
restbuffer)
logging.debug(__name__ + ' : writing to vpp43')
vpp43.write(self._vi, tekst)
sleep(0.05)