Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

NI-GPIB-USB controller as a device (C#)

Hello,

I want to use the NI-GPIB-USB controller as a device. After one week search I found only a single sample code for National Instruments GPIB !!, unfortunately that is written in “C” not in C#.

I can send strings from Unix System to Windows PC but I cannot read it. I have problems with “Board.BeginRead” and “Board.EndReadString”.

When I run the program I am getting the error message “EndReadString was called before BeginRead”.

 I am attaching the code here (I am new to GPIB and C#), it will be a great help for me if some one can give any information which can help this problem.

0 Kudos
Message 1 of 11
(10,510 Views)

I found it,

 

Where I call "BeginRead" I forgot to add the number of bytes (a 7), So it should look like below.

 

// Initiates a read to a device asynchronously

board.BeginRead(7,new AsyncCallback(endread), null);

0 Kudos
Message 2 of 11
(10,503 Views)

Did you finally made it or refined your code?

 

I habe the same problem. Do you use a handle to a device or to the board? And do you use the Notify method to automatically read the command send by the controller or did you implement it analog to the C - examples (with a thread polling the ibsta flags and doing something when, for example, "if ((ibsta&LACS)&&(!(ibsta&ATN)))" is true) ?

 

Thank you for every hint..

0 Kudos
Message 3 of 11
(9,942 Views)

Hello, I don’t have the final code with me and as far I remember I Waite until one of the needed GPIB status flag occurs and rest is depends on the received status flag.

 

GpibStatusFlags mask = (GpibStatusFlags.ListenerAddressed | GpibStatusFlags.TalkerAddressed | .. .);

 

//Waite until one of the GPIB status flag occurs

board.Wait(mask);

0 Kudos
Message 4 of 11
(9,928 Views)

Thank you very much for your answer!

 

...but the wait function is blocking until anything happens, right? Did you create an extra thread for board.wait() or does it not matter for you if the program blocks? Do you know a way using the board.notify() method?

 

Greetings from Germany, Christian

0 Kudos
Message 5 of 11
(9,921 Views)

I am still working on it so that I can run the all the GPIB functions in a single worker thread.

I use the "Board" for using the PC as a GPIB device and "Device" for using the PC as a GPIB controller.

0 Kudos
Message 6 of 11
(9,685 Views)

Yes I did it.

Need no extra thread for board.wait(). I run the function which contains the while()  loop (or GPIB device loop, this includes listening, talking on GPIB) in a separate thread and set that thread as back ground worker. For displaying the GPIB status and messages I use Invoke so, that is also working independent.

0 Kudos
Message 7 of 11
(9,622 Views)

Few interesting documents which includes informations about > Device & Board functions, Waiting for GPIB Conditions, Asynchronous Event Notification in NI-488.2 Applications and so on.

0 Kudos
Message 8 of 11
(9,528 Views)

Few interesting documents which includes informations about > Device & Board functions, Waiting for GPIB Conditions, Asynchronous Event Notification in NI-488.2 Applications and so on.

0 Kudos
Message 9 of 11
(9,527 Views)

Few interesting documents which includes informations about > Device & Board functions, Waiting for GPIB Conditions, Asynchronous Event Notification in NI-488.2 Applications and so on.

Message 10 of 11
(9,526 Views)