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

📄 contactlessdemovcdlg.cpp

📁 RFID Omnikey Reader Application source
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// ContactlessDemoVCDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ContactlessDemoVC.h"
#include "ContactlessDemoVCDlg.h"

#ifdef _DEBUG
   #define new DEBUG_NEW
   #undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define Card_Absent  0x00
#define Card_Present 0x01
#define Card_Changed 0x02
/*****************************************************************************/
/*           ISO standard CS(CCCC****)
******************************************************************************/
#define ISO14443A_123	      0x01
#define ISO14443A_1234		   0x02
#define ISO15693_12ICL			0x03
#define ISO15693_123 			0x04
#define ISO14443B_12STM 		0x05
#define ISO14443B_123   		0x06
#define ISO14443B_1234 			0x07
#define ISO15693_12ICODE1  	0x08
#define ISO15693_12ICODEEPC  	0x09


/*****************************************************************************/
/*           Chip Type CS(****SSSS)
******************************************************************************/
#define UNKNOWN_CHIP				0x00
//ISO 14443A_123
#define MIFARE_ST1K				0x10
#define MIFARE_ST4K				0x20
#define MIFARE_ULIT				0x30
#define SLE55R_XXXX				0x70	

//ISO14443A_1234
#define MIFARE_DESF				0x40
#define MIFARE_PRX				0x50
#define SLE66C_320P				0x60	

//ISO14443B_123
#define AT88RF020				0x10
#define AT88SC6416CRF			0x20
//ISO14443B_12
#define SR176					0xE0
#define SRIX4K					0xF0

//ISO15693_123
#define SRF55V10P				0x10
#define SRF55V02P				0x20
#define SRF55V10S				0x30
#define SRF55V02S				0x40
#define TAG_IT					0x90
#define LRI512					0xA0
#define ICODESLI				0xB0
#define SRF55XXX				0xC0
#define TEMPSENS				0xD0


//ISO15693_12ICL
#define INSIDECL_XXXX			0x80	


//ICODE1 Card
#define ICODE1CARD				0x10



/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
   {
public:
   CAboutDlg();

// Dialog Data
   //{{AFX_DATA(CAboutDlg)
   enum
      {
      IDD = IDD_ABOUTBOX
      };
   //}}AFX_DATA

   // ClassWizard generated virtual function overrides
   //{{AFX_VIRTUAL(CAboutDlg)
protected:
   virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
   //}}AFX_VIRTUAL

// Implementation
protected:
   //{{AFX_MSG(CAboutDlg)
   //}}AFX_MSG
   DECLARE_MESSAGE_MAP()
   };

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
   {
   //{{AFX_DATA_INIT(CAboutDlg)
   //}}AFX_DATA_INIT
   }

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
   {
   CDialog::DoDataExchange(pDX);
   //{{AFX_DATA_MAP(CAboutDlg)
   //}}AFX_DATA_MAP
   }

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CContactlessDemoVCDlg dialog

CContactlessDemoVCDlg::CContactlessDemoVCDlg(CWnd* pParent /*=NULL*/)
: CDialog(CContactlessDemoVCDlg::IDD, pParent)
   {
   //{{AFX_DATA_INIT(CContactlessDemoVCDlg)
   m_strReaderName = _T("");
   m_strMifKeyToReader = _T("");
   m_longBlockNr = 0;
   m_strAuthentKey = _T("");
   m_intAuthentMode = -1;
   m_intAuthentKeyOption = -1;
   m_intAccessOption = -1;
   m_strKeyNrToReader = _T("");
   m_strMifAuthentKeyNr = _T("");
   m_strDataRead = _T("");
   m_strDataToWrite = _T("");
   m_strIncrementValue = _T("");
   m_strDecrementValue = _T("");
   m_strOutPutList = _T("");
   m_intMifTrOption = -1;
   m_strMifTrKeyNr = _T("");
   m_strTrKeyNoToReader = _T("");
   m_intTrKeyOptionS = -1;
   m_strTrTrKeyNo = _T("");
   m_strTrKeyToReader = _T("");
   m_dwNByteSend = 0;
   m_strByteSend = _T("");
   m_strByteReceive = _T("");
   m_dwNByteReceive = 0;
   m_nWriteByte = 0;
   //}}AFX_DATA_INIT
   // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
   m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
   }

