C# 与HID设备的通信在读/写时挂起(AS3992 RFID读卡器)

C# 与HID设备的通信在读/写时挂起(AS3992 RFID读卡器),c#,.net,usb,hid,C#,.net,Usb,Hid,我正在尝试与基于AS3992芯片的超高频RFID阅读器通信。 这个设备是Windows标准HID检测的,它与第三方应用程序(我发现一些UHF RFID阅读器GUI由LINKSpRITE工作,但它看起来像一些旧的C++应用程序)。 因此,我正在尝试将此设备支持集成到我的.NET应用程序中。经过一些研究后,我尝试了,但当我尝试向这个设备写入一些东西(本示例中的初始序列)时,它会挂起“写入” 有人知道我做错了什么吗 谢谢大家! 我的操作系统是Win 8.1 x64 以下是示例应用程序: 使用图书馆;

我正在尝试与基于AS3992芯片的超高频RFID阅读器通信。 这个设备是Windows标准HID检测的,它与第三方应用程序(我发现一些UHF RFID阅读器GUI由LINKSpRITE工作,但它看起来像一些旧的C++应用程序)。 因此,我正在尝试将此设备支持集成到我的.NET应用程序中。经过一些研究后,我尝试了,但当我尝试向这个设备写入一些东西(本示例中的初始序列)时,它会挂起“写入”

有人知道我做错了什么吗

谢谢大家!

我的操作系统是Win 8.1 x64

以下是示例应用程序:


使用图书馆;
命名空间HidTest2
{
班级计划
{
静态void Main(字符串[]参数)
{
var devices=HidDevices.Enumerate(0x1325);
var rfid=devices.First();
OpenDevice();
Write(新字节[]{0x31,0x03,0x01});//应用程序挂起
while(true)//我到不了这里
{
睡眠(50);
var result=rfid.Read();
控制台。写入(结果。数据);
}
}
}
}

我也试过HidSharp,但我得到了同样的结果。检测到HID设备,但我无法写入


PSS:这是设备:

我找不到您提到的AS3229芯片的数据表,所以我在这里猜测

该设备可能呈现为USB键盘,因此您通常只能向其写入LED状态位(大写锁定、数字锁定、移位)。这就是你想写的吗

尝试删除写操作,然后等待扫描的RFID字符串进入

编辑:看起来此设备是通过USB以串行设备的形式显示的…我在此处找到了与之非常匹配的描述:


如果它是您正在测试的同一台设备,那么我会尝试通过COM端口API与它通信,而不是使用您一直使用的相对较低级别的HID API。

因为每次收到电子邮件时,我都知道如何解决此问题,如果我解决了此问题,下面是一个答案:


我必须将HID通信的原始固件替换为串行通信的固件(在互联网上搜索“as399x uart 115200十六进制”或“as399x uart 9600十六进制”),然后它就像一个sharm一样工作。当然,对于C8051Fxxx(大约20美元,来自中国)和USB串行转换器,您需要合适的编程器,并熟悉一些焊接(您必须在板上焊接JTAG和串行端口的引脚)。

如上所述,该设备实际上可能不是Hid设备。您是否尝试过通过USB设备而不是Hid设备进行枚举?下面是一些列举USB或Hid设备的代码。代码是

对于Hid设备,使用类别GUID:4D1E55B2-F16F-11CF-88CB-001111000030

对于Win USB设备,请使用:dee824ef-729b-4a0e-9c14-b7117d33a817

