C#的usb通讯编程

转载 2007年09月23日 10:15:00
<iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-9043283529440151&amp;dt=1190513432973&amp;lmt=1190513432&amp;format=468x60_as&amp;output=html&amp;correlator=1190513432963&amp;channel=4153268400&amp;url=http%3A%2F%2Fwww.vs2005.com%2FCode%2F419%2F1%2Fdefault.aspx&amp;color_bg=FFFFFF&amp;color_text=000000&amp;color_link=000000&amp;color_url=000000&amp;color_border=FFFFFF&amp;ad_type=text_image&amp;cc=100&amp;ga_vid=1748915312.1190512828&amp;ga_sid=1190512828&amp;ga_hid=331151626&amp;ga_fc=true&amp;flash=9&amp;u_h=768&amp;u_w=1024&amp;u_ah=738&amp;u_aw=1024&amp;u_cd=32&amp;u_tz=480&amp;u_java=true" frameborder="0" width="468" scrolling="no" height="60" allowtransparency="allowtransparency"></iframe>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace U盘更新
{
    public partial class Form1 : Form
    {
        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 Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        protected override void WndProc(ref Message m)
        {
            try
            {
                if (m.Msg == WM_DEVICECHANGE)
                {
                    switch (m.WParam.ToInt32())
                    {
                        case WM_DEVICECHANGE:
                            break;
                        case DBT_DEVICEARRIVAL://U盘插入
                            DriveInfo[] s = DriveInfo.GetDrives();
                            foreach (DriveInfo drive in s)
                            {
                                if (drive.DriveType == DriveType.Removable)
                                {
                                    listBox1.Items.Add("U盘已插入,盘符为:" + drive.Name.ToString());
                                    break;
                                }
                            }
                            break;
                        case DBT_CONFIGCHANGECANCELED:
                            break;
                        case DBT_CONFIGCHANGED:
                            break;
                        case DBT_CUSTOMEVENT:
                            break;
                        case DBT_DEVICEQUERYREMOVE:
                            break;
                        case DBT_DEVICEQUERYREMOVEFAILED:
                            break;
                        case DBT_DEVICEREMOVECOMPLETE: //U盘卸载
                            break;
                        case DBT_DEVICEREMOVEPENDING:
                            break;
                        case DBT_DEVICETYPESPECIFIC:
                            break;
                        case DBT_DEVNODES_CHANGED:
                            break;
                        case DBT_QUERYCHANGECONFIG:
                            break;
                        case DBT_USERDEFINED:
                            break;
                        default:
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            base.WndProc(ref m);
        }
    }
}

 

相关文章推荐

C# USB通讯

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin...

如何通过xcode编程使MAC机器和HID的USB单片机设备进行通讯

之前大家会通过苹果IOKIT的框架里面的教程进行编程,但是z
  • czl0325
  • czl0325
  • 2014年09月03日 09:06
  • 3064

C#使用usb通讯libusbdotnet

  • 2017年11月09日 10:57
  • 446KB
  • 下载

C#编写的与usb通讯程序

  • 2012年09月20日 09:10
  • 58KB
  • 下载

【转】 在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架2

一.TcpSvr的使用方法 A.测试程序: using System; using Ibms.Net.TcpCSFramework; using System.Collections; using S...

在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(二)----使用方法

一.TcpSvr的使用方法 A.测试程序: using System; using Ibms.Net.TcpCSFramework; using System.Collections; using S...
  • educast
  • educast
  • 2012年04月08日 19:37
  • 976

在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(二)

在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(二)----使用方法  一.TcpSvr的使用方法 A.测试程序: using System; using Ibms.N...

C#网络编程(一)------最简单的基于cs的sokect通讯程序

    程序中 常用方法列表:             (1)Socket(AddressFamily af,SocketType st,ProtocolType pt)               ...
  • wap168
  • wap168
  • 2011年01月12日 06:06
  • 1953

C#通讯编程

Socket通讯: public class XmlSocket { //异步socket诊听 // Incoming data from cli...

在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(一)----基础类库部分

////////////////////////////////////////////////////////////////////////////////////////// /* 标题:在C#...
  • educast
  • educast
  • 2012年04月08日 19:37
  • 1544
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:C#的usb通讯编程
举报原因:
原因补充:

(最多只允许输入30个字)