We are trying to obtain screen grabs from the instrument console to add to our pdf report, which is part of the ResultListener
.
The Scpi command to obtain screen grab works when we run the following scpi commands directly:
MMEM:STOR:IMAG "pic.png"
The above command saves the screen grab into a file called pic.png on the instrument
The below command then transfer the same file to the client machine
MMEM:DATA? "pic.png" > pic.png
However when we run these commands via C# code using ScpiCommand
/ ScpiQuery
methods of ScpiInstrument
, we get a sequence of numbers in an array as the output.
How can we save the image to our machine at a particular location via the OpenTap SDK?
EDIT : Keysight command expert returns us a list of comma separated integers, which are supposed to be 488.2
block format. We believe that we need a way to convert this list of comma separated integers into an image - perhaps a bmp?
EDIT 2 : attempted to write this into a png file thus:
using System.Drawing;
using System.Text.RegularExpressions;
string intArrayString = "[137,80,78,71,13,10,2]"; // huge string, partly provided here
int[] intArray = Regex.Matches(intArrayString, @"\d+")
.Cast<Match>()
.Select(m => int.Parse(m.Value))
.ToArray();
// Convert integer array to byte array
byte[] byteArray = new byte[intArray.Length * sizeof(int)];
Buffer.BlockCopy(intArray, 0, byteArray, 0, byteArray.Length);
using (MemoryStream ms = new(byteArray))
{
Image image = Image.FromStream(ms);
image.Save("abc.png", System.Drawing.Imaging.ImageFormat.Png);
}
This thows an error
Unhandled exception. System.ArgumentException: Parameter is not valid.
at Windows.Win32.Graphics.GdiPlus.StatusExtensions.ThrowIfFailed(Status status)
at System.Drawing.Image.LoadGdipImageFromStream(IStream* stream, Boolean useEmbeddedColorManagement)
at System.Drawing.Image.LoadGdipImageFromStream(Stream stream, Boolean useEmbeddedColorManagement)
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement)
at System.Drawing.Image.FromStream(Stream stream)
at Program.<Main>$(String[] args) in Program.cs
which doesn’t make sense because that would mean the output from the scpi query is invalid. Or could there be another reason, better yet is there a simpler way to get the image from this binary block?