PyVISA SCPI commands and queries (issue with value update)

穿精又带淫゛_ 提交于 2019-12-08 11:13:10

问题


UPDATE: It seems to be working "OK" this am... although I am not sure why certain replies have /r/n at the end and why certain don't. I have explicitly turned Handshaking OFF...

An example of the commands, queries, and replies is posted below.

**I am using PyVISA frontend to communicate with a sensor.

I am having to have to send a command or make a query three times before there is a change in the output...

Do I have to add wait command before proceeding? I thought the SCPI commands were blocking (synchronous so as to speak). Please let me know if I am doing something awry. Here are a few of my commands:**

    >>> import visa
    >>> ins = visa.ResourceManager()
    >>> print(ins.list_resources())
    ('ASRL1::INSTR', 'ASRL3::INSTR', 'ASRL6::INSTR', 'ASRL10::INSTR')
    >>> Energy_sense = ins.open_resource('ASRL6::INSTR')
    >>> print(Energy_sense.query('*IDN?'))
     Coherent, Inc - EnergyMax USB - V1.2 - Jan 27 2011


    >>> Energy_sense.write(":CONF:WAVE 780")
     (16, <StatusCode.success: 0>)
    >>> print(Energy_sense.query(':CONF:WAVE?'))
    780


     >>> Energy_sense.write(":SYST:COMM:HAND OFF")
     (21, <StatusCode.success: 0>)
     >>>
     >>> Energy_sense.write(":CONF:MEAS:STAT ON")
     (20, <StatusCode.success: 0>)
     >>> Energy_sense.write(":CONF:STAT:BSIZ 1000")
     (22, <StatusCode.success: 0>)
      >>> Energy_sense.query(":CONF:STAT:BSIZ?")
      '1000\r\n'
      >>> Energy_sense.write(":CONF:STAT:STAR")
      (17, <StatusCode.success: 0>)
      >>> Energy_sense.query(":READ?")
       '3.728E-5,3.150E-5,4.358E-5,2.597E-6\r\n'
      >>>
      >>> Energy_sense.query(":CONF:STAT:BSIZ?")
      '1000\r\n'
      >>>
      >>> print(Energy_sense.query(':CONF:WAVE?'))
      780

      >>>

You can find the rest of the commands in the image.


回答1:


You are correct. VISA commands are blocking, so you should not need a wait after a VISA command. Have you set the timeout? Is it too short? Some devices may take longer to respond to commands than others.

import visa
self._rm = visa.ResourceManager()
self._visa_conn = self._rm.open_resource('GPIB0::%s::INSTR' % instr_addr)
self._visa_conn.timeout = 1000 # In milliseconds

You can remove the '\n' with:

string.rstrip('\n')


来源:https://stackoverflow.com/questions/35518230/pyvisa-scpi-commands-and-queries-issue-with-value-update

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!