I'm still new to python and instrument controlling and I'm facing some issues that I couldn't find answers to yet. I'm using PyVisa to control a monochromator (Spectral Products dk240) via rs232. (Python 3.5, PyVisa 1.8)
I can write commands and read the response by setting the right termination character. The problem is that sometimes the instrument response is a single byte without termination, and then I get a timeout (even though I see the response I want on a port monitor).
I tried to use read_raw to get the single byte but it doesn't work. Here's a simple version of my code:
import pyvisa
rm = pyvisa.ResourceManager()
instrument = rm.open_resource('ASRL1::INSTR')
instrument.baud_rate= 9600
instrument.data_bits=8
instrument.stop_bits = pyvisa.constants.StopBits.one
instrument.parity = pyvisa.constants.Parity.none
instrument.read_termination = chr(24) #specified in the manual
instrument.write(chr(33)) # command to get the serial number
instrument.read() # this works!
instrument.write(chr(27)) # echo command
# instrument replies one byte echo (seen on port monitor)
instrument.read_raw(1) # I get a timeout here
and the error:
raise errors.VisaIOError(ret_value)
pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
I also tried to set the termination character to "none" so visa wouldn't wait for it, but still get the timeout. Additionally, I tried to read the serial number with read_raw(1), but instead of one byte I get the full answer from the instrument, why is that?
any help will be greatly appreciated!!!