Closing Active Serial Port

Joined
Mar 14, 2005
Messages
10
Programming Experience
5-10
I'm using VB.NET 2005 to make a RS232 Serial Port connection with a device. I am using the new SerialPort Class that was added to .net 2.0 and I am not using any handshaking or flow control. Everything works great with 1 exception. If I try to close the serial port without first stopping the data stream coming from the device the program hangs. I wonder if I'm having trouble because the DataReceived Event is raised on another thread.
How can I close an active SerialPort.
thanks
Jonathan
 
I am using the same setup to read a digital compass. I simply use 'removehandler' to disable capturing of the data-received event and then use the close method of the serial port instance to close the port. If I am not using t again I set the instance of the serial port equl to 'nothing'
 
Back
Top