ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

C#.Net Listen Only and ReadByteArray

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

 

Message 1 of 6
(7,243 Views)

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/

0 Kudos
Message 2 of 6
(7,221 Views)

Thanks,

 

I use that table all the time...

 

Steve

0 Kudos
Message 3 of 6
(7,219 Views)
0 Kudos
Message 4 of 6
(7,180 Views)

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.

Message 5 of 6
(7,177 Views)

What happens when you try to read only single byte?

 

Do you know which expections are thrown? 

0 Kudos
Message 6 of 6
(7,153 Views)