Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling multiple GPIBs in c#

Solved!
Go to solution

Hi all,

I'm pretty new to GPIB communication but doing well with various programs which I'm running two instruments connected to one controller (CIC).

So I'm trying to write a program that one controller will listen to two GPIB instruments and read the message that was sent by any of the instruments.

I'm writing my code in C# (WPF actually but this is not the point).

So in my controller application I have two threads and two GPIB devices each connected to a different primary address. It looks like that:

        deviceMain = new Device(gpibBrdID, primaryAddress, secAddress);    // PAD - 1, SAD - 0
        if (deviceMain != null)
           mainPSHandle = deviceMain.Handle;
        deviceSec = new Device(gpibBrdID, primaryAddressSec, secAddress);    // PAD - 2, SAD - 0
       if (deviceSec != null)
          secPSHandle = deviceSec.Handle;

Each of the devices is reading the GPIB line for any incoming messages. Each device is in a separate thread - e.g. deviceMain.ReadString()

The point is that when a message is peaked up by lets say deviceMain device I get a GPIB exception  on the other device (deviceSec ) which also tries to read the GPIB line at the same time. I tried to synchronize the threads with locking technics but no help.

My question is - how is it possible to identify the sending device that sent a message prior using the "ReadString()" method? So if I'll know for instance from which primary address the response came I'll know from which thread to activate the "ReadString()"?

I'm really stuck with this case and will greatly appreciate any help, thanks much in advance.

0 Kudos
Message 1 of 5
(3,323 Views)

Hi Arik2017,

 

What is the GPIB hardware that you are using? If you are using any NI GPIB+ hardware, you have access to the GPIB analyzer which will allow you to monitor, capture, and participate in bus activity on the GPIB.

 

Additionally, NI has some documentation on Developing Multithreaded GPIB Applications using NI-488.2

 

As far as I know, there is no function that allows you to identify the sending device prior to using the ReadString() function

Applications Engineering
National Instruments
0 Kudos
Message 2 of 5
(3,295 Views)

Hello SaileshK

Thanks for the replay. I guess that I was doing wrong trying to read from a gpib device before telling it to write. To answer your question, I'm using two PCI GPIB boards each on a different PC controlled by a USB-GPIB HS+ cable from a controller on a third PC.

I understand perfectly the examples in your reply. It's just that I'm using C# code and in my coding I don't see how can I use the device handle to address a gpib instrument. Using the devices I created with the boards' PADs I simply read and write from/to the instruments (device1.ReadString() and device1.Write()). Do you know about a C# example for controlling multiple gpib instruments?

Thanks many for your support so far.

0 Kudos
Message 3 of 5
(3,288 Views)

Arik2017,

 

Below I have attached a link for how to locate the Measurement Studio examples on your computer.

 

Where to Find Examples

http://zone.ni.com/reference/en-XX/help/375857A-01/xml/locateexamples2013/  - This should lead you to some examples which can help in working with controlling multiple GPIB instruments.

Applications Engineering
National Instruments
0 Kudos
Message 4 of 5
(3,272 Views)
Solution
Accepted by topic author Arik2017

OK Saileshk, I'll mark this post as resolved. Thanks your replies so far.

0 Kudos
Message 5 of 5
(3,266 Views)