Tektronix Technical Forums are maintained by community involvement. Feel free to post questions or respond to questions by other members. Should you require a time-sensitive answer, please contact your local Tektronix support center here.
I have successfully used OpenChoiceDesktop to capture screens, and OpenChoice Call Monitor to see exactly how this was done, so I have had some success capturing images with my C# application. However, I have found that the C# API layer (above the viRead() function) can cause corruption of the binary image data, as it converts it from a binary byte array to a text unicode string, and frequently causes some bytes to be dropped.
OpenChoiceDesktop does not appear to use the C# API, and seems to use the lower level viRead calls, so it has more reliable screen capturing.
1. Is it possible to augment the existing Read function of the C# API, with an overload function like this:
bool Read(out byte OutputBuffer, int BytesDesired, out BytesRead)
This function would keep the binary data intact, and would likely only be used for screen dumping.
2. Are there any examples of using the C# API with the lower level viRead calls as needed?
I found an ancient copy of Visa32.cs -, and from this I extracted just the information required to use the viRead function in Visa32.dll from C#.
internal static class Visa32Helper
[DllImportAttribute("VISA32.DLL", EntryPoint = "#256", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
public static extern int viRead(int vi, byte buffer, int count, out int retCount);
public const int VI_SUCCESS = 0;
public const int VI_SUCCESS_TERM_CHAR = 1073676293;
public const int VI_SUCCESS_MAX_CNT = 1073676294;
And here is a C# Read() wrapper function that uses the viRead() function to return a byte instead of a unicode string:
private bool Read(int BytesDesired, out int BytesRead, out byte data)
// This is the function I would like to see in the Tek C# API, to support screen captures
bool success = false;
byte buffer = new byte[BytesDesired];
data = null;
BytesRead = 0;
int vi = (int)myVISA.Session;
int status = Visa32Helper.viRead(vi, buffer, BytesDesired, out BytesRead);
success = true;
data = new byte[BytesRead];
Array.ConstrainedCopy(buffer, 0, data, 0, BytesRead);
It sounds like you're using Tek VISA in your application. For C# development I'd high recommend using NI-VISA as NI-VISA has a really great native C# interface and does not use interop with a COM driver like Tek VISA does. NI-VISA message based session objects have a member method ReadByteArray() that returns an array of bytes and removes the issue with ReadString() turning the data into unicode characters. The NI-VISA package also include really good standard .NET formatted documentation. As I said, I recommend using it for your C# development.
Who is online
Users browsing this forum: No registered users and 2 guests