using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; namespace ICS
{
public partial class FrmMain : Form
{

#region WndProc常量
public const int WM_DEVICECHANGE = 0x219;
public const int DBT_DEVICEARRIVAL = 0x8000;
public const int DBT_CONFIGCHANGECANCELED = 0x0019;
public const int DBT_CONFIGCHANGED = 0x0018;
public const int DBT_CUSTOMEVENT = 0x8006;
public const int DBT_DEVICEQUERYREMOVE = 0x8001;
public const int DBT_DEVICEQUERYREMOVEFAILED = 0x8002;
public const int DBT_DEVICEREMOVECOMPLETE = 0x8004;
public const int DBT_DEVICEREMOVEPENDING = 0x8003;
public const int DBT_DEVICETYPESPECIFIC = 0x8005;
public const int DBT_DEVNODES_CHANGED = 0x0007;
public const int DBT_QUERYCHANGECONFIG = 0x0017;
public const int DBT_USERDEFINED = 0xFFFF;

public const int DBT_DEVTYP_OEM = 0x00000000;//OEM- or IHV-defined device type
public const int DBT_DEVTYP_PORT = 0x00000003;//Port device (serial or parallel).
public const int DBT_DEVTYP_VOLUME = 0x00000002;//Logical volume.
#endregion

[StructLayout(LayoutKind.Sequential)]
public struct DEV_BROADCASR_HDR
{
public int Size;
public int DeviceType;
public int Reserved;
}
public FrmMain()
{
InitializeComponent();
}

protected override void WndProc(ref Message m)
{
base.WndProc(ref m);//要保证这句话必须能构执行,否则会出现“创建窗口句柄时出错”,和写代码习惯有关。。
try
{
if (m.Msg != WM_DEVICECHANGE) return;
DEV_BROADCASR_HDR devHdr = (DEV_BROADCASR_HDR)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCASR_HDR));
if (devHdr.DeviceType == DBT_DEVTYP_PORT)
{
AddSerialPort();
}
}
catch { }
}

public void AddSerialPort()
{
cmboxSerial.Items.Clear();
cmboxSerial.Items.AddRange(SerialPort.GetPortNames());
}

}

}

zz Alex's BLOG 串口连接的更多相关文章

  1. 【嵌入式开发】嵌入式 开发环境 (远程登录 | 文件共享 | NFS TFTP 服务器 | 串口连接 | Win8.1 + RedHat Enterprise 6.3 + Vmware11)

    作者 : 万境绝尘 博客地址 : http://blog.csdn.net/shulianghan/article/details/42254237 一. 相关工具下载 嵌入式开发工具包 : -- 下 ...

  2. 【记录】恢复win7与ARM开发板TQ2440的串口连接

    1.给板子上电. 2.接好物理上的串口连接,板子那端就是普通的RS232串口,电脑这端是USB转串口的线的USB这头,连到电脑上,然后在Win7系统下,先去看看,当前连接的USB虚拟出来的串口是哪个口 ...

  3. Qt 串口连接

    Qt 串口连接 使用 Qt 开发上位机程序时,经常需要用到串口,在 Qt 中访问串口比较简单,因为 Qt 已经提供了 QSerialPort 和 QSerialPortInfo 这两个类用于访问串口. ...

  4. C# 串口连接的读取与发送

    一.串口连接的打开与关闭 串口,即COM口,在.NET中使用 SerialPort 类进行操作.串口开启与关闭,是涉及慢速硬件的IO操作,频繁打开或关闭会影响整体处理速度,甚至导致打开或关闭串口失败. ...

  5. RPI学习--环境搭建_串口连接

    有两种, 一种是通过MAX2323芯片连接的串口,要接VCC为芯片供电. 另一种是通过PL2302芯片连接的USB,可不接VCC,用电脑USB口为芯片供电. 下面以通过MAX2323方式为例. 1,V ...

  6. Win7下使用Putty代替超级终端通过COM串口连接开发板方法

    1.如果电脑(笔记本)没有串口接口,则需要使用一个 USB-Serial 转换线,这里使用 prolific usb-serial USB--串口转换线,首先需要在win7上安装对应的 USB--串口 ...

  7. 树莓派zero 使用usb串口连接

    使用minicom连接bash$ lsusbBus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hubBus 001 Device 0 ...

  8. vue app混合开发蓝牙串口连接(报错java.io.IOException: read failed, socket might closed or timeout, read ret: -1;at android.bluetooth.BluetoothSocket.connect at js/BluetoothTool.js:329)

    我使用的uni-app <template> <view class="bluetooth"> <!-- 发送数据 --> <view c ...

  9. laravel 安装碰到的问题:全局安装 Laravel Installer,然后用下面的指令创建新项目: laravel new blog报连接超时解决方案

    在执行laravel new project 的时候报错 cURL error 7: Failed to connect to cabinet.laravel.com port 80: Timed o ...

随机推荐

  1. pandas 中的常用数学计算

    1.开方: >>> s = pd.Series([1.2 + 1j]) >>> s.abs()

  2. Spring beanFactory ApplicationContext

    一.BeanFactoryBeanFactory 是 Spring 的“心脏”.它就是 Spring IoC 容器的真面目.Spring 使用 BeanFactory 来实例化.配置和管理 Bean. ...

  3. xlwt使用

    xlwt引入xlwt,import xlwt 新建工作簿,xlsx = xlwt.Workbook( encoding="utf-8" ),参数:设置编码为utf-8 添加工作表, ...

  4. Light Probe Proxy Volume

    [Light Probe Proxy Volume] The Light Probe Proxy Volume (LPPV) component allows you to use more ligh ...

  5. 十 suprocess模块

    1 import subprocess 2 3 ''' 4 sh-3.2# ls /Users/egon/Desktop |grep txt$ 5 mysql.txt 6 tt.txt 7 事物.tx ...

  6. 第二章 向量(d5)有序向量:插值查找

  7. Centos 7 下 LAMP 部署

    一.介绍 LAMP is a combination of operating system and open-source software stack. The acronym of LAMP i ...

  8. 优化-最小化损失函数的三种主要方法:梯度下降(BGD)、随机梯度下降(SGD)、mini-batch SGD

    优化函数 损失函数 BGD 我们平时说的梯度现将也叫做最速梯度下降,也叫做批量梯度下降(Batch Gradient Descent). 对目标(损失)函数求导 沿导数相反方向移动参数 在梯度下降中, ...

  9. 安装程序遇到错误0x80240037

    安装ie插件或者微软的一些其他程序等报错0x80240037,如下图所示: 解决办法: 下面我将以ie的插件IE11-Windows6.1-KB3008923-x64.msu安装为例: 1.把IE11 ...

  10. UmBasketella

    UmBasketella http://poj.org/problem?id=3737 Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...