• 大小: 183KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: C#
  • 标签: C#  HID  

资源简介

网上下载的C#读写HID的代码修改的,https://blog.csdn.net/u010875635/article/details/73321066,没积分请到https://github.com/beatfan/HID_Communication下载原始代码。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Collections;

namespace Hid_test
{
    public class ClassHid
    {
        Guid guidHID = Guid.Empty;
        IntPtr hDevInfo;


        //以下是调用windows的API的函数

        //获得GUID
        [DllImport(“hid.dll“)]
        public static extern void HidD_GetHidGuid(ref Guid HidGuid);


        public enum DIGCF
        {
            DIGCF_DEFAULT = 0x1
            DIGCF_PRESENT = 0x2
            DIGCF_ALLCLASSES = 0x4
            DIGCF_PROFILE = 0x8
            DIGCF_DEVICEINTERFACE = 0x10
        }

        //过滤设备,获取需要的设备
        [DllImport(“setupapi.dll“ SetLastError = true)]
        public static extern IntPtr SetupDiGetClassDevs(ref Guid ClassGuid uint Enumerator IntPtr HwndParent DIGCF Flags);


        //获取设备,true获取到
        public struct SP_DEVICE_INTERFACE_DATA
        {
            public int cbSize;
            public Guid interfaceClassGuid;
            public int flags;
            public int reserved;
        }


        [DllImport(“setupapi.dll“ CharSet = CharSet.Auto SetLastError = true)]
        public static extern Boolean SetupDiEnumDeviceInterfaces(IntPtr hDevInfo IntPtr devInfo ref Guid interfaceClassGuid UInt32 memberIndex ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData);
        

        // 获取接口的详细信息 必须调用两次 第1次返回长度 第2次获取数据 
        [StructLayout(LayoutKind.Sequential)]
        public class SP_DEVINFO_DATA
        {
            public int cbSize = Marshal.SizeOf(typeof(SP_DEVINFO_DATA));
            public Guid classGuid = Guid.Empty; // temp
            public int devInst = 0; // dumy
            public int reserved = 0;
        }

        [StructLayout(LayoutKind.Sequential Pack = 2)]
        internal struct SP_DEVICE_INTERFACE_DETAIL_DATA
        {

            internal int cbSize;

            internal short devicePath;

        }

        [DllImport(“setupapi.dll“ SetLastError = true CharSet = CharSet.Auto)]
        private static extern bool SetupDiGetDeviceInterfaceDetail(IntPtr deviceInfoSet ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData IntPtr deviceInterfaceDetailData
            int deviceInterfaceDetailDataSize ref int requiredSize SP_DEVINFO_DATA deviceInfoData);



        //获取设备文件

        [DllImport(“kernel32.dll“ SetLastError = true)]
        private static extern int CreateFile(
            string lpFileName                            // file name
            uint dwDesiredAccess                        // access mode
            uint dwShareMode                            // share mode
            uint lpSecurityAttributes                    // SD
            uint dwCreationDisposition                    // how to create
            uint dwFlagsAndAttributes                    // file attributes
            uint hTemplateFile                            // handle to

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

     文件        307  2018-05-03 10:27  HID_Communication\.git\config

     文件         73  2018-05-03 10:27  HID_Communication\.git\description

     文件         23  2018-05-03 10:27  HID_Communication\.git\HEAD

     文件        478  2018-05-03 10:27  HID_Communication\.git\hooks\applypatch-msg.sample

     文件        896  2018-05-03 10:27  HID_Communication\.git\hooks\commit-msg.sample

     文件        189  2018-05-03 10:27  HID_Communication\.git\hooks\post-update.sample

     文件        424  2018-05-03 10:27  HID_Communication\.git\hooks\pre-applypatch.sample

     文件       1642  2018-05-03 10:27  HID_Communication\.git\hooks\pre-commit.sample

     文件       1348  2018-05-03 10:27  HID_Communication\.git\hooks\pre-push.sample

     文件       4951  2018-05-03 10:27  HID_Communication\.git\hooks\pre-rebase.sample

     文件        544  2018-05-03 10:27  HID_Communication\.git\hooks\pre-receive.sample

     文件       1239  2018-05-03 10:27  HID_Communication\.git\hooks\prepare-commit-msg.sample

     文件       3610  2018-05-03 10:27  HID_Communication\.git\hooks\update.sample

     文件       2205  2018-05-03 10:27  HID_Communication\.git\index

     文件        240  2018-05-03 10:27  HID_Communication\.git\info\exclude

     文件        191  2018-05-03 10:27  HID_Communication\.git\logs\HEAD

     文件        191  2018-05-03 10:27  HID_Communication\.git\logs\refs\heads\master

     文件        191  2018-05-03 10:27  HID_Communication\.git\logs\refs\remotes\origin\HEAD

     文件         40  2018-05-03 10:27  HID_Communication\.git\objects\14\5a977d26a404322c6dbf29a0eb862433c2cf2e

     文件       1184  2018-05-03 10:27  HID_Communication\.git\objects\15\0f2169bf7ae7e518caf3ef47a8cf65b8c42ec0

     文件       1730  2018-05-03 10:27  HID_Communication\.git\objects\17\4ebc727903fe8648fc4dec10d4e33de464b52b

     文件        136  2018-05-03 10:27  HID_Communication\.git\objects\22\87106f76fa5df14603813ac7a328d65dd9b5c4

     文件         35  2018-05-03 10:27  HID_Communication\.git\objects\2b\cc8f2c5390ad7aa13f3b15260152baa5ea83a9

     文件        367  2018-05-03 10:27  HID_Communication\.git\objects\30\476bd22024a544026353b69a1042da9b63e5a3

     文件        186  2018-05-03 10:27  HID_Communication\.git\objects\39\645652af62950ebf3b28ec3a5400dcec30b1c4

     文件        910  2018-05-03 10:27  HID_Communication\.git\objects\3f\a13bb918c867ff7772b95dffcec91cc17b564f

     文件       3974  2018-05-03 10:27  HID_Communication\.git\objects\3f\d5dfba1db0d2f6431bc6c9b39e4d3ec3c1915e

     文件        163  2018-05-03 10:27  HID_Communication\.git\objects\41\4b9d82cb308d7311c5d60826b3dc29d905da1f

     文件        384  2018-05-03 10:27  HID_Communication\.git\objects\44\eb6f31030e6d8d4e11b76aa1dd47cf5140498a

     文件        783  2018-05-03 10:27  HID_Communication\.git\objects\50\5c2d2f025a5d74284eb81c5d11cf3e9c3c2447

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

评论

共有 条评论