文件名称:CSerialPort-problem-
介绍说明--下载内容均来自于网络,请自行研究使用
CSerialPort是一个很好的串口通讯类,但它没有关闭串口的方法,如果对这个类的实现原理不了解,自行编写串口关闭方法可能会带来如下问题:
1、用closehandle方法关闭串口:由于调用类方法StartMonitoring后会生成一个串口通信线程,这个线程中要不停地访问串口,这种方法会带来明显的错误。
2、先用StopMonitoring方法停止串口监听,然后用closehandle关闭串口:由于StopMonitoring只是将进程挂起,这样做将使程序结束时解构函数无法将中止事件发送到线程,可能导致程序不能完全退出,主窗口关闭后仍可在进程管理器中看到进程。
3、先用SetEvent发送中止事件给线程,等待线程结束后再用closehandle关闭串口,程序如下:-CSerialPort class is a good serial interface communication, but it has no closing method of the serial port, if you don t understand the implementation principle of this class, to write a serial port closure method may lead to the following questions:
1, close a serial port with the closehandle method: as the call after class methods StartMonitoring generates a serial port communication thread, the thread to keep access to a serial port, this method can bring obvious errors.
2, use StopMonitoring method first stop serial port to monitor, then use closehandle close the serial port: because StopMonitoring just hang up the process, doing so will make the program at the end of the destructors cannot send to suspend the event to the thread, may cause the program can t quit, main window is turned off, can still be seen in the process in task manager.
3, with SetEvent first send the thread to suspend the event, after the waiting thread to use closehandle to close a serial port,
1、用closehandle方法关闭串口:由于调用类方法StartMonitoring后会生成一个串口通信线程,这个线程中要不停地访问串口,这种方法会带来明显的错误。
2、先用StopMonitoring方法停止串口监听,然后用closehandle关闭串口:由于StopMonitoring只是将进程挂起,这样做将使程序结束时解构函数无法将中止事件发送到线程,可能导致程序不能完全退出,主窗口关闭后仍可在进程管理器中看到进程。
3、先用SetEvent发送中止事件给线程,等待线程结束后再用closehandle关闭串口,程序如下:-CSerialPort class is a good serial interface communication, but it has no closing method of the serial port, if you don t understand the implementation principle of this class, to write a serial port closure method may lead to the following questions:
1, close a serial port with the closehandle method: as the call after class methods StartMonitoring generates a serial port communication thread, the thread to keep access to a serial port, this method can bring obvious errors.
2, use StopMonitoring method first stop serial port to monitor, then use closehandle close the serial port: because StopMonitoring just hang up the process, doing so will make the program at the end of the destructors cannot send to suspend the event to the thread, may cause the program can t quit, main window is turned off, can still be seen in the process in task manager.
3, with SetEvent first send the thread to suspend the event, after the waiting thread to use closehandle to close a serial port,
(系统自动生成,下载前可以参看下载内容)
下载文件列表
CSerialPort problem .txt