我正在尝试从横河示波器中读取一些值。我使用 pyvisa 建立了连接,它可以很好地从 osci 发送和接收数据。当我尝试读取超过 857 个值时会出现此问题。如果我将 END 点设置为 857,我可以接收并将整个数据打印/写入文件,但如果我将其设置为 858,我会收到下一个错误:
Traceback (most recent call last):
File "osci_connect.py", line 16, in <module>
values1 = (my_osci.query_ascii_values(':WAVEFORM:SEND? 0'))
File "C:\Python37\lib\site-packages\pyvisa\resources\messagebased.py", line 629, in query_ascii_values
delay)
File "C:\Python37\lib\site-packages\pyvisa\resources\messagebased.py", line 447, in read_ascii_values
block = self.read()
File "C:\Python37\lib\site-packages\pyvisa\resources\messagebased.py", line 413, in read
message = self._read_raw().decode(enco)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xec in position 8156: ordinal not in range(128)
这是我使用 pydev 调试时最后一个字节的数据的样子:
b'.04E+00,-0.04E+00,-0.02E+00,0.03E+00,-0.01E+00,-0.01E+00,0.00E+00,-0.02E+00,'
b'-0.01E+00,-0.03E+00,-0.03E+00,0.01E+00,0.04E+00,-0.01E+00,-0.02E+00,-0.06E+0'
b'0,0.02E+00,0.03E+00,0.03E+00,0.01E+00,0.04E+00,0.00E+00,0.01E+00,0.04E+00,0.'
b'03E+00,-0.03E+00,-0.\x00\x005\xc4\x1c\xbf~')
我猜该错误是由“\x00\x005...”字符生成的,但我不明白为什么其他字符会按预期返回,并且在 857 之后出现此错误。
贝娄是我的代码:
import visa
rm = visa.ResourceManager()
#rm = visa.ResourceManager('C:\WINDOWS\system32\visa32.dll')
my_osci = rm.open_resource("TCPIP::172.20.113.189::INSTR",write_termination='\n',read_termination='\n')
print("Hello, I am:" + my_osci.query("*IDN?"))
print("Send ':WAVEFORM:END 1' ")
my_osci.write(":WAVEFORM:FORMAT ASCII")
my_osci.write(":WAVEFORM:START 0")
my_osci.write(":WAVEFORM:END 858")
#values = my_osci.query_ascii_values(':WAVEFORM:END 20')
values1 = (my_osci.query_ascii_values(':WAVEFORM:SEND? 0'))
print("Received values:")
print(values1)