예제 #1
0
        public byte[] SwitchReport(byte[] report)
        {
            var buff = new byte[] { 0x00, 0xAA, 0xAA, 0xAA, 0x96, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                    0x00 };
            var chk_sum = (byte)(report.Length + 1);

            buff[7] = (byte)(report.Length + 1);
            for (int i = 0; i < report.Length; i++)
            {
                chk_sum    ^= report[i];
                buff[8 + i] = report[i];
            }
            buff[8 + report.Length] = chk_sum;
            HID.HidD_SetOutputReport(m_intPtrUSB, buff, (uint)buff.Length);

            HID.HidD_GetInputReport(m_intPtrUSB, buff, (uint)buff.Length);
            var retbufflen = (UInt16)((buff[6] * 0x100) + buff[7]);

            var returnbuff = new List <byte>();

            returnbuff.AddRange(buff.Skip(8).ToArray());
            while (returnbuff.Count() < retbufflen)
            {
                HID.HidD_GetInputReport(m_intPtrUSB, buff, (uint)buff.Length);
                returnbuff.AddRange(buff.Skip(1));
            }

            return(returnbuff.Take(retbufflen - 1).ToArray());
        }
예제 #2
0
        public byte[] SendMysteriousCMD()
        {
            /*
             *          关于Report ID。在Windows环境下通过ReadFile和WriteFile访问HID设备时,必须在数据开头附加1字节的Report ID(一般为0)。在Linux环境下,如果使用HID驱动的ioctl接口,那么需要在hiddev_usage_ref结构中指定Report ID;如果使用自己编写的USB驱动程序,则不需要考虑Report ID,直接发送数据就得了。
             *          // */
            var buff = new byte[] { 0x00, 0x55, 0xAA, 0x04, 0x01, 0xFF, 0xFF, 0xFA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                    0x00 };

            HID.HidD_SetOutputReport(m_intPtrUSB, buff, (uint)buff.Length);

            HID.HidD_GetInputReport(m_intPtrUSB, buff, (uint)buff.Length);
            var returnbuff = buff.Skip(8).Take((buff[6] * 0x100) + buff[7] - 1).ToArray();

            return(returnbuff);
        }