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)); }
public void DisplayResponsePacket(ushort p_nCode) { checkOK = false; goToAdd = false; saveID = ""; int w_nRet; ushort w_nData = 0; ushort w_nData2 = 0; ushort w_nRcvCks = 0; ushort w_nSize = 0; //ClearResponseInfo(); if (CommandProc.GET_PACKET_PREFIX(false) == CommonDefine.RCM_PREFIX_CODE) { w_nRcvCks = (ushort)((CommandProc.m_pPacketBuffer[CommonDefine.ST_COM_PACKET_LEN + 1] << 8) + CommandProc.m_pPacketBuffer[CommonDefine.ST_COM_PACKET_LEN]); } else if (CommandProc.GET_PACKET_PREFIX(false) == CommonDefine.RCM_DATA_PREFIX_CODE) { w_nRcvCks = (ushort)((CommandProc.m_pPacketBuffer[CommandProc.GET_DATAPACKET_LEN(false) + 1] << 8) + CommandProc.m_pPacketBuffer[CommandProc.GET_DATAPACKET_LEN(false)]); } w_nRet = (int)CommandProc.GET_PACKET_RETURN(false); w_nData = CommandProc.GET_PACKET_RCMDATA(0, false); // MAKEWORD(g_Packet[8], g_Packet[9]); w_nData2 = CommandProc.GET_PACKET_RCMDATA(2, false); //MAKEWORD(g_Packet[10], g_Packet[11]); w_nSize = CommandProc.GET_PACKET_LEN(false); string strMsg = ""; switch (p_nCode) { case CommonDefine.CMD_CLEAR_TEMPLATE_CODE: //指定删除 if (w_nRet == CommonDefine.ERR_SUCCESS) { //strMsg = string.Format("结果 : 成功\r\n指纹编号 : {0}", w_nData); } else { // strMsg = string.Format("结果 : 错误\r\n{0}", GetErrorMsg(w_nData)); } break; case CommonDefine.CMD_WRITE_TEMPLATE_CODE: //指定录入 if (w_nRet == CommonDefine.ERR_SUCCESS) { strMsg = string.Format("结果 : 成功\r\n指纹编号 : {0}", w_nData); } else { strMsg = string.Format("结果 : 错误\r\n{0}", GetErrorMsg(w_nData)); if (w_nData == CommonDefine.ERR_DUPLICATION_ID) { strMsg += string.Format(" {0}.", w_nData2); } } break; case CommonDefine.CMD_GET_EMPTY_ID_CODE: //获取最小ID if (w_nRet == CommonDefine.ERR_SUCCESS) { strMsg = string.Format("结果 : 成功\r\n可以编号 : {0}", w_nData); strID = w_nData.ToString(); } else { strMsg = string.Format("结果 : 错误\r\n{0}", GetErrorMsg(w_nData)); strID = ""; } break; case CommonDefine.CMD_GET_ENROLL_COUNT_CODE: //已经注册个数 if (w_nRet == CommonDefine.ERR_SUCCESS) { strMsg = string.Format("结果 : 成功\r\n指纹数量 : {0}", w_nData); } else { strMsg = string.Format("结果 : 错误\r\n{0}", GetErrorMsg(w_nData)); } break; case CommonDefine.CMD_VERIFY_WITH_DOWN_TMPL_CODE: case CommonDefine.CMD_IDENTIFY_WITH_DOWN_TMPL_CODE: case CommonDefine.CMD_VERIFY_CODE: case CommonDefine.CMD_IDENTIFY_CODE: case CommonDefine.CMD_IDENTIFY_FREE_CODE: case CommonDefine.CMD_ENROLL_CODE: case CommonDefine.CMD_ENROLL_ONETIME_CODE: case CommonDefine.CMD_CHANGE_TEMPLATE_CODE: case CommonDefine.CMD_IDENTIFY_WITH_IMAGE_CODE: case CommonDefine.CMD_VERIFY_WITH_IMAGE_CODE: if (w_nRet == CommonDefine.ERR_SUCCESS) { switch (w_nData) { case CommonDefine.GD_NEED_RELEASE_FINGER: strMsg = "请离开手指"; break; case CommonDefine.GD_NEED_FIRST_SWEEP: strMsg = "请按手指"; break; case CommonDefine.GD_NEED_SECOND_SWEEP: strMsg = "请再按一次"; break; case CommonDefine.GD_NEED_THIRD_SWEEP: strMsg = "请再按一次"; break; case CommonDefine.CMD_CLEAR_TEMPLATE_CODE: strMsg = "请按手指"; break; default: strMsg = string.Format("结果 : 成功\r\n指纹编号 : {0}", w_nData); strID = ""; checkOK = p_nCode == CommonDefine.CMD_IDENTIFY_FREE_CODE; loginID = p_nCode == CommonDefine.CMD_IDENTIFY_FREE_CODE ? w_nData.ToString() : ""; saveID = p_nCode == CommonDefine.CMD_ENROLL_ONETIME_CODE ? w_nData.ToString() : ""; break; } } else { strMsg = string.Format("结果 : 错误\r\n{0}", GetErrorMsg(w_nData)); if (CommandProc.LOBYTE(w_nData) == CommonDefine.ERR_BAD_QUALITY) { strMsg += "\r\nAgain... !"; } else { goToAdd = p_nCode == CommonDefine.CMD_IDENTIFY_FREE_CODE; if (w_nData == CommonDefine.ERR_DUPLICATION_ID) { strMsg += string.Format(" {0}.", w_nData2); } } } break; case CommonDefine.CMD_FINGER_DETECT_CODE: if (w_nRet == CommonDefine.ERR_SUCCESS) { if (w_nData == CommonDefine.GD_DETECT_FINGER) { strMsg = string.Format("检测到指纹"); } else if (w_nData == CommonDefine.GD_NO_DETECT_FINGER) { strMsg = string.Format("没有检测到指纹"); } else { strMsg = string.Format("通讯错误."); } } else { strMsg = string.Format("结果 : 错误\r\n{0}", GetErrorMsg(w_nData)); } break; case CommonDefine.CMD_FP_CANCEL_CODE: /* if (w_nRet == CommonDefine.ERR_SUCCESS) * strMsg = string.Format("结果 : 取消命令成功"); * else * strMsg = string.Format("结果 : 错误\r\n{0}", GetErrorMsg(w_nData)); */ break; default: break; } edtRC_Result.Text = strMsg; if ((p_nCode == CommonDefine.CMD_IDENTIFY_FREE_CODE)) { if (w_nRet == CommonDefine.ERR_SUCCESS || CommandProc.LOBYTE(w_nData) != CommonDefine.ERR_NOT_AUTHORIZED && CommandProc.LOBYTE(w_nData) != CommonDefine.ERR_FP_CANCEL && CommandProc.LOBYTE(w_nData) != CommonDefine.ERR_INVALID_OPERATION_MODE && CommandProc.LOBYTE(w_nData) != CommonDefine.ERR_ALL_TMPL_EMPTY) { Array.Clear(CommandProc.m_pPacketBuffer, 0, CommonDefine.MAX_DATA_LEN + 10); if (checkOK) { Array.Clear(CommandProc.m_pPacketBuffer, 0, CommonDefine.MAX_DATA_LEN + 10); m_clsCmdProc.m_bCmdDone = true; Login(loginID); return; } if (goToAdd) { if (MessageBox.Show("当前指纹未识别到身份证信息,是否手动登录?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK) { Array.Clear(CommandProc.m_pPacketBuffer, 0, CommonDefine.MAX_DATA_LEN + 10); m_clsCmdProc.m_bCmdDone = true; AddLogin(); } } m_clsCmdProc.StartSendThread(); return; } if (goToAdd) { if (MessageBox.Show("当前指纹未识别到身份证信息,是否手动登录?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK) { Array.Clear(CommandProc.m_pPacketBuffer, 0, CommonDefine.MAX_DATA_LEN + 10); m_clsCmdProc.m_bCmdDone = true; AddLogin(); } } } if ((p_nCode == CommonDefine.CMD_ENROLL_CODE) || (p_nCode == CommonDefine.CMD_CHANGE_TEMPLATE_CODE)) { switch (w_nData) { case CommonDefine.GD_NEED_RELEASE_FINGER: case CommonDefine.GD_NEED_FIRST_SWEEP: case CommonDefine.GD_NEED_SECOND_SWEEP: case CommonDefine.GD_NEED_THIRD_SWEEP: case CommonDefine.ERR_BAD_QUALITY: Array.Clear(CommandProc.m_pPacketBuffer, 0, CommonDefine.MAX_DATA_LEN + 10); m_clsCmdProc.StartSendThread(); return; default: break; } } if ((p_nCode == CommonDefine.CMD_ENROLL_ONETIME_CODE) || (p_nCode == CommonDefine.CMD_VERIFY_CODE) || (p_nCode == CommonDefine.CMD_IDENTIFY_CODE) || (p_nCode == CommonDefine.CMD_IDENTIFY_FREE_CODE)) { switch (w_nData) { case CommonDefine.GD_NEED_RELEASE_FINGER: Array.Clear(CommandProc.m_pPacketBuffer, 0, CommonDefine.MAX_DATA_LEN + 10); m_clsCmdProc.StartSendThread(); return; default: break; } } Array.Clear(CommandProc.m_pPacketBuffer, 0, CommonDefine.MAX_DATA_LEN + 10); m_clsCmdProc.m_bCmdDone = true; if (!string.IsNullOrEmpty(saveID)) { SaveID(saveID); } if (p_nCode == CommonDefine.CMD_CLEAR_TEMPLATE_CODE) { if (MessageBox.Show("当前指纹未识别到身份证信息,是否手动登录?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK) { Array.Clear(CommandProc.m_pPacketBuffer, 0, CommonDefine.MAX_DATA_LEN + 10); m_clsCmdProc.m_bCmdDone = true; AddLogin(); return; } Run_IdentifyFree(); } }