private void btnWrite_Click(object sender, System.EventArgs e) { // Validate input template if (txtData.Text == "") { txtData.Focus(); } //Check User File selected by user if (RBAA11.Checked == true) { HiAddr = 0xAA; LoAddr = 0x11; dataLen = 0x0A; //ChkStr = "91 00"; } if (RBBB22.Checked == true) { HiAddr = 0xBB; LoAddr = 0x22; dataLen = 0x10; //ChkStr = "91 01"; } if (RBCC33.Checked == true) { HiAddr = 0xCC; LoAddr = 0x33; dataLen = 0x20; //ChkStr = "91 02"; } // Select User File SelectFile(HiAddr, LoAddr); if (retcode != ModWinsCard.SCARD_S_SUCCESS) { return; } tmpStr = ""; tmpStr = txtData.Text; //Clear the data first for (indx = 0; indx < tmpArray.Length; indx++) tmpArray[indx] = 0x00; writeRecord(0x01, 0x00, (byte)tmpArray.Length, (byte)tmpArray.Length, ref tmpArray); //Now write the data to the card for(indx=0; indx < tmpStr.Length; indx++) tmpArray[indx] = (byte)Asc(tmpStr.Substring(indx,1)); writeRecord(0x01, 0x00, dataLen, dataLen, ref tmpArray); if (retcode != ModWinsCard.SCARD_S_SUCCESS) { return; } lstOutput.Items.Add("Data read from Text Box is written to card."); lstOutput.SelectedIndex = lstOutput.Items.Count - 1; } int Asc(string character) { if (character.Length == 1) { System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); int intAsciiCode = (int)asciiEncoding.GetBytes(character)[0]; return (intAsciiCode); } else { throw new Exception("Character is not valid."); } } private void writeRecord(int caseType, byte RecNo, byte maxLen, byte DataLen, ref byte[] ApduIn) { if (caseType == 1) // If card data is to be erased before writing new data. Re-initialize card values to $00 { apdu.bCLA = 0x80; // CLA apdu.bINS = 0xD2; // INS apdu.bP1 = RecNo; // Record No apdu.bP2 = 0x00; // P2 apdu.bP3 = maxLen; // Length of Data apdu.IsSend = true; for(i=0; i< maxLen; i++) apdu.Data[i] = ApduIn[i]; PerformTransmitAPDU(ref apdu); } //Write data to card apdu.bCLA = 0x80; // CLA apdu.bINS = 0xD2; // INS apdu.bP1 = RecNo; // Record No apdu.bP2 = 0x00; // P2 apdu.bP3 = DataLen; // Length of Data apdu.IsSend = true; for(i=0; i< maxLen; i++) apdu.Data[i] = ApduIn[i]; lstOutput.Items.Add("Write to FF 02"); PerformTransmitAPDU(ref apdu); } private void RBAA11_Click(object sender, System.EventArgs e) { txtData.Text = ""; txtData.MaxLength = 10; } private void RBBB22_Click(object sender, System.EventArgs e) { txtData.Text = ""; txtData.MaxLength = 16; } private void RBCC33_Click(object sender, System.EventArgs e) { txtData.Text = ""; txtData.MaxLength = 32; } private void btnRead_Click(object sender, System.EventArgs e) { int indx; string ChkStr; // Check User File selected by user if (RBAA11.Checked == true) { HiAddr = 0xAA; LoAddr = 0x11; dataLen = 0x0A; //ChkStr = "91 00"; } if (RBBB22.Checked == true) { HiAddr = 0xBB; LoAddr = 0x22; dataLen = 0x10; //ChkStr = "91 01"; } if (RBCC33.Checked == true) { HiAddr = 0xCC; LoAddr = 0x33; dataLen = 0x20; //ChkStr = "91 02"; } // Select User File SelectFile(HiAddr, LoAddr); if (retcode != ModWinsCard.SCARD_S_SUCCESS) { return; } // Read First Record of User File selected readRecord(0x00, dataLen); if (retcode != ModWinsCard.SCARD_S_SUCCESS) { return; } // Display data read from card to textbox tmpStr = ""; indx = 0; while (RecvBuff[indx] != 0x00) { if (indx < txtData.M
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)