Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

closing serial port

I have the following code:

session = ResourceManager.GetLocalManager().Open(CurrentSession);
CurrentSerialSession = session as SerialSession;

which opens com1 @ 9600 baud, no parity, 1 stop bit, etc.

If I want to close this and free up the serial port for other applications would I do this:

session.Dispose();

I have tried this as well as CurrentSerialSession.Dispose(); to no avail. How do I close the serial port once
I have opened it?
Thanks,
Barry
0 Kudos
Message 1 of 2
(3,156 Views)
The call to Dispose should close the VISA session, and you should see the same behavior whether you call the method through a Session reference or a SerialSession reference. Can you describe in some more detail the behavior you are observing when calling Dispose on the session, and post a block of code that produces the problem?

You might also be interested to know about the "using" expression in C#:

using (SerialSession serialSession = ResourceManager.GetLocalManager().Open(CurrentSession))
{
//Code to use the serial session goes here.
};

The using expression calls Dispose on the object in the declaration when the block exits. It also guarantees that even if the block of code exits prematurely because of an exception, the Dispose method is called on the serialSession object.
0 Kudos
Message 2 of 2
(3,153 Views)