0

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

使用:

  • Python3.7、Pyusb 1.1、带有 Pyvisa-py 0.5.1 后端的 Pyvisa 1.11。尝试了 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
4

1 回答 1

0

最好轮询设备以查看操作是否已完成,而不是等待操作完成。尝试使用“*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
于 2020-11-12T16:50:36.783 回答