Ejemplo n.º 1
0
        public void CmdRead(ref byte[] dat)
        {
            byte[] array  = new byte[8];
            byte[] array2 = new byte[8];
            array[0] = 1;
            array[1] = 1;
            Array.Copy(dat, 0, array, 2, dat.Length);
            for (int i = 0; i < array2.Length; i++)
            {
                array2[i] = 0;
            }
            array2[0] = 1;
            array2[1] = 1;
            int j;

            for (j = 0; j < CUSB.__USB_RETRY_COUNT__; j++)
            {
                if (HID.HidD_SetFeature(m_intPtrUSB, array, (uint)array.Length) && HID.HidD_GetFeature(m_intPtrUSB, array2, (uint)array2.Length))
                {
                    Array.Copy(array2, 2, dat, 0, dat.Length);
                    break;
                }
                HID.HidD_FlushQueue(m_intPtrUSB);
            }
            if (j == CUSB.__USB_RETRY_COUNT__)
            {
                throw new Exception(CMessages.GetLastWin32ErrorToString());
            }
        }
Ejemplo n.º 2
0
        private static bool GetVersion(IntPtr intPtrUSB, ref string strVersion)
        {
            var result = false;

            byte[] array = new byte[8], array2 = new byte[8];
            array[0]  = 1;
            array[1]  = 16;
            array2[0] = 1;
            array2[1] = 16;
            for (var i = 0; i < CUSB.__USB_RETRY_COUNT__; i++)
            {
                if (HID.HidD_SetFeature(intPtrUSB, array, (uint)array.Length) && HID.HidD_GetFeature(intPtrUSB, array2, (uint)array2.Length))
                {
                    strVersion = string.Format("{0:c}{1:c}{2:c}{3:c}{4:c}", new object[]
                    {
                        (char)array2[2],
                        (char)array2[3],
                        (char)array2[4],
                        (char)array2[5],
                        (char)array2[6]
                    });
                    result = true;
                    break;
                }
                HID.HidD_FlushQueue(intPtrUSB);
                Thread.Sleep(1);
            }
            return(result);
        }
Ejemplo n.º 3
0
        public bool DataWrite(byte[] dat)
        {
            //Kernel32.wri
            byte[] array = new byte[8], array2 = new byte[8];
            array[0] = 1;
            array[1] = 2;
            Array.Copy(dat, 0, array, 2, dat.Length);
            for (int i = 0; i < array2.Length; i++)
            {
                array2[i] = 0;
            }
            array2[0] = 1;
            array2[1] = 2;
            if (!HID.HidD_SetFeature(m_intPtrUSB, array, (uint)array.Length))
            {
                return(false);
            }
            Thread.Sleep(5);
            int j;

            for (j = 0; j < CUSB.__USB_RETRY_COUNT__; j++)
            {
                if (HID.HidD_GetFeature(m_intPtrUSB, array2, (uint)array2.Length))
                {
                    return(true);
                }
                HID.HidD_FlushQueue(m_intPtrUSB);
                Thread.Sleep(5);
            }
            if (j == CUSB.__USB_RETRY_COUNT__)
            {
                throw new Exception(CMessages.GetLastWin32ErrorToString());
            }
            return(false);
        }