VISAInterface: Read/Write Binary configuration
Hi all,
I found that the VISAInterface class thrown an exception when trying to execute the following commands on a Keysight DSOX1202G Oscilloscope.
def set_setup(self, filename):
self.write_binary_file(':SYSTem:SETup ',filename)
def get_setup(self, filename):
self.read_binary_file(":SYSTem:SETup?", filename)
The lines are the following
https://gitlab.com/tackv/spintop-openhtf/-/blob/master/src/spintop_openhtf/plugs/visa.py#L80
https://gitlab.com/tackv/spintop-openhtf/-/blob/master/src/spintop_openhtf/plugs/visa.py#L88
if file_name != "" and command != "":
if read_binary:
self.logger.info('Copying remote file to %s' % file_name)
values = self.instr.query_binary_values(command, datatype='c')
values = bytearray(values) # this function thrown an exception.
with open(file_name, 'wb') as f:
f.write(values)
else:
#Command + binary file
binary = bytes_from_file(file_name)
self.logger.info("Sending binary file: %s<%s>" % (command, file_name))
self.instr.write_binary_values(command, list(binary), datatype='c') # the instrument shown 'Invalid Character'
I fixed it by changing the datatype='c' to datatype='b'.
Here is an extract of the Oscilloscope's Programmer's Guide:
I have 2 suggestions:
- Change the datatype to 'b' if this issue happens with other instruments. Or
- Add 'datatype' as object property so one may define it on the open() function, for example, or as method argument, instead of hardcoding it.
What do you think? Let me know if you need more information.