0

I am trying to read some values from an Yokogawa oscilloscope. I made a connection using pyvisa and it worked fine sending and receiving data from the osci. The issue appears when I try to read more than 857 values. If I set the END point 857 I can receive and print/write into a file the whole data but if I set it 858 I get the next error:

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)

and here is how the last bytes of data look like when I debug using 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~')

I'm guessing that the error is generated by the "\x00\x005..." characters but I don't understand why the others are returned as expected and after 857 I get this error.

Bellow is my code:

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)
padurean04
  • 27
  • 5
  • 2
    I suspect you're overflowing a buffer in the oscilloscope: the problem occurs right around the 8K mark. Either read the data in chunks (by changing the START and END parameters in a loop), or read the data in binary format (which is going to be much more compact than ASCII). – jasonharper Mar 05 '19 at 22:14
  • Thank you, I will try that. – padurean04 Mar 06 '19 at 08:33

0 Answers0