Is it normal to wait for some time between operations under the VISA protocol?

5.1k views Asked by At

I am using pyvisa to program a power supply which conforms to the SCPI protocol, like this:

power = get_power()
power.write('VOLTage 24.000')
time.sleep(1)       # **Must delay**
power.query(u'VOLTage?')
disconnect_power(power)

Everything was OK, but if I didn't wait between 'write' and 'query', then there was a timeout error, just like this:

raise errors.VisaIOError(ret_value) pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.

Is it normal to delay between operations when programming such instrument under VISA protocol? If not, what is the usual way? Or is there any mechanism like Event? If yes, how do I decide the latency time?

2

There are 2 answers

0
lengxuehx On BEST ANSWER

In fact, this is a common problem when programming an SCPI instrument. Actually, SCPI provides many methods for synchronization, see IEEE-488.2.87 section 12: Device/Controller Synchronization Techniques. And here is a summary for good SCPI programming practices, although it's for a proprietary instrument, some tips apply to all SCPI devices.

So the key issue is: The power supply can not process the next 'Program Message' (refer to IEEE-488.2.87 for details) before the previous ('VOLTage 24.000') is completed. If you force to do it without a proper delay, the processing will be interrupted.

SCPI provides a synchronization command, "*OPC?" to wait for all commands before it to complete. When every command completes, it will put a 1 in output buffer. So we can just append '*OPC?' to the previous Program Message and then just wait for completion by read, after that we query, like this:

power = get_power()
power.write('VOLTage 24.000;*OPC?')
power.read()
power.query(u'VOLTage?')
disconnect_power(power)

So that's it.

0
cinsight On

The *WAI command can be used in place of the *OPC? query.

power = get_power()

voltage_read = power.query('VOLTage 24.000;*WAI;u'VOLTage?')

disconnect_power(power)

The *WAI instructs the instrument to wait for the completion for setting the voltage, before reading back the query.