08-21-2014 07:37 PM
I have a NI GPIB-USB-HS adapter running the 488.2 3.1.2 drivers.
It runs a C app in listen-only mode and captures bus data strings well.
I'm trying to get the same functionality using C#.Net.
So far I have tried the following code snippet in VS2010 (.Net 4.0)
with the corresponding NI 488.2 and Common assemblies referenced by the project.
Here is a snippet...
Form...
private Board board = null;
Form_Load...
try {
board = new Board(0); // ibfind(GPIB0);
board.Reset(); // ibonl();
board = new Board(0); // ibfind(GPIB0);
board.ListenOnlyMode = true; // ibconfig(GPIB0, IbcLON, 1)
board.IOTimeout = Timeoutvalue.t300ms; // ibconfig(GPIB0, IbcTMO, T300ms)
}
catch {
...
}
Form_Shown...
while(running)
{
Application.DoEvents();
try {
data = board.ReadByteArray(256); // ibrd
length = board.LastCount; // Ibcnt
}
catch {
...
}
}
With the NI GPIB-USB-HS adapter disconnected from any GPIB host or devices,
the ReadByteArray lands in the catch every 300ms per the timeout value as expected.
With the NI GPIB-USB-HS adapter connected to a GPIB host and devices with data flowing,
the ReadByteArray method ends up in the catch everytime still and the length is always 0.
Polling in C (ibrd/Ibcnt) is the only way I have been able to get Listen-Only to work.
What needs to be done in .Net to make Listen-Only work?
Here is a list of the calls in C that I use for Listen-Only to work...
Setup...
Bd = ibfindA("GPIB0");
ibonl(Bd, 0); // Take board offline - loses handle
Bd = ibfindA("GPIB0");
ibconfig(Bd, IbcSAD, 0x00);
ibconfig(Bd, IbcLON, 1);
ibconfig(Bd, IbcTMO, T300ms);
Poll...
ibrd(Bd, ReadBuffer, 256);
length = Ibcnt();
Thanks,
Steve
08-22-2014 04:58 PM
Hi,
I dont have direct answer for you but i think this article might help you in writting your code in C# .NET
http://zone.ni.com/reference/en-XX/help/370628F-01/mstudiowebhelp/html/gpibapimapping/
08-22-2014 05:02 PM
Thanks,
I use that table all the time...
Steve
08-25-2014 03:42 PM - edited 08-25-2014 03:43 PM
Have you consider looking at GPIB C#.NET examples?
08-25-2014 04:17 PM
Yes, I started with those examples a while back. If I recall correctly, they used the device class. I've gone the route of the board class. None of the .Net examples covered Listen-Only.
08-26-2014 06:35 PM
What happens when you try to read only single byte?
Do you know which expections are thrown?