Pyvisa-Pyusb无法加载大于1 MB的序列

问题描述

我正在通过USB连接到Agilent(33600)波形发生器。如果我正在发送的波形小于1MB(2 ^ 20字节),则可以正常工作。如果更大,它将挂起并在超时时失败。

使用:

  • python3.7,Pyusb 1.1,Pyvisa 1.11和后端Pyvisa-py 0.5.1。尝试了Linux Mint和RaspBerry Pi 4。

最小工作示例:

import pyvisa as visa

my_WFM = 262000*[1] # works fine 262000*4 = 1,048,000
#my_WFM = 263000*[1] # fails (it is just above 1MB) 263000*4 = 1,052,000

resources = visa.ResourceManager('@py')
devices = resources.list_resources()
my_device = resources.open_resource(devices[1])
print(my_device.query('*IDN?')) # works fine

## Prepare the device
my_device.timeout = 300000
my_device.write('*CLS;*RST')
tmp = my_device.query('*OPC?')
my_device.write('SOURce1:DATA:VOLatile:CLEar')

## Send the waveform
my_device.write('FORM:BORD norM') # set the byte order
bytes_sent = my_device.write_binary_values('SOUR1:DATA:ARB myARB,',my_WFM,datatype='f',is_big_endian=True)
print(bytes_sent)
my_device.write('*WAI') # Wait for the waveform to load

print(my_device.query('SYstem:ERROR?')) # no errors for less than 1MB

my_device.close() # close connection to device

解决方法

最好轮询设备以查看操作是否已完成,而不是等待操作完成。尝试使用“ * OPC?”像下面的示例一样循环执行命令。

import pyvisa as visa
from time import sleep

my_WFM = 262000*[1] # works fine 262000*4 = 1,048,000
#my_WFM = 263000*[1] # fails (it is just above 1MB) 263000*4 = 1,052,000

resources = visa.ResourceManager('@py')
devices = resources.list_resources()
my_device = resources.open_resource(devices[1])
print(my_device.query('*IDN?')) # works fine

## Prepare the device
my_device.timeout = 300000
my_device.write('*CLS;*RST')
tmp = my_device.query('*OPC?')
my_device.write('SOURce1:DATA:VOLatile:CLEar')

## Send the waveform
my_device.write('FORM:BORD NORM') # set the byte order
bytes_sent = my_device.write_binary_values('SOUR1:DATA:ARB myARB,',my_WFM,datatype='f',is_big_endian=True)
print(bytes_sent)
device_operation_complete = 0
while not device_operation_complete:
    device_operation_complete = my_device.query('*OPC?') #should return a 1 if complete
    sleep(2)


print(my_device.query('SYSTEM:ERROR?')) # no errors for less than 1MB

my_device.close() # close connection to device