Open WillMatthews opened 2 years ago
That's a tough one. I know some manufacturers implement USBTMC loosely, which is why the BulkInMessage has a from quirky method, but apparently it does not help in your case.
Since you are running Ubuntu you can try to install the VISA distribution of Keysight and see if things work with the ici backend. If it does it would be great to see a Wireshark comparison between the two backends to figure out what pyvisa-py is doing wrong.
Thank you! I know some USBTMC implementations can be a bit janky. What you suggest is a great idea. Before I implement that, I managed to get a wireshark capture of serial communications through pyvisa. I will update soon once I have the Keysight VISA installed and working.
Made some progress!
I had a poke around in ./pyvisa_py/protocols/usbtmc.py
On line 440 is the definition of the method read(self,size)
In this method's main loop iterating through requests and parsing the data, beginning at approx line 457, sometimes resp
can have zero length.
I added a check as follows in the loop just after receiving data and before it's parsed with from_bytes
:
if len(resp) == 0:
continue
and I get far more data than before, but it eventually ends up in a write timeout (sometimes?).
Now if I use read_bytes(1000000)
it's able to get 1M points, however when attempting to get the full 14M points I also end up in a write timeout.
I'll have a go with the Keysight VISA and grab a wireshark capture soon to see what they do differently. I'm spread a bit thin at the moment (writing up thesis) so regrettably this isn't my priority number 1. I'll get around to exploring more when I have time.
Thanks for your investigation.
Could you post the timeout traceback and check if adding a 1ms sleep before the continue helps in case we are saturating the instrument somehow.
I found that once this timeout occurs, the o'scope must be restarted in order to communicate with it successfully again. It looks like data points are still in the scope's memory - but when running a query it just continues providing the point data.
It looks like the 1ms pause fixes this! I will check more tonight and hopefully get a pull request in soon. Many many thanks Matthieu :)
Spoke too soon! I still have the timeout traceback as above when doing read_binary_values()
I also had this traceback when doing read_bytes(14000000)
, which I haven't yet seen I think...
You may have to add the smae logic to from_quirky since often in long transfer the USB is weirdly formatted and we cannot go through from_bytes. Having the wait in both functions may help.
Adding a sleep in from_quirky didn't seem to help. What (maybe?) helped was calling read_bytes(128) over and over. Not sure what to make of this yet but I will look more in detail.
looking at the documentation on page 163 on the vi.read example they have, they use a maximum count (MAX_CNT) of 200. When I try chunking with read_bytes(200)
it seems to work better than read_bytes(128)
or read_bytes(64)
.
I will have to update on this later, as I'm still trying to see if this workaround actually works.
This method is extremely slow, however.
Instrument details
Output of
pyvisa-info
The problem...
I got this traceback, which I've seen mentioned around with no good fix for..
I've been dashing my brain out over rocks on this problem for quite a while now, I contacted Siglent themselves and they couldn't offer any help.
I appear to get approx. 60k points from the oscilloscope, a little shorter than the expected 14M points the scope claims to have in its memory. I found this by putting a print statement in
from_bytes
(usbtmc.py) and analysing the output. the last line seems to cause the exception, as it's empty:b''
On my waveform query, the output format appears like it doesn't match the packing specified in
from_bytes
'sstruct.unpack_from
. Thestruct.unpack_from
infrom_bytes
(usbtmc.py) has a packing of"BBBx"
, however I get far more, valid, points if I use the packing"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
which seems weird to me - I'm even sure if I'm doing this correctly or if this provides anything insightful, as I don't have any other instruments to compare to.Here are a couple lines I've captured from somewhere in the middle of the waveform response.
I'm not really sure what else I can do - I think I've reached the extent I can just poking around by myself, please may I have some help? Many Thanks in advance, William