10-10-2008 08:23 AM
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 |
10-13-2008 12:23 PM
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.
National Instruments
10-15-2008 09:02 AM - edited 10-15-2008 09:05 AM
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
10-16-2008 09:14 AM
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).
National Instruments
10-16-2008 10:04 AM
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
10-16-2008 10:19 AM
National Instruments
10-16-2008 10:27 AM
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
10-16-2008 11:35 AM
National Instruments
10-16-2008 12:32 PM
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
10-17-2008 10:20 AM
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.
National Instruments