示例#1
0
        bool USB_ReceiveDataAck(ushort p_wCMD)
        {
            byte[] btCDB       = new byte[8];
            int[]  nLen        = new int[1];
            int    w_dwTimeOut = CommonDefine.COMM_TIMEOUT;

            byte[] w_WaitPacket = new byte[8];
            byte[] w_pTmpBuf;

            if (p_wCMD == CommonDefine.CMD_VERIFY_CODE ||
                p_wCMD == CommonDefine.CMD_IDENTIFY_CODE ||
                p_wCMD == CommonDefine.CMD_IDENTIFY_FREE_CODE ||
                p_wCMD == CommonDefine.CMD_ENROLL_CODE ||
                p_wCMD == CommonDefine.CMD_ENROLL_ONETIME_CODE)
            {
                w_dwTimeOut = (CommonDefine.GD_MAX_FP_TIME_OUT + 1) * (1000);
            }

            CommandProc.memset(w_WaitPacket, 0xAF, 0, 8);
            CommandProc.memset(btCDB, 0, 0, 8);

            do
            {
                btCDB[0] = 0xEF; btCDB[1] = 0x15;
                nLen[0]  = 6;
                if (!USBSCSIRead(btCDB, 8, CommandProc.m_pPacketBuffer, nLen, (uint)w_dwTimeOut))
                {
                    return(false);
                }
                Thread.Sleep(100);
                if (!CommandProc.DoEvents())
                {
                    return(false);
                }
            } while (CommandProc.memcmp(CommandProc.m_pPacketBuffer, w_WaitPacket, 6) == true);

            nLen[0]   = CommandProc.GET_PACKET_LEN(false) + 2;
            w_pTmpBuf = new byte[nLen[0] + 10];
            do
            {
                Array.Copy(CommandProc.m_pPacketBuffer, 6, w_pTmpBuf, 0, nLen[0]);
                if (!USB_ReceiveRawData(w_pTmpBuf, (uint)nLen[0]))
                {
                    return(false);
                }
                Array.Copy(w_pTmpBuf, 0, CommandProc.m_pPacketBuffer, 6, nLen[0]);
                Thread.Sleep(5);
                if (!CommandProc.DoEvents())
                {
                    return(false);
                }
            } while (CommandProc.memcmp(CommandProc.m_pPacketBuffer, w_WaitPacket, 4) == true);

            return(MainWindow.m_clsCmdProc.CheckReceive(CommonDefine.RCM_DATA_PREFIX_CODE, p_wCMD));
        }
示例#2
0
        public bool USB_ReceiveAck(ushort p_wCMD, bool p_bCmdData)
        {
            byte[] btCDB        = new byte[8];
            byte[] w_WaitPacket = new byte[24];
            int[]  nLen         = new int[1];
            int    w_dwTimeOut  = (int)SCSI_TIMEOUT;

            if (p_wCMD == CommonDefine.CMD_VERIFY_CODE ||
                p_wCMD == CommonDefine.CMD_IDENTIFY_CODE ||
                p_wCMD == CommonDefine.CMD_IDENTIFY_FREE_CODE ||
                p_wCMD == CommonDefine.CMD_ENROLL_CODE ||
                p_wCMD == CommonDefine.CMD_ENROLL_ONETIME_CODE)
            {
                w_dwTimeOut = (CommonDefine.GD_MAX_FP_TIME_OUT + 1) * (1000);
            }

            CommandProc.memset(w_WaitPacket, 0xAF, 0, CommonDefine.ST_COM_PACKET_LEN + 2);
            CommandProc.memset(btCDB, 0, 0, 8);

            do
            {
                CommandProc.memset(CommandProc.m_pPacketBuffer, 0, 0, CommonDefine.MAX_DATA_LEN + 10);
                btCDB[0] = 0xEF; btCDB[1] = 0x12;
                nLen[0]  = CommonDefine.ST_COM_PACKET_LEN + 2;
                if (!USBSCSIRead(btCDB, 8, CommandProc.m_pPacketBuffer, nLen, (uint)w_dwTimeOut))
                {
                    return(false);
                }
                Thread.Sleep(100);
                if (!CommandProc.DoEvents())
                {
                    return(false);
                }
            } while (CommandProc.memcmp(CommandProc.m_pPacketBuffer, w_WaitPacket, CommonDefine.ST_COM_PACKET_LEN + 2) == true);

            if (p_bCmdData)
            {
                return(MainWindow.m_clsCmdProc.CheckReceive(CommonDefine.RCM_PREFIX_CODE, p_wCMD));
            }
            else
            {
                return(MainWindow.m_clsCmdProc.CheckReceive(CommonDefine.RCM_DATA_PREFIX_CODE, p_wCMD));
            }
        }
示例#3
0
        public bool ReceiveData(byte[] p_pDataBuf, uint p_nDataLen, uint[] p_nReadLen, uint p_nTimeOut)
        {
            // Wait For ACK
            CommTimer w_tmrComm = new CommTimer();
            bool      w_bRet    = false;

            w_tmrComm.Start(p_nTimeOut);
            while ((m_comPort.BytesToRead < p_nDataLen) && (w_tmrComm.timedout == false))
            {
//                 System.Threading.Thread.Sleep(1);
                if (!CommandProc.DoEvents())
                {
                    return(false);
                }
            }

            // Receive
            if (m_comPort.BytesToRead > 0)
            {
                m_comPort.ReadTimeout = (int)p_nTimeOut;
                p_nReadLen[0]         = (uint)m_comPort.Read(p_pDataBuf, 0, (int)p_nDataLen);
                if (p_nReadLen[0] <= 0)
                {
                    w_bRet = false;
                }
                else
                {
                    w_bRet = true;
                }
            }
            else
            {
                w_bRet = false;
            }

            // Release
            w_tmrComm.tmrComm.Dispose();
//             m_comPort.DiscardInBuffer();
            m_comPort.DiscardOutBuffer();

            // Return
            return(w_bRet);
        }