pyvisa / pyvisa-py

A pure python PyVISA backend
https://pyvisa-py.readthedocs.io
MIT License
272 stars 116 forks source link

Problem with TCPIP read() when more than "chunk_length" is returned #101

Open rriggs opened 7 years ago

rriggs commented 7 years ago

I am attempting to download a screenshot from a Siglent DSO using the SCDP command. This just dumps the binary data for a BMP file. The problem appears to be that it sends all of the data in one shot.

n, status = scope.write('SCDP')
if status == StatusCode.success:
    data = scope.read_raw()
    open("test.bmp", "w").write(data)

The code just hangs at read_raw().

Adding some diagnostics to TCPIPInstrSession.read(), this is what I see:

wanted 4096 bytes, read 1152057 bytes
want -1131577 more bytes

Upon return from this function, count is negative, the excess data read and returned, but the count is lost in the upper layers. I don't understand the VXI-11 protocol well enough to know if this is a problem with the device not conforming to spec (it seems to work with NI-VISA and their native app), with PyVISA or with PyVISA-py.

I bodged the read() function to buffer the data it receives and only return the requested chunk_size. That seems to work for me (I successfully stored a screenshot), but I don't know if that is a reasonable fix. If it is, I am happy to work up a pull request.

rriggs commented 7 years ago

It appears I can work around the issue by telling read_raw() to read 2MB of data. Somehow I missed that read_raw() accepts an optional length argument.

skrchnavy commented 6 years ago

@rriggs are you able test this isse when #116 merged?

skrchnavy commented 6 years ago

116 merged, is there a chance to verify if this issue is fixed?