Click here to Skip to main content
15,886,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir/Madam


i am using sdk of acr38 and using the class ModWinsCard.cs to write and read data but when i read data after writing it show only 'n'

additional information copied from comment below
C#
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
Posted
Updated 17-Jan-14 21:49pm
v3
Comments
AmitGajjar 18-Jan-14 3:27am    
Can you post your written code ?
rajbir singh thind 18-Jan-14 3:30am    
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
Nelek 18-Jan-14 3:42am    
You code is incomplete (and in my opinion it might be too much). Please try to reduce the code to the section where the problem is happening. If more code needed, people will ask for it.
You can read: best way to post code snippets[^]
rajbir singh thind 18-Jan-14 5:50am    
sorry sir i was confuse because i spent a lot time on it bt still i cant read and write data on it
vijayashankar20 18-Jun-18 1:35am    
help me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900