Exemple #1
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);
        }
Exemple #2
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());
            }
        }
Exemple #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);
        }
Exemple #4
0
 public bool WriteBlock(byte[] blk, ref byte[] dataByte, ref byte status)
 {
     byte[] array = new byte[8], array2 = new byte[8], array3 = new byte[blk.Length + 1];
     array[0] = 1;
     array[1] = 128;
     for (int i = 0; i < array2.Length; i++)
     {
         array2[i] = 0;
     }
     array2[0] = 1;
     array2[1] = 128;
     array[2]  = dataByte[0];
     array[3]  = dataByte[1];
     array[4]  = dataByte[2];
     array[5]  = dataByte[3];
     array[6]  = dataByte[4];
     array[7]  = dataByte[5];
     Array.Copy(blk, 0, array3, 1, blk.Length);
     array3[0] = 2;
     if (!HID.HidD_SetFeature(m_intPtrUSB, array, (uint)array.Length) || !HID.HidD_SetFeature(m_intPtrUSB, array3, (uint)array3.Length))
     {
         return(false);
     }
     if (HID.HidD_GetFeature(m_intPtrUSB, array2, (uint)array2.Length))
     {
         status = array2[7];
         return(true);
     }
     return(false);
 }
Exemple #5
0
 public bool ReadBlock(ref byte[] blk, ref byte[] dataByte, ref byte status)
 {
     byte[] array  = new byte[8];
     byte[] array2 = new byte[8];
     byte[] array3 = new byte[blk.Length + 1];
     array[0] = 1;
     array[1] = 64;
     array[2] = dataByte[0];
     array[3] = dataByte[1];
     array[4] = dataByte[2];
     array[5] = dataByte[3];
     array[6] = dataByte[4];
     array[7] = dataByte[5];
     for (int i = 0; i < array2.Length; i++)
     {
         array2[i] = 0;
     }
     array2[0] = 1;
     array2[1] = 64;
     for (int j = 0; j < array3.Length; j++)
     {
         array3[j] = 0;
     }
     array3[0] = 2;
     if (!HID.HidD_SetFeature(m_intPtrUSB, array, (uint)array.Length))
     {
         return(false);
     }
     Thread.Sleep(1);
     if (HID.HidD_GetFeature(m_intPtrUSB, array3, (uint)array3.Length))
     {
         Array.Copy(array3, 0, blk, 0, blk.Length);
         return(true);
     }
     return(false);
 }