NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I close a generation session in C#

Hello,
 
   Please see the code below, how do I close the generation session after I have completed the io operations?
 

static void Main(string[] args)

{

/* start of main */

string card_name = "PXI-6552";

bool id_query_status = false;

bool reset_instrument_status = false;

string output_channels = "0,1,2,3,10,11,12";

string input_channels = "13";

uint misc_counter=0;

uint write_data=0x00000000;

uint mask_value=0XFFFFFFFF;

niHSDIO sig_gen = niHSDIO.InitGenerationSession(card_name,id_query_status,reset_instrument_status,"");

/* create a generation session to the Digital IO card */

sig_gen.AssignStaticChannels(output_channels);

sig_gen.ConfigureDataVoltageLogicFamily(output_channels,InstrumentDriverInterop.Ivi.niHSDIOConstants._33vLogic);

misc_counter = 0;

while(misc_counter <= 10000)

{

sig_gen.WriteStaticU32(0x00000000,mask_value);

sig_gen.WriteStaticU32(0xFFFFFFFF,mask_value);

Console.Write(misc_counter+"\n");

misc_counter++;

}

} /* end of main */

How do I close the generation session?

 

Regards,

 

Kaspar

 

Regards,


Kaspar
0 Kudos
Message 1 of 3
(4,292 Views)
Hello Kaspar,
 
You should be able to close the session by calling sig_gen.Dispose() method to properly dispose of the object handle.  There is a helpful example you could reference here which runs a basic HSDIO acquisition session and demonstrates using this command.
John B.
Applications Engineer
National Instruments
Message 2 of 3
(4,266 Views)

Kaspar,

I have some more information that might help explain how (and why) the Dispose() method works.  If you look at the definition of Dispose() you see that it calls a private method, Dispose(bool). This wrapper function contains a direct call to the Close() function imported from niHSDIO.dll.  Thus you are calling the Close() method that you are probably used to seeing in the C version it has just been updated to work in C#.  Hope this is helpful!

public void Dispose(){
  this.Dispose(true
);
  System.GC.SuppressFinalize(
this
);
}

private
void Dispose(bool disposing){
  if ((this._disposed == false
)){
    PInvoke.close(
this
._handle);
    this
._handle = System.IntPtr.Zero;
  }
  this._disposed = true
;
}

John B.
Applications Engineer
National Instruments
0 Kudos
Message 3 of 3
(4,243 Views)