Open lsi8 opened 3 years ago
The way you read the binary data is dangerous. read_raw will break on any termchar and will leave binary data in the buffer which is probably the cause of the next error. I suggest you try to use use the read_binary_values function or take inspiration from it if you do not want/cannot use this functio..
Is there an up-to-date example showing how to get waveform data from an oscilloscope?
That depends of the model of your oscilloscope. The manual for your model (https://beyondmeasure.rigoltech.com/acton/attachment/1579/f-0386/1/-/-/-/-/DS1000Z_Programming%20Guide_EN.pdf) describe the format starting line 240 and include what parameters enter into the conversion from the data returned to actual voltage. From there if you choose to use BYTE you need to use the datatype "b" with read_binary_values
or "h" if you choose to use WORD. The documentation I linked in the pyvisa thread, describe how to get all the other parameters right for the transfer.
Let me know if you encounter any further issue.
I haven't been able to get read_binary_values(datatype='b') to work. It produces the following error:
Traceback (most recent call last):
File "/home/pi/Documents/projects/cu/pnaci/rigol/test.py", line 56, in <module>
rawdata = scope.read_binary_values(datatype='b')
File "/usr/local/lib/python3.7/dist-packages/pyvisa/resources/messagebased.py", line 575, in read_binary_values
block = self._read_raw(chunk_size)
File "/usr/local/lib/python3.7/dist-packages/pyvisa/resources/messagebased.py", line 442, in _read_raw
chunk, status = self.visalib.read(self.session, size)
File "/usr/local/lib/python3.7/dist-packages/pyvisa_py/highlevel.py", line 519, in read
return data, self.handle_return_value(session, status_code)
File "/usr/local/lib/python3.7/dist-packages/pyvisa/highlevel.py", line 251, in handle_return_value
raise errors.VisaIOError(rv)
pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
I have been able to get scope.query_binary_values(":WAV:DATA?", datatype='B') to work but only up to 400ish datapoints... Anything over 500 datapoints and I get the following error:
Traceback (most recent call last):
File "/home/pi/Documents/projects/cu/pnaci/rigol/test.py", line 56, in <module>
rawdata = scope.query_binary_values("WAV:DATA?", datatype='B')
File "/usr/local/lib/python3.7/dist-packages/pyvisa/resources/messagebased.py", line 754, in query_binary_values
chunk_size,
File "/usr/local/lib/python3.7/dist-packages/pyvisa/resources/messagebased.py", line 602, in read_binary_values
self.read_bytes(expected_length - len(block), chunk_size=chunk_size)
File "/usr/local/lib/python3.7/dist-packages/pyvisa/resources/messagebased.py", line 371, in read_bytes
chunk, status = self.visalib.read(self.session, size)
File "/usr/local/lib/python3.7/dist-packages/pyvisa_py/highlevel.py", line 512, in read
data, status_code = self.sessions[session].read(count)
File "/usr/local/lib/python3.7/dist-packages/pyvisa_py/usb.py", line 156, in read
USBTimeoutException,
File "/usr/local/lib/python3.7/dist-packages/pyvisa_py/sessions.py", line 793, in _read
current = reader()
File "/usr/local/lib/python3.7/dist-packages/pyvisa_py/usb.py", line 133, in _usb_reader
return self.interface.read(count)
File "/usr/local/lib/python3.7/dist-packages/pyvisa_py/protocols/usbtmc.py", line 465, in read
response = BulkInMessage.from_bytes(resp)
File "/usr/local/lib/python3.7/dist-packages/pyvisa_py/protocols/usbtmc.py", line 113, in from_bytes
msgid, btag, btaginverse = struct.unpack_from("BBBx", data)
struct.error: unpack_from requires a buffer of at least 4 bytes
I am not sure how why going from signed to unsigned changes the number of point. However the second error looks like either an issue in pyvisa-py or another oddity from Rigol ? As I suggested in your pyvisa-py issue do you have access to a machine where you can install Keysight or NI Visa ?
I will install NI Visa on my mac and attempt to save waveform data today.
Could the problem be chunk_size?
I am using latest version of pyvisa with Rigol DS1104Z oscilloscope and Raspberry Pi 4. I have omitted the last few lines of the following code (which would generate a plot) because the error is being generated by the last line only when I turn my sensing circuit on, i.e., only when the scope is exposed to a large sine wave signal:
Here is the error message
Output of
pyvisa-info