Posted Tue, 05 Dec 2023 12:53:24 GMT by RU, Rmj
Hi,
I am passing Ivi.VISA command to save oscilloscope screenshot as .png file and then read it back from oscilloscope to save in my local system, using C# code. My code segment is as follows:
                    scope.TimeoutMilliseconds = 10000;
                    // Save image to instrument's local disk
                    scope.FormattedIO.WriteLine("SAVE:IMAGe \"eval.png\"");
                    scope.FormattedIO.WriteLine("*OPC?");

                    // Read image file from instrument
                    scope.FormattedIO.WriteLine("FILESystem:READFile \"eval.png\"");
                    
                    byte[] imgData = new byte[5000];
                    imgData = scope.RawIO.Read();
                    scope.FormattedIO.WriteLine("*OPC?");

Though the saved image in Oscilloscope is of size 23 MB. bytes returned by RawIO.Read() (i.e. in imgData) is only 1MB.

Thanks,
Reena
Posted Wed, 06 Dec 2023 17:09:41 GMT by Teles, Afonso
Hi Reena,

I think this might be related to this discussion in the old forum: https://forum.tek.com/viewtopic.php?t=139957

Could also be that the Read() method stops reading when it sees a termination character (0x0A most likely), which will fail to read an arbitrary block. You should check if your library has a function to read an array if arbitrary binary values (like pyvisa's read_binary_values()).
Posted Wed, 06 Dec 2023 18:23:04 GMT by RU, Rmj
I am using Ivi.Visa;
I do not see any other read functions like ReadByteArray() as is used in the  forum 
https://forum.tek.com/viewtopic.php?t=139957.
If there is any other library that I can install and try, please let me know.
Currently, I installed from https://www.ni.com/en/support/downloads/drivers/download.ni-visa.html#494653.
I do not see NI.VISA package in my NuGet packages. If anybody knows how I can get NI.VISA
My application is in .NET 4.7.2.

Thanks,
Reena
Posted Wed, 06 Dec 2023 22:08:57 GMT by Wyban, David
Use the version of the Read() method where you specify the maximum number of bytes to read and set it to a large value.
byte[] Read(
	long count
)
By default the Visa.Net library uses a buffer of 1M, but that isn't large enough for your file so you are only getting 1M of it.

Another option would be to make multiple reads until you perform a read that returns fewer bytes than you set count to.  You could use the following version of the Read() method and set the parameters so that the data keeps getting put into the same byte array.
void Read(
	byte[] buffer,
	long index,
	long count,
	out long actualCount,
	out ReadStatus readStatus
)
Easiest thing to do though, just set the count to value larger than the size of the file being transferred.

You must be signed in to post in this forum.