-
Notifications
You must be signed in to change notification settings - Fork 0
Description
In the tutorial you have an query function with error handling, like this:
def query(self, command, *, send_args=(None, None), recv_args=(None, None)):
answer = super().query(command, send_args=send_args, recv_args=recv_args)
if answer == 'ERROR':
raise InstrumentError
return answer
However not every instrument will send an error back but set an bit in the ESR register
So I propose something like this:
def query(self, command, *, send_args=(None, None), recv_args=(None, None)):
answer = super().query(command, send_args=send_args, recv_args=recv_args)
if answer == 'ERROR':
raise InstrumentError
else:
e = int(super().query("*ESR?"))
if e:
msg = ["*ESR?={}".format(e)]
if e & 1:
msg.append("ERROR: {0}: OPC Operation is complete.".format(self.__class__.__name__))
if e & 4:
msg.append("ERROR: {0}: RQL The device is requesting control.".format(self.__class__.__name__))
if e & 8:
msg.append("ERROR: {0}: QYE A query error has been detected.".format(self.__class__.__name__))
if e & 16:
msg.append("ERROR: {0}: DDE A device-dependent error has been detected.".format(self.__class__.__name__))
if e & 32:
msg.append("ERROR: {0}: EXE An execution error has been detected".format(self.__class__.__name__))
if e & 64:
msg.append("ERROR: {0}: CMD A command error has been detected.".format(self.__class__.__name__))
print('\n'.join(msg))
while True:
errn, errtext = super().query(":STATus:ERRor?").split(',')
errn = int(errn)
if errn != 0:
print("ERROR: {0}: {1} {2}".format(self.__class__.__name__,errn, errtext))
else:
break
raise Exception("Error occured: {0}".format('\n'.join(msg)))
return answer
The first new part will check the ESR bit to see if an error exists and what kind of error it is. The print statement should be changed to the Lanz equivalent logging function.
The second part reads out the Status Error. Depending on the equipment used this might not be supported or use an different command. There could be multiple errors stored therefore a while loop is used. Something similar should be done for the write command, as this can generate errors too.
Do you think this would be worthwhile to integrate into Lanz? And only enable it by the driver if the instrument supports it.
For example the Yokogawa WT310 supports this and the command to read out the error status is ":STATus:ERRor?". The Agilent DSOX-3000 scope has the command "":SYSTem:ERRor?"" for this. And the TTI CPX400P power supply uses "QER?". Therefore each driver should define this error command and if it is defined the errors will be checked as described above.
What do you think something worthwhile to integrate in Lantz?