公共异步任务GetConnectedDeviceDefinitions(uint?vendorId,uint?productId)
{
返回等待任务。运行(()=>
{
var deviceDefinitions=新集合();
var spDeviceInterfaceData=新的spDeviceInterfaceData();
var spDeviceInfoData=新的spDeviceInfoData();
var spDeviceInterfaceDetailData=新的spDeviceInterfaceDetailData();
spDeviceInterfaceData.CbSize=(uint)Marshal.SizeOf(spDeviceInterfaceData);
spDeviceInfoData.CbSize=(uint)Marshal.SizeOf(spDeviceInfoData);
var guidString=ClassGuid.ToString();
var copyOfClassGuid=新Guid(guidString);
变量i=apicall.SetupDiGetClassDevs(参考copyOfClassGuid、IntPtr.Zero、IntPtr.Zero、apicall.DigcfDeviceinterface | apicall.DigcfPresent);
如果(IntPtr.Size==8)
{
spDeviceInterfaceDetailData.CbSize=8;
}
其他的
{
spDeviceInterfaceDetailData.CbSize=4+Marshal.SystemDefaultCharSize;
}
var x=-1;
var productIdHex=GetHex(productId);
var vendorHex=GetHex(vendorId);
while(true)
{
x++;
var issucess=APICalls.setupDienumDeviceInterface(i,IntPtr.Zero,ref copyOfClassGuid,(uint)x,ref spDeviceInterfaceData);
如果(!isSuccess)
{
var errorCode=Marshal.GetLastWin32Error();
if(errorCode==APICalls.ERROR\u无\u更多\u项)
{
打破
}
抛出新异常($“无法枚举设备。错误代码:{errorCode}”);
}
isSuccess=APICalls.SetupDiGetDeviceInterfaceDetail(i,参考spDeviceInterfaceData,参考spDeviceInterfaceDetailData,256,out,参考SPDeviceInfo数据);
WindowsDeviceBase.HandleError(isSuccess,“无法获取设备接口详细信息”);
//请注意,这是有点讨厌,但我们可以过滤视频和Pid的方式,我认为。。。
如果(vendorId.HasValue&!spDeviceInterfaceDetailData.DevicePath.ToLower().Contains(vendorHex))继续;
如果(productId.HasValue&&!spDeviceInterfaceDetailData.DevicePath.ToLower().Contains(productIdHex))继续;
添加(GetDeviceDefinition(spDeviceInterfaceDetailData.DevicePath));
}
Apicall.SetupDiDestroyDeviceInfo列表(i);
返回设备定义;
});
}

您从哪里获得0x1325?听起来你想和你的音频硬件通话。这是供应商ID,是正确的。。。。这不是问题…嗨,我能找到数据表作为“AS3992数据表”在谷歌的第一个结果。不幸的是,这个设备没有键盘的功能。您可以在代码中看到的“写入”是“初始化序列”,它告诉设备“开始读取RFID芯片”。顺便说一句:
public async Task<IEnumerable<DeviceDefinition>> GetConnectedDeviceDefinitions(uint? vendorId, uint? productId)
    {
        return await Task.Run<IEnumerable<DeviceDefinition>>(() =>
        {
            var deviceDefinitions = new Collection<DeviceDefinition>();
            var spDeviceInterfaceData = new SpDeviceInterfaceData();
            var spDeviceInfoData = new SpDeviceInfoData();
            var spDeviceInterfaceDetailData = new SpDeviceInterfaceDetailData();
            spDeviceInterfaceData.CbSize = (uint)Marshal.SizeOf(spDeviceInterfaceData);
            spDeviceInfoData.CbSize = (uint)Marshal.SizeOf(spDeviceInfoData);

            var guidString = ClassGuid.ToString();
            var copyOfClassGuid = new Guid(guidString);

            var i = APICalls.SetupDiGetClassDevs(ref copyOfClassGuid, IntPtr.Zero, IntPtr.Zero, APICalls.DigcfDeviceinterface | APICalls.DigcfPresent);

            if (IntPtr.Size == 8)
            {
                spDeviceInterfaceDetailData.CbSize = 8;
            }
            else
            {
                spDeviceInterfaceDetailData.CbSize = 4 + Marshal.SystemDefaultCharSize;
            }

            var x = -1;

            var productIdHex = GetHex(productId);
            var vendorHex = GetHex(vendorId);

            while (true)
            {
                x++;

                var isSuccess = APICalls.SetupDiEnumDeviceInterfaces(i, IntPtr.Zero, ref copyOfClassGuid, (uint)x, ref spDeviceInterfaceData);
                if (!isSuccess)
                {
                    var errorCode = Marshal.GetLastWin32Error();
                    if (errorCode == APICalls.ERROR_NO_MORE_ITEMS)
                    {
                        break;
                    }

                    throw new Exception($"Could not enumerate devices. Error code: {errorCode}");
                }

                isSuccess = APICalls.SetupDiGetDeviceInterfaceDetail(i, ref spDeviceInterfaceData, ref spDeviceInterfaceDetailData, 256, out _, ref spDeviceInfoData);
                WindowsDeviceBase.HandleError(isSuccess, "Could not get device interface detail");

                //Note this is a bit nasty but we can filter Vid and Pid this way I think...
                if (vendorId.HasValue && !spDeviceInterfaceDetailData.DevicePath.ToLower().Contains(vendorHex)) continue;
                if (productId.HasValue && !spDeviceInterfaceDetailData.DevicePath.ToLower().Contains(productIdHex)) continue;

                deviceDefinitions.Add(GetDeviceDefinition(spDeviceInterfaceDetailData.DevicePath));
            }

            APICalls.SetupDiDestroyDeviceInfoList(i);

            return deviceDefinitions;
        });
}