资源简介

C# USB数据接收与发送,可以作参考学习之用。

资源截图

代码片段和文件信息

//Download by http://www.NewXing.com
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 USB
{
    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)
                                {
                                    richTextBox1.AppendText(“U盘已插入,盘符为:“ + drive.Name.ToString() + “\r\n“);
                                    break;
                                }
                            }
                            break;
                        case DBT_CONFIGCHANGECANCELED:
                            MessageBox.Show(“2“);
                            break;
                        case DBT_CONFIGCHANGED:
                            MessageBox.Show(“3“);
                            break;
                        case DBT_CUSTOMEVENT:
                            MessageBox.Show(“4“);
                            break;
                        case DBT_DEVICEQUERYREMOVE:
                            MessageBox.Show(“5“);
                            break;
                        case DBT_DEVICEQUERYREMOVEFAILED:
                            MessageBox.Show(“6“);
                            break;
                        case DBT_DEVICEREMOVECOMPLETE: //U盘卸载
                            richTextBox1.AppendText(“U盘已卸载,盘符为:“);
                            break;
                       

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    .......     55167  1999-12-15 19:58  VBUsb\CY7C63000\usbhidio.asm

    .......      2862  1999-11-26 15:05  VBUsb\CY7C63000\usbhidio.hex

    .......     89711  1999-11-26 15:05  VBUsb\CY7C63000\usbhidio.lst

    .......      3650  1999-11-26 15:05  VBUsb\CY7C63000\usbhidio.rom

    .......      1465  1999-12-15 21:17  VBUsb\usbhidio.inf

     文件       7716  2013-01-12 23:06  VBUsb\VisualBasic\ApiDeclarations.bas

     文件      27466  2013-01-12 23:06  VBUsb\VisualBasic\frmMain.frm

    .......     49152  1999-12-15 21:30  VBUsb\VisualBasic\usbhidio.exe

     文件        879  2013-01-12 23:06  VBUsb\VisualBasic\usbhidio.vbp

    .......        90  2004-03-28 15:35  VBUsb\VisualBasic\usbhidio.vbw

     文件       4141  2013-01-12 23:06  USB\Form1.cs

     文件       2666  2013-01-12 23:06  USB\Form1.Designer.cs

    .......      5814  2007-09-15 12:51  USB\Form1.resx

    .......       240  2008-07-01 10:20  USB\obj\USB.csproj.FileList.txt

     文件        500  2013-01-12 23:06  USB\Program.cs

     文件       1200  2013-01-12 23:06  USB\Properties\AssemblyInfo.cs

     文件       2898  2013-01-12 23:06  USB\Properties\Resources.Designer.cs

    .......      5612  2007-09-15 10:35  USB\Properties\Resources.resx

     文件       1124  2013-01-12 23:06  USB\Properties\Settings.Designer.cs

    .......       249  2007-09-15 10:35  USB\Properties\Settings.settings

    .......      3213  2007-09-15 10:37  USB\USB.csproj

    .......       894  2007-09-15 10:36  USB\USB.sln

    ..A..H.     12288  2008-07-01 10:36  USB\USB.suo

     文件       4544  2013-01-12 23:06  UsbEject\About.cs

    .......     43688  2006-03-19 12:39  UsbEject\About.resx

     文件        783  2013-01-12 23:06  UsbEject\AssemblyInfo.cs

    .......    171819  2006-03-19 13:07  UsbEject\Icons.resx

     文件       8615  2013-01-12 23:06  UsbEject\Library\Device.cs

     文件        998  2013-01-12 23:06  UsbEject\Library\DeviceCapabilities.cs

     文件       9000  2013-01-12 23:06  UsbEject\Library\DeviceClass.cs

............此处省略30个文件信息

评论

共有 条评论