Salve sono in possesso della seguente smartshield:
http://www.elettroinnova.it/
Ho delle SLE4442,su cui dovrei scrivere e leggere dei dati provenienti da un contapezzi.Una volta inserita la smartcard,bisognera' leggerne il contenuto,e un volta contati i pezzi ,aggiungerli,sovrascrivendo quelli presenti.
La variabile e' di tipo intero: int contatore.
Il mio problema e' che non riesco a capire come leggere e scrivere i dati.Mi spiego meglio:
Analizzando per esempio lo sketch di scrittura ho :
//write byte to address 0x20
smartcard.WriteByte4442(0x20,0x50);
dove 0x20 e l'indirizzo di memoria,e 0x50 e' il dato.
WriteByte4442(address,data);
Ho pensato di usare i puntatori, magari a quanto pare non e' possibile,perche' in questo caso non sto "puntando" ad una locazione di memoria "interna" di arduino,almeno cosi' ho capito!Come dovrei fare?
Di seguito gli sketch di lettura e di scrittura delle SLE4442
Ecco lo sketch completo, di scrittura:
/*
Smartcard Library - WriteCard
Demonstrates the use of a SLE4442 sync smartcard. The Smartcard
library works with the Arduino Smartcard shield.
This sketch demonstrates the use of the VerifyPSC4442() and
WriteByte4442() functions. Please check the correct PSC code of
smartcard, otherwise after three incorrect attempts the card
will be blocked.
The circuit:
SmartShield (http://www.elettroinnova.it)
Library originally added 12 Apr 2012
by Fabio Riscica
This example code is in the public domain.
*/
// include the SPI library:
#include <SPI.h>
//include the Smartcard library
#include <Smartcard.h>
// initialize the library with address of slave select pin
Smartcard smartcard(7);
//convert from hexadecimal to ASCII for display the result
void HexToAsc(char *c){
if (((*c&0x0F)>=0)&&((*c&0x0F)<=9))
*(c+1) = (*c&0x0F)+0x30;
else
*(c+1) = (*c&0x0F)+0x37;
if ((((*c&0xF0)>>4)>=0)&&(((*c&0xF0)>>4)<=9))
*c = ((*c&0xF0)>>4)+0x30;
else
*c = ((*c&0xF0)>>4)+0x37;
}
void setup() {
// start the serial library:
Serial.begin(9600);
}
void loop() {
unsigned char data[16];
char ascii_data[2];
unsigned char psc[3];
Serial.print("Wait smartcard insertion... ");
//wait smartcard
while(!smartcard.IsCardPresent(1)){
delay(500);
}
Serial.println("done");
Serial.println();
//reset smartcard
smartcard.PowerOnATRSC(data);
Serial.println(">> VerifyPSC4442 <<");
Serial.println();
//check PSC
psc[0] = 0x17;
psc[1] = 0x05;
psc[2] = 0x65;
data[0] = smartcard.VerifyPSC4442(psc);
switch(data[0]){
case 0x07 :
break;
case 0x06 :
Serial.println("failed - two attempts remaining");
Serial.println();
break;
case 0x04 :
Serial.println("failed - one attempt remaining");
Serial.println();
break;
case 0x00 :
Serial.println("locked");
Serial.println();
break;
}
Serial.println(">> Write Byte <<");
Serial.println();
//write byte to address 0x20
smartcard.WriteByte4442(0x20,0x50);
Serial.print("Wait smartcard extraction...");
smartcard.PowerOffSC();
//wait smartcard extraction
while(smartcard.IsCardPresent(1)){
delay(500);
}
Serial.println("done");
Serial.println();
}
E quello di lettura:
/*
Smartcard Library - WriteCard
Demonstrates the use of a SLE4442 sync smartcard. The Smartcard
library works with the Arduino Smartcard shield.
This sketch demonstrates the use of the VerifyPSC4442() and
WriteByte4442() functions. Please check the correct PSC code of
smartcard, otherwise after three incorrect attempts the card
will be blocked.
The circuit:
SmartShield (http://www.elettroinnova.it)
Library originally added 12 Apr 2012
by Fabio Riscica
This example code is in the public domain.
*/
// include the SPI library:
#include <SPI.h>
//include the Smartcard library
#include <Smartcard.h>
// initialize the library with address of slave select pin
Smartcard smartcard(7);
//convert from hexadecimal to ASCII for display the result
void HexToAsc(char *c){
if (((*c&0x0F)>=0)&&((*c&0x0F)<=9))
*(c+1) = (*c&0x0F)+0x30;
else
*(c+1) = (*c&0x0F)+0x37;
if ((((*c&0xF0)>>4)>=0)&&(((*c&0xF0)>>4)<=9))
*c = ((*c&0xF0)>>4)+0x30;
else
*c = ((*c&0xF0)>>4)+0x37;
}
void setup() {
// start the serial library:
Serial.begin(9600);
pinMode(2, OUTPUT);
}
void loop() {
unsigned char data[16];
char ascii_data[2];
Serial.print("Wait smartcard insertion... ");
//wait smartcard
while(!smartcard.IsCardPresent(1)){
delay(500);
}
Serial.println("done");
Serial.println();
//reset smartcard
smartcard.PowerOnATRSC(data);
Serial.println(">> ReadByte4442 <<");
Serial.println();
ascii_data[0] = smartcard.ReadByte4442(0x20);
HexToAsc(ascii_data);
if((ascii_data[0] == '5')&&(ascii_data[1] == '0'))
{
digitalWrite(2, HIGH);
Serial.println(">> LED OFF <<");
Serial.println();
}
else
{
digitalWrite(2, LOW);
Serial.println(">> LED ON <<");
Serial.println();
}
Serial.print("Wait smartcard extraction...");
smartcard.PowerOffSC();
//wait smartcard extraction
while(smartcard.IsCardPresent(1)){
delay(500);
}
Serial.println("done");
Serial.println();
}