Python - USB to RS232 for lock-in amplifier, can write commands but not read.

Thread Starter

las39

Joined Oct 6, 2021
7
I'm trying to control an SR830 lock-in amplifier (LIA) with Python script. I am using the packages PyMeasure and PyVISA. My connection is USB to RS232. I can write commands to the LIA but when I try to read from the LIA I get the error below.
Note: I believe the issue is the rv value; it is supposed to be >0 but it looks like its
-1073807339.
I think I have defined the serial port parameters correctly:
adapter = VISAAdapter('ASRL3::INSTR', baud_rate=9600, data_bits=8, flow_control=1, parity=Parity.none, stop_bits=StopBits.one)
Like I said, I can write just fine but reading is the issue. Maybe I need to install a driver or change something about how to interpret the message from the LIA?
I didn't change the instrument.py, visa.py, messagebased.py, highlevel.py codes, they came with the packages.
Any help is appreciated, thank you.



VisaIOError Traceback (most recent call last)
<ipython-input-3-275122865b50> in <module>
----> 1 LIA.ask("*IDN?")
2 print
("ok")

C:\ProgramData\Anaconda3\lib\site-packages\pymeasure\instruments\instrument.py in ask(self, command)
90
:param command: command string to be sent to the instrument
91 """

---> 92 return self.adapter.ask(command)
93
94
def write(self, command):

C:\ProgramData\Anaconda3\lib\site-packages\pymeasure\adapters\visa.py in ask(self, command)
110
:returns: String ASCII response of the instrument
111 """

--> 112 return self.connection.query(command)
113
114
def ask_values(self, command, **kwargs):

C:\ProgramData\Anaconda3\lib\site-packages\pyvisa\resources\messagebased.py in query(self, message, delay)
642 time
.sleep(delay)
643

--> 644 return self.read()
645
646 def query_ascii_values(

C:\ProgramData\Anaconda3\lib\site-packages\pyvisa\resources\messagebased.py in read(self, termination, encoding)
484
if termination is None:
485 termination
= self._read_termination
--> 486 message = self._read_raw().decode(enco)
487
else:
488
with self.read_termination_context(termination):

C:\ProgramData\Anaconda3\lib\site-packages\pyvisa\resources\messagebased.py in _read_raw(self, size)
440 status
,
441 )

--> 442 chunk, status = self.visalib.read(self.session, size)
443 ret
.extend(chunk)
444
except errors.VisaIOError as e:

C:\ProgramData\Anaconda3\lib\site-packages\pyvisa_py\highlevel.py in read(self, session, count)
517 )
518

--> 519 return data, self.handle_return_value(session, status_code)
520
521
def write(self, session: VISASession, data: bytes) -> Tuple[int, StatusCode]:

C:\ProgramData\Anaconda3\lib\site-packages\pyvisa\highlevel.py in handle_return_value(self, session, status_code)
249
250
if rv < 0:
--> 251 raise errors.VisaIOError(rv)
252
253
if rv in self.issue_warning_on:

VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
 

michael8

Joined Jan 11, 2015
415

Thread Starter

las39

Joined Oct 6, 2021
7
I can set the LIA frequency using the Python code. I say LIA.frequency=10000 and the frequency output actually becomes 10000 Hz.
 

Thread Starter

las39

Joined Oct 6, 2021
7
"
a. I can run python code which is supposed to write to the SR830 and I can see on the SR830 that the write
had the effect it was supposed to.
"

I can set the LIA frequency using the Python code. I say LIA.frequency=10000 and the frequency output actually becomes 10000 Hz.
Looking at Device Manager under Ports (COM & LPT), it shows the USB (COM10) and says that I have the Prolific driver installed and "this device is working properly". The cable is the Tripp-Lite
 
Top