Matlab 2015中的Python VISA。无法阅读

时间:2016-07-05 14:26:11

标签: python matlab sockets tcp visa

我正在尝试使用python VISA 1.8与Matlab 2015b结合使用TTI PL303QMT-P(三电源)。

我在python中完成了我的代码并完美地运行但为了使其工作,我必须将read_termination设置为\ r \ n。 如果我尝试在Matlab中做同样的事情,我可以写入设备,但阅读不起作用。

我在python中的代码:

>>> import visa
>>> rm = visa.ResourceManager()
>>> sup = rm.open_resource("TCPIP::sup6.xxxxxxx::9221::SOCKET")
>>> sup.query("*IDN?")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pyvisa-1.8-py2.7.egg\pyvisa\resources\messagebased.py", line 407, in query
  return self.read()
  File "C:\Python27\lib\site-packages\pyvisa-1.8-py2.7.egg\pyvisa\resources\messagebased.py", line 332, in read
  message = self.read_raw().decode(enco)
  File "C:\Python27\lib\site-packages\pyvisa-1.8-py2.7.egg\pyvisa\resources\messagebased.py", line 306, in read_raw
  chunk, status = self.visalib.read(self.session, size)
  File "C:\Python27\lib\site-packages\pyvisa-1.8-py2.7.egg\pyvisa\ctwrapper\functions.py", line 1582, in read
  ret = library.viRead(session, buffer, count, byref(return_count))
  File "C:\Python27\lib\site-packages\pyvisa-1.8-py2.7.egg\pyvisa\ctwrapper\highlevel.py", line 188, in _return_handler
  raise errors.VisaIOError(ret_value)
  pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
>>> sup.read_termination = '\r\n'
>>> sup.query("*IDN?")
u'THURLBY THANDAR, PL303QMT-P,  406793, 3.02 - 1.00 - 1.02'

在Matlab中,我尝试以下方法:

py.importlib.import_module('visa');
   rm = py.visa.ResourceManager();
   TCPIP = 'TCPIP::sup6.xxxx::9221::SOCKET';
   sup = rm.open_resource(TCPIP);

   sup.read_termination = '\r\n';
   sup.query('*IDN?')

并获得输出:

Error using highlevel>_return_handler (line 188)
Python Error: VisaIOError: VI_ERROR_TMO (-1073807339): Timeout
expired before operation completed.

Error in functions>read (line 1582)
    ret = library.viRead(session, buffer, count,
    byref(return_count))

Error in messagebased>read_raw (line 306)
                    chunk, status =
                    self.visalib.read(self.session, size)

Error in messagebased>read (line 332)
            message = self.read_raw().decode(enco)

Error in messagebased>query (line 407)
        return self.read()

非常感谢任何帮助!: - )

BR,

汉斯

0 个答案:

没有答案