⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contactlessdemovcdlg.cpp

📁 RFID Omnikey Reader Application source
💻 CPP
📖 第 1 页 / 共 5 页
字号:
   ulistopTime.LowPart=ftimetmp.dwLowDateTime;
   ulistopTime.HighPart=ftimetmp.dwHighDateTime;
   ulirunTime.QuadPart=ulistopTime.QuadPart-ulistartTime.QuadPart;
   ftimetmp.dwHighDateTime=ulirunTime.HighPart;
   ftimetmp.dwLowDateTime=ulirunTime.LowPart;
   FileTimeToSystemTime(&ftimetmp, &runTime);


   _itoa(runTime.wSecond,bytetochar,10);
   if (runTime.wSecond<=9)strncat(strFortime,"0",19);
   strncat(strFortime,bytetochar,19);
   strncat(strFortime,":",19);

   _itoa((runTime.wMilliseconds/10),bytetochar,10);
   if ((runTime.wMilliseconds/10)<=9)strncat(strFortime,"0",19);
   strncat(strFortime,bytetochar,19);

   _itoa((runTime.wMilliseconds - (runTime.wMilliseconds/10)*10) ,bytetochar,10);
   strncat(strFortime,bytetochar,19);

   m_ctrOutput.AddString("Currently executed operation took :  " +  CString(strFortime) + " Sec");

   startTime.wMilliseconds = 0;
   startTime.wSecond = 0;
   stopTime.wMilliseconds = 0;
   stopTime.wSecond = 0;
   runTime.wMilliseconds = 0;
   runTime.wSecond = 0;

   iMode = CLed::LED_DISABLED;
   iColor = CLed::LED_COLOR_RED;
   m_ledError.SetLed(iColor,iMode,CLed::LED_SQUARE);

   iMode = CLed::LED_ON;
   iColor = CLed::LED_COLOR_GREEN;
   m_ledSuccess.SetLed(iColor,iMode,CLed::LED_SQUARE);


   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void CContactlessDemoVCDlg::DisableAllFields()
   {

   GetDlgItem(IDC_MIFAUTHENT)->EnableWindow(FALSE);
   GetDlgItem(IDC_AUTHENTBLOCKNR)->EnableWindow(FALSE);
   GetDlgItem(IDC_ACCESSOPTIONKEYNR)->EnableWindow(FALSE);
   GetDlgItem(IDC_MIFAUTHENTKEYNR)->EnableWindow(FALSE);
   GetDlgItem(IDC_ACCESSOPTIONKEY)->EnableWindow(FALSE);
   GetDlgItem(IDC_AUTHENTKEY)->EnableWindow(FALSE);
   GetDlgItem(IDC_MODEA)->EnableWindow(FALSE);
   GetDlgItem(IDC_MODEB)->EnableWindow(FALSE);
   GetDlgItem(IDC_READ)->EnableWindow(FALSE);
   GetDlgItem(IDC_DATAREAD)->EnableWindow(FALSE);
   GetDlgItem(IDC_WRITE)->EnableWindow(FALSE);
   GetDlgItem(IDC_DATATOWRITE)->EnableWindow(FALSE);
   GetDlgItem(IDC_INCREMENT)->EnableWindow(FALSE);
   GetDlgItem(IDC_INCREMENTVAL)->EnableWindow(FALSE);
   GetDlgItem(IDC_DECREMENT)->EnableWindow(FALSE);
   GetDlgItem(IDC_DECREMENTVAL)->EnableWindow(FALSE);
   GetDlgItem(IDC_TRANSMIT)->EnableWindow(FALSE);
   GetDlgItem(IDC_BYTESEND)->EnableWindow(FALSE);
   GetDlgItem(IDC_NBYTESEND)->EnableWindow(FALSE);
   GetDlgItem(IDC_NBYTERECEIVED)->EnableWindow(FALSE);

   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void CContactlessDemoVCDlg::EnableAllFields()
   {

   GetDlgItem(IDC_MIFAUTHENT)->EnableWindow(TRUE);
   GetDlgItem(IDC_AUTHENTBLOCKNR)->EnableWindow(TRUE);
   GetDlgItem(IDC_ACCESSOPTIONKEYNR)->EnableWindow(TRUE);
   GetDlgItem(IDC_ACCESSOPTIONKEY)->EnableWindow(TRUE);
   // GetDlgItem(IDC_MIFAUTHENTKEYNR)->EnableWindow(TRUE);
   // GetDlgItem(IDC_AUTHENTKEY)->EnableWindow(TRUE);
   GetDlgItem(IDC_MODEA)->EnableWindow(TRUE);
   GetDlgItem(IDC_MODEB)->EnableWindow(TRUE);
   GetDlgItem(IDC_READ)->EnableWindow(TRUE);
   GetDlgItem(IDC_DATAREAD)->EnableWindow(TRUE);
   GetDlgItem(IDC_WRITE)->EnableWindow(TRUE);
   GetDlgItem(IDC_DATATOWRITE)->EnableWindow(TRUE);
   GetDlgItem(IDC_INCREMENT)->EnableWindow(TRUE);
   GetDlgItem(IDC_INCREMENTVAL)->EnableWindow(TRUE);
   GetDlgItem(IDC_DECREMENT)->EnableWindow(TRUE);
   GetDlgItem(IDC_DECREMENTVAL)->EnableWindow(TRUE);


   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void CContactlessDemoVCDlg::OnExit()
   {

   fCM5121Selected = FALSE;
   SCardDisconnect(hCard,SCARD_LEAVE_CARD );
   SCardReleaseContext(hContext);
   exit(0);
   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void CContactlessDemoVCDlg::ShowCursorOutScreen()
   {

   int iCount = m_ctrOutput. GetCount( );
   for (int iUnsel = 0; iUnsel<iCount - 1;iUnsel++)
      m_ctrOutput.SetSel(iUnsel,  FALSE );
   m_ctrOutput.SetSel(iCount - 1,  TRUE );

   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void CContactlessDemoVCDlg::TurnOnErrorLed()
   {

   iMode = CLed::LED_ON;
   iColor = CLed::LED_COLOR_RED;
   m_ledError.SetLed(iColor,iMode,CLed::LED_SQUARE);

   iMode = CLed::LED_DISABLED;
   iColor = CLed::LED_COLOR_RED;
   m_ledSuccess.SetLed(iColor,iMode,CLed::LED_SQUARE);


   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void CContactlessDemoVCDlg::OnAccessoptionkeynr()
   {
   m_strMifAuthentKeyNr ="00";
   m_intAccessOption = 0 ;
   GetDlgItem(IDC_MIFAUTHENTKEYNR)->EnableWindow(TRUE);
   GetDlgItem(IDC_AUTHENTKEY)->EnableWindow(FALSE);
   UpdateData(FALSE);

   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void CContactlessDemoVCDlg::OnAccessoptionkey()
   {
   m_strMifAuthentKeyNr ="";
   m_intAccessOption = 1 ;
   GetDlgItem(IDC_MIFAUTHENTKEYNR)->EnableWindow(FALSE);
   GetDlgItem(IDC_AUTHENTKEY)->EnableWindow(TRUE);
   UpdateData(FALSE);

   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void CContactlessDemoVCDlg::OnMifkeyoptions()
   {
   GetDlgItem(IDC_MIFTRKEYNR)->EnableWindow(TRUE);
   m_strMifTrKeyNr = "00";
   m_intMifTrOption = 0;
   UpdateData(FALSE);

   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void CContactlessDemoVCDlg::OnMifkeyoptionp()
   {
   GetDlgItem(IDC_MIFTRKEYNR)->EnableWindow(FALSE);
   m_intMifTrOption = 1;
   }

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CContactlessDemoVCDlg::OnWritetrkeytoreader()
   {


   UCHAR ucTransKey[16] = {0};
   ULONG ulTransKeyLen = 0;
   ULONG ulTransKeyNr = 0;
   ULONG ulTrTrKeyNr = 0;
   BOOLEAN fSecuredTransmission = FALSE;
   char Reader[80]=" ";
   UCHAR ucKeyNr[1]={0};
   ULONG ulTrKeyNrLen = 0;


   m_strTrKeyToReader.Empty();
   UpdateData(TRUE);

   CStringToUchar( m_strTrKeyToReader,ucTransKey,&ulTransKeyLen);
   if (ulTransKeyLen != 16)
      {

      m_ctrOutput.AddString("The Key must be of 16 bytes");
      TurnOnErrorLed();
      goto EXIT;


      }

   CStringToUchar( m_strTrKeyNoToReader,ucKeyNr,&ulTrKeyNrLen);
   ulTransKeyNr = ucKeyNr[0];

   if (m_intTrKeyOptionS == 0)
      {
      fSecuredTransmission = TRUE;
      CStringToUchar(m_strTrTrKeyNo,ucKeyNr,&ulTrKeyNrLen);
      ulTrTrKeyNr = ucKeyNr[0];
      }
   else if (m_intTrKeyOptionS == 1)
      {
      fSecuredTransmission = FALSE;

      }
   else
      {
      m_ctrOutput.AddString("One security option must be selected");
      TurnOnErrorLed();
      goto EXIT;
      }




   if (fCM5121Selected == TRUE)
      {

      strcpy(Reader,(LPCTSTR) m_strReaderName);

      if (fCardConnected != TRUE)hCard = 0x00000000;

      GetSystemTime(&startTime);

//      lErr = SCardCLWriteTransmissionKeyToReader(hCard,hContext,Reader,ulTransKeyNr,ulTransKeyLen,
//                                                 ucTransKey,fSecuredTransmission,ulTrTrKeyNr);

      GetSystemTime(&stopTime);

      if (lErr == NO_ERROR)
         {

         m_ctrOutput.AddString("The key has been written succesfully");
         ShowTimeRequired();

         }
      else
         {
         ShowErrorMessage(lErr);
         }
      }
   else
      {

      m_ctrOutput.AddString("For any operation one reader must be selected");
      TurnOnErrorLed();
      }



   EXIT:
   ShowCursorOutScreen();
   m_strMifKeyToReader.Empty();
   UpdateData(FALSE);



   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void CContactlessDemoVCDlg::OnTrkeyoptions()
   {
   GetDlgItem(IDC_TRTRKEYNR)->EnableWindow(TRUE);
   m_intTrKeyOptionS = 0;
   m_strTrTrKeyNo = "00";
   UpdateData(FALSE);

   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void CContactlessDemoVCDlg::OnTrkeyoptionp()
   {
   GetDlgItem(IDC_TRTRKEYNR)->EnableWindow(FALSE);
   m_intTrKeyOptionS = 1;
   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void CContactlessDemoVCDlg::OnTransmit()
   {
   UCHAR ucByteSend[260] = {0};
   UCHAR ucByteReceive[260] = {0};
   ULONG ulnByteSend = 0;
   DWORD dwRecvLength = 260;
   char str[1024] = "";
   SCARD_IO_REQUEST pioSendPci;


   if (dwActiveProtocols == SCARD_PROTOCOL_T0)
      {
      pioSendPci.dwProtocol= SCARD_PCI_T0->dwProtocol;
      pioSendPci.cbPciLength= SCARD_PCI_T0->cbPciLength;
      }
   else
      if (dwActiveProtocols == SCARD_PROTOCOL_T1)
      {
      pioSendPci.dwProtocol= SCARD_PCI_T1->dwProtocol;
      pioSendPci.cbPciLength= SCARD_PCI_T1->cbPciLength;

      }


   UpdateData(TRUE);


   CStringToUchar(m_strByteSend,ucByteSend,&ulnByteSend);

   if (ulnByteSend != m_dwNByteSend)
      {
      MessageBox(" Problem in length of Data send and number of bytes send");
      TurnOnErrorLed();
      goto EXIT;
      }

   GetSystemTime(&startTime);


   if(m_strCardName.Find("iClass") != -1)
   {
   
    SCard_Status = SCardCLICCTransmit(hCard,ucByteSend,m_dwNByteSend,ucByteReceive,&dwRecvLength);

   
   }
   else
   {

   SCard_Status = SCardTransmit (hCard,
                                 &pioSendPci,
                                 ucByteSend,
                                 m_dwNByteSend,
                                 NULL,
                                 ucByteReceive,
                                 &dwRecvLength);
   }

   GetSystemTime(&stopTime);

   if (SCard_Status == 0)
      {
      m_ctrOutput.AddString("Transmission has been done succesfully");
      m_dwNByteReceive = dwRecvLength;
      UcharToStr(ucByteReceive,dwRecvLength,str);
      m_strByteReceive = str;
      ShowTimeRequired();
      }
   else
      {
      ShowErrorMessage(SCard_Status);
      m_strByteReceive = "";
      TurnOnErrorLed();
      }


   UpdateData(FALSE);
   EXIT:
   ;
   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void CContactlessDemoVCDlg::OnChangeBytesend()
   {
   UpdateData(TRUE);
      if (CheckLetter(m_strByteSend)!= TRUE)
      {
      m_strByteSend.Remove(m_strByteSend.GetAt(m_strByteSend.GetLength()-1));
      }

   m_dwNByteSend = m_strByteSend.GetLength()/2;

   UpdateData(FALSE);

   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void CContactlessDemoVCDlg::OnChangeDatatowrite()
   {
   UpdateData(TRUE);
         if (CheckLetter(m_strDataToWrite)!= TRUE)
      {
      m_strDataToWrite.Remove(m_strDataToWrite.GetAt(m_strDataToWrite.GetLength()-1));
      }

   m_nWriteByte = m_strDataToWrite.GetLength()/2;
   UpdateData(FALSE);

   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOLEAN CContactlessDemoVCDlg::CheckLetter(CString String)
   {
   int i = 0;
   int k = 0;
   for (i = 0;i<String.GetLength();i++)
      {
      if ((String.GetAt(i) >= '0' && String.GetAt(i) <= '9') ||(String.GetAt(i) >= 'A' && String.GetAt(i) <= 'F'))
         k = 0;
      else
         {

         MessageBox("The values must be a hex value");
         return FALSE;
         }
      }
   return TRUE;
   }

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -