-
Notifications
You must be signed in to change notification settings - Fork 28
DetectCom
Chishin edited this page Jun 10, 2018
·
2 revisions
检测Com口的类,可以订阅事件进行自动检测,串口列表发生变化时触发事件。
//实例化自动刷新(简单实例)
DetectCom dc = new DetectCom(new DetectCom.DelegateSerialPortListEvent(AutoReflashSericalPortList));
//打开自动刷新
dc.Open();
使用DetectComMode属性来指定刷新串口的方式,包括Timer 定时器和Thread 线程两种方式。
若不指定DetectComMode属性,默认使用定时器刷新串口列表。
//实例化自动刷新
DetectCom dc = new DetectCom(new DetectCom.DelegateSerialPortListEvent(AutoReflashSericalPortList));
//线程刷新
dc.DetectComMode = DetectComModeEnum.Thread;
//打开自动刷新
dc.Open();
使用DetectComMode属性来指定刷新串口的时间间隔(毫秒),该属性可跟项目要求自行设定。
建议刷新间隔设定在100至500毫秒范围内,设定值太小浪费系统资源,设定值太大响应速度慢。
若不指定DetectComInterval属性,默认刷新间隔为300毫秒。
//实例化自动刷新
DetectCom dc = new DetectCom(new DetectCom.DelegateSerialPortListEvent(AutoReflashSericalPortList));
//设置刷新间隔100ms
dc.DetectComInterval = 100;
//打开自动刷新
dc.Open();
使用StrSerialPortDefaultInfo属性设定串口默认(第一个)的设备描述。
该属性赋值必须完全比配串口设备描述内容才能实现。
配成功的串口设备会在List中第一的位置出现,当多个设备符合条件时,最后一个匹配成功的设备将出现在List第一的位置。
dc.StrSerialPortDefaultInfo = "TI CC2540 USB CDC Serial Port";