I am trying to use the 'pyvisa' library from within Matlab to communicate with VISA-supported instruments on the local network. Some of these instruments are attached through a GPIB-Ethernet bridge, while others are directly connected through TCPIP.
To load the 'pyvisa' library in Matlab, I use
pyvisa = py.importlib.import_module('pyvisa');
rm = pyvisa.ResourceManager();
From here, one can open instruments by either specifying the fully-qualified VISA identifier or the alias defined, for example, in Keysight Connection Expert.
handle = rm.open_resource('GPIB_AliasName');
handle2 = rm.open_resource('TCPIP0::K-12345B-12345::5025::SOCKET');
When it comes to communicating with the instrument, there appears to a difference between those connected through GPIB (using the network bridge) and those via TCPIP, such as the 'handle2' instrument above.
As an example, issuing a command such as
handle.query('*IDN?')
results in the return of the instrument identifier (as a Python string, py.str), while the following
handle2.query('*IDN?')
times out.
One of the properties of the VISA object (as created using pyvisa) in Matlab is the 'read_termination' and 'write_termination'. Setting the former to '\n' results in parts of the queried identifier to be returned, but broken up into odd chunks, such as
>> handle2.query('*IDN?')
ans =
Python str with no properties.
Agilen
which should have read 'Agilent Technologies,33522B,MYxxxxx,3.05-1.19-2.00-52-00', and is being read back as such doing the same from a Python interpreter. I played with the termination string, using both '\n', '\r', and '\r\n', as well as these being passed by first converting them to Python strings via py.str('\n'), etc. Nothing works.
Ideas on what to try next would be greatly appreciated.
Thanks
p.s.: Calling a Python function from within Matlab that sets the read termination once for each instrument handle resolves the issue described above, which points towards a translation problem of the '\n' string passed from Matlab to the Python pyvisa object.