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

2024-09-23 16:25:50 发布

您现在位置:Python中文网/ 问答频道 /正文

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

使用:

  • Python3.7、pyusb1.1、pyvisa1.11和Pyvisa py0.5.1后端。尝试了LinuxMint和RaspberryPi4

最低工作示例:

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

Tags: thedataismydevicevisaquerywrite
1条回答
网友
1楼 · 发布于 2024-09-23 16:25:50

最好轮询设备以查看操作是否已完成,而不是等待操作完成。尝试在循环中使用“*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

相关问题 更多 >