文件名称:CSerialPort-problem-
-
所属分类:
- 标签属性:
- 上传时间:2016-03-12
-
文件大小:1.45kb
-
已下载:0次
-
提 供 者:
-
相关连接:无下载说明:别用迅雷下载,失败请重下,重下不扣分!
介绍说明--下载内容来自于网络,使用问题请自行百度
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
本网站为编程资源及源代码搜集、介绍的搜索网站,版权归原作者所有! 粤ICP备11031372号
1999-2046 搜珍网 All Rights Reserved.