Open daturach opened 3 years ago
When reading a fixed number of bytes PyVISA will by default try to read exactly that number. You can pass break_on_termchar= True
to stop early but in that case make sure to set the proper termchar (see below).
This behavior comes from the fact that read_bytes is kind of low-level and meant for debugging/special purpose in pyvisa. If you goal is simply to read your instrument answer but ignore the \n (meaning there are not termination characters). You can do the following:
instr.read_termination = None
msg = instr.read_raw() # If you want bytes
# msg = inst.read() # if you prefer text
Hello
Thanks for the quick answer. I have tried the following and still no success: It doesn't stop after the first \n
import pyvisa as visa
rm = visa.ResourceManager('@py')
#print(rm.list_resources()) # bug, see https://github.com/pyvisa/pyvisa-py/issues/282
instr = rm.open_resource('GPIB0::6::INSTR')
instr.read_termination = '\n' # from github https://github.com/pyvisa/pyvisa-py/issues/283
instr.write_termination = '\n'
instr.write('BUS?')
print(instr.read_bytes(33, break_on_termchar=True))
instr.close()
Result:
b'MSR 000,OUTM 000\nEOI ON,SPR 010\n'
I need to be able to read a line without knowing in advance how many chars are going to be sent. I can then easily split at any chars. Thanks
That looks better:
import pyvisa as visa
rm = visa.ResourceManager('@py')
#print(rm.list_resources()) # bug, see https://github.com/pyvisa/pyvisa-py/issues/282
instr = rm.open_resource('GPIB0::6::INSTR')
instr.write('BUS?')
print(instr.read_raw()) # If you want bytes; from github https://github.com/pyvisa/pyvisa-py/issues/283
instr.close()
Result:
b'MSR 000,OUTM 000\nEOI ON,SPR 010\n'
Thanks for your help.
I took the liberty to edit the title so that I can try to come back later and fix the handling of the termchar.
Hello
I have an old Philips PM6666 counter connected to a GPIB PCI board (old as well...). I have installed pyvisa and linux-gpib. I have 2 different py scripts that should give the same results, one for the linux-gpib python binding and the other one for pyvisa. Here are the different scenarios: (notice the number of chars read)
Python bindings:
Result:
b'MSR 000,OUTM 000\nEOI ON,SPR 010\n'
pyvisa:
Result:
b'MSR 000,OUTM 000\nEOI ON,SPR 010\n'
The result is the same. Now change line in pyvisa script.
print(instr.read_bytes(33))
toprint(instr.read_bytes(35))
Result:
I wonder why the end of line is not detected.
Output python3 -m visa info
Thanks for your help.