void CContactlessDemoVCDlg::DoDataExchange(CDataExchange* pDX)
   {
   CDialog::DoDataExchange(pDX);
   //{{AFX_DATA_MAP(CContactlessDemoVCDlg)
   DDX_Control(pDX, IDC_LEDERROR, m_ledError);
   DDX_Control(pDX, IDC_LEDSUCCESS, m_ledSuccess);
   DDX_Control(pDX, IDC_ATRLIST, m_ctrAtrList);
   DDX_Control(pDX, IDC_CARDNAMELIST, m_ctrCardNameList);
   DDX_Control(pDX, IDC_UIDLIST, m_ctrUidList);
   DDX_Control(pDX, IDC_LISTOUTPUT, m_ctrOutput);
   DDX_Control(pDX, IDC_LISTREADER, m_ctrReaderName);
   DDX_LBString(pDX, IDC_LISTREADER, m_strReaderName);
   DDX_Text(pDX, IDC_MIFKEYTOREADER, m_strMifKeyToReader);
   DDV_MaxChars(pDX, m_strMifKeyToReader, 16);
   DDX_Text(pDX, IDC_AUTHENTBLOCKNR, m_longBlockNr);
   DDV_MinMaxLong(pDX, m_longBlockNr, 0, 255);
   DDX_Text(pDX, IDC_AUTHENTKEY, m_strAuthentKey);
   DDV_MaxChars(pDX, m_strAuthentKey, 12);
   DDX_Radio(pDX, IDC_MODEA, m_intAuthentMode);
   DDX_Radio(pDX, IDC_ACCESSOPTIONKEYNR, m_intAccessOption);
   DDX_CBString(pDX, IDC_KEYNRTOREADER, m_strKeyNrToReader);
   DDX_CBString(pDX, IDC_MIFAUTHENTKEYNR, m_strMifAuthentKeyNr);
   DDX_Text(pDX, IDC_DATAREAD, m_strDataRead);
   DDX_Text(pDX, IDC_DATATOWRITE, m_strDataToWrite);
   DDV_MaxChars(pDX, m_strDataToWrite, 32);
   DDX_Text(pDX, IDC_INCREMENTVAL, m_strIncrementValue);
   DDV_MaxChars(pDX, m_strIncrementValue, 8);
   DDX_Text(pDX, IDC_DECREMENTVAL, m_strDecrementValue);
   DDV_MaxChars(pDX, m_strDecrementValue, 8);
   DDX_LBString(pDX, IDC_LISTOUTPUT, m_strOutPutList);
   DDX_Radio(pDX, IDC_MIFKEYOPTIONS, m_intMifTrOption);
   DDX_CBString(pDX, IDC_MIFTRKEYNR, m_strMifTrKeyNr);
   DDX_CBString(pDX, IDC_TRKEYNRTOREADER, m_strTrKeyNoToReader);
   DDX_Radio(pDX, IDC_TRKEYOPTIONS, m_intTrKeyOptionS);
   DDX_CBString(pDX, IDC_TRTRKEYNR, m_strTrTrKeyNo);
   DDX_Text(pDX, IDC_TRKEYTOREADER, m_strTrKeyToReader);
   DDV_MaxChars(pDX, m_strTrKeyToReader, 32);
   DDX_Text(pDX, IDC_NBYTESEND, m_dwNByteSend);
   DDV_MinMaxDWord(pDX, m_dwNByteSend, 0, 253);
   DDX_Text(pDX, IDC_BYTESEND, m_strByteSend);
   DDX_Text(pDX, IDC_BYTERECEIVED, m_strByteReceive);
   DDX_Text(pDX, IDC_NBYTERECEIVED, m_dwNByteReceive);
   DDX_Text(pDX, IDC_WRITEBYTE, m_nWriteByte);
   //}}AFX_DATA_MAP
   }

BEGIN_MESSAGE_MAP(CContactlessDemoVCDlg, CDialog)
//{{AFX_MSG_MAP(CContactlessDemoVCDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_WRITEMIFKEY, OnWritemifkey)
ON_LBN_SELCHANGE(IDC_LISTREADER, OnSelchangeListreader)
ON_BN_CLICKED(IDC_REFOUTPUTSC, OnRefoutputsc)
ON_BN_CLICKED(IDC_MIFAUTHENT, OnMifauthent)
ON_BN_CLICKED(IDC_READ, OnRead)
ON_BN_CLICKED(IDC_WRITE, OnWrite)
ON_BN_CLICKED(IDC_INCREMENT, OnIncrement)
ON_BN_CLICKED(IDC_DECREMENT, OnDecrement)
ON_BN_CLICKED(IDOK, OnExit)
ON_BN_CLICKED(IDC_ACCESSOPTIONKEYNR, OnAccessoptionkeynr)
ON_BN_CLICKED(IDC_ACCESSOPTIONKEY, OnAccessoptionkey)
ON_BN_CLICKED(IDC_MIFKEYOPTIONS, OnMifkeyoptions)
ON_BN_CLICKED(IDC_MIFKEYOPTIONP, OnMifkeyoptionp)
ON_BN_CLICKED(IDC_WRITETRKEYTOREADER, OnWritetrkeytoreader)
ON_BN_CLICKED(IDC_TRKEYOPTIONS, OnTrkeyoptions)
ON_BN_CLICKED(IDC_TRKEYOPTIONP, OnTrkeyoptionp)
ON_BN_CLICKED(IDC_TRANSMIT, OnTransmit)
ON_EN_CHANGE(IDC_BYTESEND, OnChangeBytesend)
ON_EN_CHANGE(IDC_DATATOWRITE, OnChangeDatatowrite)
	ON_EN_CHANGE(IDC_TRKEYTOREADER, OnChangeTrkeytoreader)
	ON_EN_CHANGE(IDC_MIFKEYTOREADER, OnChangeMifkeytoreader)
	ON_EN_CHANGE(IDC_AUTHENTKEY, OnChangeAuthentkey)
	ON_EN_CHANGE(IDC_INCREMENTVAL, OnChangeIncrementval)
	ON_EN_CHANGE(IDC_DECREMENTVAL, OnChangeDecrementval)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CContactlessDemoVCDlg message handlers

