• 大小: 0.19M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-04-25
  • 语言: C#
  • 标签: hid  usb  sb  通信  

资源简介

USBHID通信

资源截图

代码片段和文件信息

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;

namespace USBHIDControl
{
    public partial class Form1 : Form
    {
        USBHID usbHID = null;
        public Form1()
        {
            InitializeComponent();
            usbHID = new USBHID();

            foreach (string device in usbHID.GetDeviceList())
                list_UsbHID.Items.Add(device);
            usbHID.DataReceived += usbHID_DataReceived;
            usbHID.DeviceRemoved += usbHID_DeviceRemoved;
        }

        void usbHID_DeviceRemoved(object sender EventArgs e)
        {
            report myRP = (report)e;
            if (InvokeRequired)
            {
                Invoke(new EventHandler(usbHID_DeviceRemoved) new object[] { sender e });
            }
            else
            {
                tb_information.Text = “设备连接“;
            }
        }

        void usbHID_DataReceived(object sender EventArgs e)
        {
            report myRP = (report)e;
            if (InvokeRequired)
            {
                Invoke(new EventHandler(usbHID_DataReceived) new object[] { sender e });
            }
            else
            {
                tb_information.Text +=  “\r\n“ +USBHID.ByteToHexString(myRP.reportBuff);
            }
        }

        /// 
        /// open USB HID
        /// 

        /// 
        /// 
        private void btn_connect_Click(object sender EventArgs e)
        {
            if (list_UsbHID.SelectedItem == null) {
                tb_information.Text += “\r\n vendorID和productID不能为空“;
                return;
            }

            if (usbHID.OpenUSBHid(list_UsbHID.SelectedItem.ToString()))
                tb_information.Text += “\r\n open success“;
            else
                tb_information.Text += “\r\n open fail“;
        }

        private void btn_send_Click(object sender EventArgs e)
        {
            tb_information.Text +=“\r\n w: “+ usbHID.WriteUSBHID(tb_send.Text);
        }

        private void btn_clear_Click(object sender EventArgs e)
        {
            tb_information.Text = ““;
        }
    }
}

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

    .CA..H.     39936  2018-01-03 05:06  USBHIDControl\.vs\USBHIDControl\v15\.suo

    .CA....         0  2018-01-03 04:56  USBHIDControl\.vs\USBHIDControl\v15\Server\sqlite3\db.lock

    .CA....    577536  2018-01-03 05:06  USBHIDControl\.vs\USBHIDControl\v15\Server\sqlite3\storage.ide

    .CA....     18432  2018-01-03 04:56  USBHIDControl\bin\Debug\USBHIDControl.exe

    .CA....     36352  2018-01-03 04:56  USBHIDControl\bin\Debug\USBHIDControl.pdb

    .CA....     11600  2014-11-13 23:41  USBHIDControl\bin\Debug\USBHIDControl.vshost.exe

    .CA....       490  2010-03-17 22:39  USBHIDControl\bin\Debug\USBHIDControl.vshost.exe.manifest

    .CA....      2391  2014-11-13 23:04  USBHIDControl\Form1.cs

    .CA....      6794  2014-11-13 23:04  USBHIDControl\Form1.Designer.cs

    .CA....      5817  2014-11-13 23:04  USBHIDControl\Form1.resx

    .CA....      2494  2018-01-03 04:57  USBHIDControl\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

    .CA....      7113  2018-01-03 04:57  USBHIDControl\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

    .CA....       220  2014-11-13 23:04  USBHIDControl\obj\x86\Debug\GenerateResource.read.1.tlog

    .CA....       562  2014-11-13 23:04  USBHIDControl\obj\x86\Debug\GenerateResource.write.1.tlog

    .CA....        42  2018-01-03 04:56  USBHIDControl\obj\x86\Debug\USBHIDControl.csproj.CoreCompileInputs.cache

    .CA....      2011  2018-01-03 04:56  USBHIDControl\obj\x86\Debug\USBHIDControl.csproj.FileListAbsolute.txt

    .CA....       939  2018-01-03 04:56  USBHIDControl\obj\x86\Debug\USBHIDControl.csproj.GenerateResource.Cache

    .CA....     18432  2018-01-03 04:56  USBHIDControl\obj\x86\Debug\USBHIDControl.exe

    .CA....       180  2018-01-03 04:56  USBHIDControl\obj\x86\Debug\USBHIDControl.Form1.resources

    .CA....     36352  2018-01-03 04:56  USBHIDControl\obj\x86\Debug\USBHIDControl.pdb

    .CA....       180  2018-01-03 04:56  USBHIDControl\obj\x86\Debug\USBHIDControl.Properties.Resources.resources

    .CA....       494  2014-11-13 23:04  USBHIDControl\Program.cs

    .CA....      1358  2014-11-13 23:04  USBHIDControl\Properties\AssemblyInfo.cs

    .CA....      2877  2014-11-13 23:04  USBHIDControl\Properties\Resources.Designer.cs

    .CA....      5612  2014-11-13 23:04  USBHIDControl\Properties\Resources.resx

    .CA....      1099  2014-11-13 23:04  USBHIDControl\Properties\Settings.Designer.cs

    .CA....       249  2014-11-13 23:04  USBHIDControl\Properties\Settings.settings

    .CA....      8627  2014-11-13 23:04  USBHIDControl\USBHID.cs

    .CA....      3804  2014-11-13 23:04  USBHIDControl\USBHIDControl.csproj

    .CA....       867  2014-11-14 00:08  USBHIDControl\USBHIDControl.sln

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

评论

共有 条评论