Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing C# Synchronized Read/Write Functions

Hey Caleb,

It looks like we have Measurement Studio 7.0 here.  I tried finding the GpibSession stuff, but I'm not sure if thats in this version.  Do you know if it is?

Thanks,

Nick

0 Kudos
Message 11 of 32
(3,992 Views)

Hi Nick,

 

Measurement Studio 7.1 only has support for Visual Studio 2003.  You aren't seeing all of the capabilities of Measurement Studio because it doesn't integrate properly with Visual Studio 2005.  

Caleb W

National Instruments

0 Kudos
Message 12 of 32
(3,990 Views)

Hey Caleb,

Ok, I think the problem I'm having now is doing too many Device.Write()/Device.Read()'s on top of each other.  I have a loop that does a Write, then a Read, and what happens is it does the first Write/Read fine, but when it goes to do the second iteration thourgh, it times out.  I put a delay of like 5 milliseconds at the end of the loop and it works most of the time (still times out after some amount of time).  Is there a way to check if its ok to read/write to the device?

Thanks,

Nick

0 Kudos
Message 13 of 32
(3,951 Views)

Hi Nick,

 

It depends on how your device responds to commands.  Some devices set the RQS bit and others set the SRQ line.  If you use the functions in Measurement Studio you can check those bits.  If those functions aren't available, you might need to put a longer wait. 

Caleb W

National Instruments

0 Kudos
Message 14 of 32
(3,947 Views)

Hey Caleb,

Do you know if the Device.Wait(GpibStatusFlags.IOComplete | GpibStatusFlags.Timeout) works?  It seems like I have to reset the flags or something (what I see is it looks like it just continues regardless of the flags), but I dont see any command to do that.  Would this work for what I need?  Should I maybe wait on a different GpibStatusFlags?  Should I be waiting on the Board object or the individual Device object?

Thanks,

Nick 

Message Edited by Schoon on 10-20-2008 05:22 PM
0 Kudos
Message 15 of 32
(3,945 Views)

Hi Nick,

 

The IOComplete Status flag will be set once the communication is successful, not when the device is finished and ready for the next command.  Are you able to use the function: public bool CheckForSrq().  This will return true if the SRQ line is asserted and false if the line is not asserted.  You could use this if your device sets the SRQ line.

Caleb W

National Instruments

0 Kudos
Message 16 of 32
(3,941 Views)

Hey Caleb,

Yeah, I think the solution you mentioned about making sure the command is complete works.  But now I seem to be running into a problem with the actual Device.Write and Device.ReadString calls running back to back.  I tried adding the IOComplete status flag wait, but still had problems (mainly timing out).  When I intruduced a sleep in between the Write/Read calls, it worked.  So I'm not sure if I have to clear those status flags before doing a Wait on them or what (because it seems to just go right through them).

Thanks,

Nick

0 Kudos
Message 17 of 32
(3,923 Views)

Hi Nick,

 

Once the actual write completes for Device.Write it will set the IOComplete Flag so you will go directly into the Device.Read even if the device is not yet ready to be read.  That is why you go straight through the Wait.  If your device supports setting the SRQ line, you can check that, but beyond that you will need to rely on a time delay.

Caleb W

National Instruments

0 Kudos
Message 18 of 32
(3,919 Views)

My current setup is that I have a USB GPIB Board and 4 Lambda power supplies.  I create the Board object and then create 4 seperate device objects for each power supply.

This is the setup:

 

mGpibBoard = new Board(mGPIBConfiguration.GPIBBoardID);

mGpibBoard.AbortAsynchronousIO();

mGpibBoard.TerminateReadOnEndOfString = false;

 

mGpibBoard.SendInterfaceClear();

mGpibBoard.BecomeActiveController(true);

mGpibBoard.SetEndOnEndOfString = false;

mGpibBoard.SetEndOnWrite = true;

mGpibBoard.BusTiming = BusTimingType.HighSpeed;

mGpibBoard.UseAutomaticSerialPolling = true;

 

Example device setup:

 

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

Unit.TerminateReadOnEndOfString = false;

Unit.IOTimeout = GPIB_DEVICE_TIMEOUT_VALUE;

Unit.SetEndOnEndOfString = false;

Unit.SetEndOnWrite = true;

Unit.ReaddressingEnabled = true;

 try

 

{

gpibUnit.Unit.Write("*ESE 0;*SRE 16"); // Only care about MAV

}

 

Once I have all 4 devices setup, I loop through them to check the voltages,currents, state, etc

I want to syncronize them so my program does not advance until I have the information from these calls.

 

I've setup the the following sync read/write functions as per our discussions:

 

 public void SyncWrite(String command) // this seems to be ok for what I need

{

   if (Unit != null)

   {

      Unit.Write(command +
";*OPC?");

      Unit.Wait(GpibStatusFlags.DeviceServiceRequest | GpibStatusFlags.Timeout);

      String restult = Unit.ReadString(128);

      Unit.Wait(GpibStatusFlags.End | GpibStatusFlags.Timeout); // Wait for MAV or timeout

   }

}

 public String SyncRead(String command)

{

   if (Unit != null)

   {

      // Setup for a mav event or message avialable

      Unit.Write(command);

      Unit.Wait(GpibStatusFlags.DeviceServiceRequest | GpibStatusFlags.Timeout); // Wait for MAV (command query puts data in queue that triggers MAV)

       GpibStatusFlags status = Unit.GetCurrentStatus();

      status &= GpibStatusFlags.Timeout;

      if (status != GpibStatusFlags.Timeout)

      {         read_string = Unit.ReadString(128);  <-- Problem is here

          Unit.Wait(GpibStatusFlags.End | GpibStatusFlags.Timeout); // Wait for End of String found 

      }

   }

   return read_string;

}

 

The problem I'm running into is that at random times for random devices, the line above that says "Problem is here" times out.  It's complete random.  I looked at the IOTimeout values and they are set 10 seconds for the Board and I set the devices to 1 second (cant wait too long).  Do you have any idea why it would time out there randomly.  It seems like the MAV is triggering the event, but when it goes to read that data out, there isnt any in the queue.  I do get the correct current and voltage readings for each power supply that I expect.  It must be something I'm setting up wrong.  Do you know off hand how long Device ReadString calls typically take?

 

Thanks,

Nick

0 Kudos
Message 19 of 32
(3,894 Views)

Hey Caleb,

I also set the IOTimeout for each device to 10 seconds and it still times out.  Do the Board and Device IOTimeout values need to be the same?  Could a ReadString call really take more than 10 second per device?  Should I be configuring the GPIB cables in any special way (right now they are just connected randomly, not in any star or other configuration)?  Let me know if you think of anything or see any problems in my code.

Thanks,

Nick

Message Edited by Schoon on 10-23-2008 10:19 AM
0 Kudos
Message 20 of 32
(3,892 Views)