BOOL CContactlessDemoVCDlg::OnInitDialog()
   {
   CDialog::OnInitDialog();
   // Add "About..." menu item to system menu.
   DWORD i = 0, z = 0, j =0;
   CHAR mszReaders [1024];
   DWORD dwLength = sizeof(mszReaders);
   CHAR  szReader [10] [100];
   hCard = 0x00000000;
   hContext = 0x00000000;
   fCM5121Selected = FALSE;
   char str[80] = "";
   ulUIDBufLen = 12;
   fCardConnected = FALSE;
   memset(ucATR,sizeof(ucATR),0);
   ulATRLen = sizeof(ucATR);
   m_strKeyNrToReader = "00";
   m_strTrKeyNoToReader ="00";
   // IDM_ABOUTBOX must be in the system command range.
   ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
   ASSERT(IDM_ABOUTBOX < 0xF000);

   CMenu* pSysMenu = GetSystemMenu(FALSE);
   if (pSysMenu != NULL)
      {
      CString strAboutMenu;
      strAboutMenu.LoadString(IDS_ABOUTBOX);
      if (!strAboutMenu.IsEmpty())
         {
         pSysMenu->AppendMenu(MF_SEPARATOR);
         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
         }
      }

   // Set the icon for this dialog.  The framework does this automatically
   //  when the application's main window is not a dialog
   SetIcon(m_hIcon, TRUE);       // Set big icon
   SetIcon(m_hIcon, FALSE);      // Set small icon

   // TODO: Add extra initialization here



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

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






   m_ctrOutput.AddString("CM5121 Demo Application, please see the help file of Synchronous API for detail functionality");


   SCard_Status = SCardEstablishContext(
                                       SCARD_SCOPE_USER,
                                       NULL,
                                       NULL,
                                       &hContext);



   if ( SCard_Status == SCARD_S_SUCCESS)
      {

      for (i=0;i<10;i++)
         {
         memset(&szReader[i][0],0x00,sizeof(&szReader[i][0]));
         }




      SCard_Status = SCardListReaders(hContext,
                                      NULL,
                                      mszReaders,
                                      &dwLength);


      if ( SCard_Status == SCARD_S_SUCCESS)
         {

         if (dwLength > 2) // \0\0
            {
            z=0;
            j=0;
            for (i=0;i<dwLength;i++)
               {
               if (mszReaders[i] == '\0')
                  {
                  szReader [j] [z] = mszReaders[i];
                  z=0;
                  j++;
                  }
               else
                  {
                  szReader [j] [z] = mszReaders[i];
                  z++;
                  }

               }
            }


         for (j=0;j < 10;j++)
            {
            if (szReader[j] [0] != 0x00)
               {
               m_ctrReaderName.AddString(szReader[j]);


               if (strcmp( szReader[j],"OMNIKEY CardMan 5121 0")==0)
                  {
                  m_strReaderName = "OMNIKEY CardMan 5121 0";
                  m_ctrOutput.AddString("Selected Reader is :");
                  m_ctrOutput.AddString(m_strReaderName);
                  fCM5121Selected = TRUE;
                  }
               }
            }


         }
      else
         {
         m_ctrOutput.AddString("Error in SCardListReaders, may be no reader available");
         TurnOnErrorLed();


         }

      }
   else
      {
      m_ctrOutput.AddString("Error in SCardEstablishContext");
      TurnOnErrorLed();
      }

   //If a card is present connect the card and show the ATR, UID, CardName
   //If not present start the thread to auto detection of the card

   UpdateData(FALSE);
   DisableAllFields();
   GetDlgItem(IDC_MIFTRKEYNR)->EnableWindow(FALSE);
   GetDlgItem(IDC_MIFAUTHENTKEYNR)->EnableWindow(FALSE);
   GetDlgItem(IDC_AUTHENTKEY)->EnableWindow(FALSE);
   GetDlgItem(IDC_TRTRKEYNR)->EnableWindow(FALSE);


   TrackCard();
   ShowCursorOutScreen();

   return TRUE;  // return TRUE  unless you set the focus to a control
   }

void CContactlessDemoVCDlg::OnSysCommand(UINT nID, LPARAM lParam)
   {
   if ((nID & 0xFFF0) == IDM_ABOUTBOX)
      {
      CAboutDlg dlgAbout;
      dlgAbout.DoModal();
      }
   else
      {
      CDialog::OnSysCommand(nID, lParam);
      }
   }

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CContactlessDemoVCDlg::OnPaint()
   {
   if (IsIconic())
      {
      CPaintDC dc(this); // device context for painting

      SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

      // Center icon in client rectangle
      int cxIcon = GetSystemMetrics(SM_CXICON);
      int cyIcon = GetSystemMetrics(SM_CYICON);

⌨️ 快捷键说明

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