Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing C# Synchronized Read/Write Functions

I am trying to create C# functions that will wait until the GPIB command has actually completed on the system that it is executed on.  That is, I dont want to just wait until the command has been run, I want to wait until the command is complete.  So for example, if I do a Device.Write(":INITiate:IMMediate" ) where the Device is a Spec A, I want to wait until the sweep is complete on the system before continuing in my code.  I think the Device.Wait(IOComplete) only waits for the issuing of the command to complete.  It doesnt wait for the sweep to finish (I know this because after I run Device.Write(":INITiate:IMMediate" ), then Device.Wait(IOComplete), then Device.Write(":CALCulate:MARKer:MAXimum" ), which does a peak search.  And I can see that on the Spec A, that the sweep isnt complete when the peak search is executed.

 

This is cutouts of the code I have so far.  I would also like to do a similar thing with Read (that is make sure the read is finished before moving on).  I feel there is a better way than what I have below (which seems to work ok, but it might just be because of the extra delay introduced by the *OPC? command.

 

 Board mGpibBoard = new Board(mGPIBConfiguration.GPIBBoardID);

mGpibBoard.AbortAsynchronousIO();

 

mGpibBoard.SendInterfaceClear();mGpibBoard.BecomeActiveController(true);

mGpibBoard.IOTimeout = GPIB_TIMEOUT_VALUE;

mGpibBoard.SetEndOnEndOfString =
false;

mGpibBoard.SetEndOnWrite = true;

 

Device Unit = new Device(mGPIBConfiguration.GPIBBoardID, gpibUnit.PrimaryAddress);Unit.TerminateReadOnEndOfString = false;

Unit.IOTimeout = GPIB_TIMEOUT_VALUE;

Unit.SerialPollResponseTimeout = GPIB_TIMEOUT_VALUE;

Unit.SetEndOnEndOfString =
false;

Unit.SetEndOnWrite = true;

 

public void SyncWrite(String command)

{

  if (Unit != null)

  {

    GpibStatusFlags wait_mask = (GpibStatusFlags.IOComplete | GpibStatusFlags.Timeout);     Unit.Write(command);

    Unit.Wait(wait_mask);

    bool synced = false;

    int counter = 0;

    while (!synced && counter < 100)

    {

      Unit.Write("*OPC?");

      Unit.Wait(wait_mask);

      String val = Unit.ReadString();

      Unit.Wait(wait_mask);

      synced = val.Trim().Replace(
"+","").Equals("1");

      counter++;

    }

  }

}

 

public String SyncRead(String command)

{

  String read_string = ""; if (Unit != null)

  {

    GpibStatusFlags wait_mask = (GpibStatusFlags.IOComplete | GpibStatusFlags.Timeout);

    Unit.Write(command);

    Unit.Wait(wait_mask);

    read_string = Unit.ReadString();

    Unit.Wait(wait_mask);

    bool synced = false;

    int counter = 0;

    while (!synced && counter < 100)

    {

      Unit.Write("*OPC?");

      Unit.Wait(wait_mask);

      String val = Unit.ReadString();

      Unit.Wait(wait_mask);

      synced = val.Trim().Replace(
"+", "").Equals("1");

      counter++;

    }

  }

  return read_string;

}

 

Thanks,

Nick

0 Kudos
Message 1 of 32
(7,469 Views)

Hi Nick,

 

Depending on how your device reacts to commands, there are a few ways to determine if it has completed the requested operation.  You can monitor the RQS bit (6th bit) in the status byte using the ReadStatusByte call.  If your device uses the SRQ line to announce the completion of the request, you can use the WaitSRQ function.

Caleb W

National Instruments

0 Kudos
Message 2 of 32
(7,442 Views)

Hey Caleb,

So you are saying to run the Unit.Write("*STB?" ); command, then run Unit.ReadString() and check the result for the RQS bit to be set?  I dont see any functions called ReadStatusByte or WaitSRQ. There is Unit.Wait(GpibStatusFlags.ServiceRequest); in C#.

Thanks,

Nick

Message Edited by Schoon on 10-15-2008 09:05 AM
0 Kudos
Message 3 of 32
(7,416 Views)

Hi Nick,

 

Those functions are methods of the GpibSession Class.  They are a part of the NI Measurement Studio .NET Class Library.  You can find all of the functions in the Measurement Studio .NET Class Library in Start»All Programs»National Instruments»NI-488.2»NI 488.2 .NET Framework XX Help.  To do what you are wanting, you will need to know how your device reacts to the commands you are sending it (specifically how the bytes and lines are changing).  

Caleb W

National Instruments

0 Kudos
Message 4 of 32
(7,386 Views)

Hey Caleb,

Thanks for your help.  Is that .NET Framework help available online or some place I could download it.  I only see the normal  NI-488.2 Help, and not the .NET Framework Help.

Thanks,

Nick

0 Kudos
Message 5 of 32
(7,382 Views)
When you installed Measurement Studio, did you install with .NET support?
Caleb W

National Instruments

0 Kudos
Message 6 of 32
(7,380 Views)

Yeah, I installed the NI-488.2 version 2.2 for Windows, clicked Custom from the Installation Options, selected all features (including the .NET Languages support for VS2003).  I have a C:\Program Files\National Instruments\MeasurementStudioVS2003\Help directory, but none of the files look like anything I can open.  I also have the C:\Program Files\National Instruments\NI-488.2\Help directory, but I dont see any .NET Framework help.

Thanks,

Nick

0 Kudos
Message 7 of 32
(7,378 Views)
One other place that you can find it is searching the help in Visual Studio.  When you search the help, you will see the Measurement Studio Help files in the Local Help tab.
Caleb W

National Instruments

0 Kudos
Message 8 of 32
(7,376 Views)

I didnt see anything there either.  Not sure if its because the NI install is for 2003 and I'm running 2005 or what, but I dont see anything in the help.

Thanks,

Nick

0 Kudos
Message 9 of 32
(7,372 Views)

Hi Nick,

 

You might need to reinstall Measurement Studio to get the help files integrated with Visual Studio.  As long as you have Measurement Studio version 8.0.1 or later it has support for Visual Studio 2005.

Caleb W

National Instruments

0 Kudos
Message 10 of 32
(7,343 Views)