I am trying to convert data from a Keysight scope to .png Image. When I looked how to do it online, I stumbled the following code:
# Download the screen image.
# --------------------------------------------------------
sDisplay = do_query_ieee_block(":DISPlay:DATA? PNG")
# Save display data values to file.
f = open("screen_image.png", "wb")
f.write(sDisplay)
f.close()
The problem with code above is that I'm not sure what do_query_ieee_block is. I thought it was under pyvisa but couldn't find it there. After looking online, I understood that query_binary_values is more or less the same thing as pyvisa assumes that data is in IEEE.
According to this information, I wrote the following code:
import pyvisa
import struct
IDN="SomeScopeIDN" #something like 'USB0::0xhhhh::0xhhhh::MYdddddddd::0::INSTR'
scope=pyvisa.ResourceManager().open_resource(IDN)
binImage=self.scope.query_binary_values(":DISPlay:DATA? PNG") #This gets a list of floats
byteImage=struct.pack('%sf' % len(binImage),*binImage) #Convert the list to bytes-like object
path=r"c:\Users\user\Desktop\Scope_Image.png"
with open (path,'wb') as f:
f.write(byteImage)
This creates an image, but the outcome is bad:
and from snipping tool:
As you can see, only the upper 10% of the image is fine but the rest is not (it will be mentioned that each time I retrieve new data from the scope I get a different area that is corrupted, which is between 50-90% of the picture. Most of the time the corrupted area is between 80-90%, as seen in the picture above).
So basically my questions are:
-
Could it be that I don't read the whole data from the instrument? and if so, how can overcome this issue?
-
Could it be happening because of packing in a wrong way? If so, what's the solution?
from Converting float list to byte-like object results in a corrupted image


No comments:
Post a Comment