Exemplo n.º 1
0
        protected byte[] ReadRAW(int cmd, int addr)
        {
            if (this.IsOpen())
            {
                byte[] buff     = new byte[64];
                byte[] buffer   = new byte[64];
                uint   numbytes = 0;
                int    i;

                int nbytes = 0;
                USBXpress.ReturnCodes ret = USBXpress.ReturnCodes.SI_SUCCESS;

                ClearInputBuffer(handle);
                buffer[0] = (byte)'F';
                buffer[1] = (byte)'R';
                buffer[2] = (byte)'M';
                buffer[3] = (byte)cmd;
                buffer[4] = (byte)(addr & 0xff);
                buffer[5] = (byte)((addr >> 8) & 0xff);


                for (i = 4; i < 64; i++)
                {
                    buffer[i] = 0;
                }
                usbXpress.SI_Write(handle, buffer, OLEN, ref nbytes, 0);

                USBXpress.RXQueueStatus queueStatus = USBXpress.RXQueueStatus.SI_RX_EMPTY;
                numbytes = 0;

                for (i = 0; i < 50 && numbytes < ILEN; i++)
                {
                    usbXpress.SI_CheckRXQueue(handle, ref numbytes, ref queueStatus);
                    Thread.Sleep(20);
                }
                ret = usbXpress.SI_Read(handle, buffer, 64, ref nbytes, 0);
                for (i = 0; i < 64; i++)
                {
                    buff[i] = buffer[i];
                }

                if (ret != USBXpress.ReturnCodes.SI_SUCCESS)
                {
                    isOpen = false;
                }

                return(buff);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public void ClearInputBuffer(UInt32 handle)
        {
            USBXpress.RXQueueStatus queueStatus = USBXpress.RXQueueStatus.SI_RX_EMPTY;
            uint unumbytes = 0;
            int  numbytes;

            do
            {
                usbXpress.SI_CheckRXQueue(handle, ref unumbytes, ref queueStatus);
                numbytes = (int)unumbytes;
                usbXpress.SI_Read(handle, new byte[numbytes], numbytes, ref numbytes, 0);
            } while (queueStatus != USBXpress.RXQueueStatus.SI_RX_EMPTY);
        }
Exemplo n.º 3
0
        protected void WaitACK_USB()
        {
            uint numbytes = 0;

            byte[] buffer = new byte[OLEN];
            int    nbytes = 0;

            USBXpress.RXQueueStatus queueStatus = USBXpress.RXQueueStatus.SI_RX_EMPTY;
            int i;

            for (i = 0; i < 20 && numbytes != ILEN; i++)
            {
                usbXpress.SI_CheckRXQueue(handle, ref numbytes, ref queueStatus);
                Thread.Sleep(5);
            }
            if (numbytes == ILEN)
            {
                usbXpress.SI_Read(handle, buffer, 64, ref nbytes, 0);
            }
        }
Exemplo n.º 4
0
 public USBXpress.ReturnCodes SI_CheckRXQueue(UInt32 cyHandle, ref UInt32 lpdwNumBytesInQueue, ref USBXpress.RXQueueStatus lpdwQueueStatus)
 {
     if (tipo == TypeOS.i64)
     {
         return(USBXpress64.SI_CheckRXQueue(cyHandle, ref lpdwNumBytesInQueue, ref lpdwQueueStatus));
     }
     else
     {
         return(USBXpress32.SI_CheckRXQueue(cyHandle, ref lpdwNumBytesInQueue, ref lpdwQueueStatus));
     }
 }
Exemplo n.º 5
0
 public static extern USBXpress.ReturnCodes SI_CheckRXQueue(UInt32 cyHandle, ref UInt32 lpdwNumBytesInQueue, ref USBXpress.RXQueueStatus lpdwQueueStatus);
Exemplo n.º 6
0
        public byte[] Read(int cmd, byte id, int offset, int len)
        {
            if (this.IsOpen())
            {
                byte[]    buff        = new byte[len];
                byte[]    buffer      = new byte[64];
                const int max_payload = 64; // 64 (long paquete)
                uint      numbytes    = 0;

                int nbytes = 0;
                USBXpress.ReturnCodes ret = USBXpress.ReturnCodes.SI_SUCCESS;

                ClearInputBuffer(handle);

                for (int j = 0; j < buff.Length; j += max_payload)
                {
                    buffer[0] = (byte)'A';
                    buffer[1] = (byte)'T';
                    buffer[2] = (byte)'C';
                    buffer[3] = (byte)cmd;
                    buffer[4] = (byte)id;
                    buffer[5] = (byte)j;
                    if (len - j > max_payload)
                    {
                        buffer[6] = (byte)max_payload;
                    }
                    else
                    {
                        buffer[6] = (byte)(len - j);
                    }
                    for (int i = 7; i < 64; i++)
                    {
                        buffer[i] = 0;
                    }
                    usbXpress.SI_Write(handle, buffer, OLEN, ref nbytes, 0);

                    USBXpress.RXQueueStatus queueStatus = USBXpress.RXQueueStatus.SI_RX_EMPTY;

                    numbytes = 0;
                    for (int i = 0; i < 100 && numbytes < ILEN; i++)
                    {
                        usbXpress.SI_CheckRXQueue(handle, ref numbytes, ref queueStatus);
                        Thread.Sleep(10);
                    }
                    if (numbytes >= ILEN)
                    {
                        ret = usbXpress.SI_Read(handle, buffer, 64, ref nbytes, 0);
                        for (int i = 0; i < 64 && i + j < len; i++)
                        {
                            buff[j + i] = buffer[i];
                        }
                    }
                }
                if (ret != USBXpress.ReturnCodes.SI_SUCCESS)
                {
                    isOpen = false;
                }

                return(buff);
            }
            else
            {
                return(null);
            }
        }