pfroud / JVisa

Java library for VISA (Virtual Instrument Software Architecture) instruments
Apache License 2.0
38 stars 13 forks source link

Does JVisa support requesting and parsing binary block data? #13

Closed changhexuefei closed 1 year ago

changhexuefei commented 1 year ago

PyVisa uses query_binary_values method to parse blocks of binary data,does JVisa support parsing binary block data?

pfroud commented 1 year ago

Right now JVisa does not have a method to parse a binary block. I think it is easy, I will add it.

Documentation in this discussion: https://github.com/pfroud/JVisa/discussions/10#discussioncomment-5059595

Links to PyVisa functions:

changhexuefei commented 1 year ago

We look forward to your upgrade of the JVisa library

pfroud commented 1 year ago

Please post a sample of the data you want to parse. You can use the VISA Test Panel in NI-MAX. I only need to see the beginning of the bytes.

For example, a screenshot from dist:data? on a Rigol oscilloscope returns

#9001152054BM6\94\11\00\00\00\00\006\00\00\00(\00\00\00\s\03\00...
changhexuefei commented 1 year ago

The following is the data 1: Write Operation (:WAVeform:DATA?)

Return Count: 15 bytes

2: Read Operation Return Count: 1024 bytes

800488251\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\

80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\80\ 80\80\80\80\80\80\80\80\80\80\80

pfroud commented 1 year ago

I added code on branch add-data-block. I can take a screenshot from my instrument:

byte[] bytes = instrument.queryBinaryBlock("display:data?");
Files.write(Paths.get("screenshot.bmp"), bytes);

Check the programming manual for your instrument about waveform:data?. For the Rigol DS1000Z series oscilloscope, it says

Before reading the waveform data in the internal memory, you need to judge whether the waveform data can all be read at one time according to the memory depth of the oscilloscope and the maximum number of waveform points that can be read each time.

changhexuefei commented 1 year ago

When using the new method, such an error was reported, "in viRead(): VI_SUCCESS_MAX_CNT: The number of bytes read is equal to count (0x3FFF0006)"

changhexuefei commented 1 year ago

Below is the programming documentation for the instrument I am using.

4000X-Programming.pdf

changhexuefei commented 1 year ago

When this problem occurs, pyvisa handles it as follows:

image

pfroud commented 1 year ago

The VI_SUCCESS_MAX_CNT status should be handled, see

https://github.com/pfroud/JVisa/blob/f1aa131e3b07d2f3a4be4fa2397b9ef5a3a1022b/src/main/java/xyz/froud/jvisa/JVisaResourceManager.java#L315

and

https://github.com/pfroud/JVisa/blob/f1aa131e3b07d2f3a4be4fa2397b9ef5a3a1022b/src/main/java/xyz/froud/jvisa/JVisaResourceManager.java#L350

changhexuefei commented 1 year ago

Sorry, I just copied part of the code, now after copying all the code, it can work, thank you

changhexuefei commented 1 year ago

The following is the return value obtained by sending the "waveform data?" command using PyVisa and JVisa, and why they are different. The first picture is the result of pyvisa, and the second picture is the result of JVisa. image

image

pfroud commented 1 year ago

I think it is different signed vs unsigned interpretation of byte primitive. Try this

for (int i = 0; i < bytes.length; i++) {
    System.out.println(i + " = " + Byte.toUnsignedInt(bytes[i]));
}
changhexuefei commented 1 year ago

yes,thank you ,I get it

pfroud commented 1 year ago

Hi, if the queryBinaryBlock() method works, can we close this issue?

changhexuefei commented 1 year ago

Yes, we can close this issue.

changhexuefei commented 1 year ago

Is it considered to publish the newly added part as an official version?

pfroud commented 1 year ago

Yes, I plan to make an official release with the newly added features

pfroud commented 1 year ago

Released in 2.0.0