Go Down

Topic: Reading 35 ascii characters from card reader track (Read 1 time) previous topic - next topic

Palliser

Hello there. What could be the best approach to read large amount of ASCII data from a track in a card?.
I have a serial card reader (ID Tech IDMB) and data contained in the three tracks of a card in the standard format: %ABCD.........? and ;ABCD............?. My initial interest is to know the best approach to read a maximum of 35 ASCII characters from one track using my Arduino uno. For example:
%FIELD1 FIELD2 FIELD3 FIELD4 FIELD5?. I did this in the past but reading a maximum of 3 and 4 ascii characters and saving them in one variable. What I need to do now is to read a maximum of 35 ASCII character from one track. Should I create an ascii table? How to save them? I will appreciate any help. Thank you.

PeterH

A char array is the most obvious way to store them. I suggest you keep the array null-terminated, so remember to size the array to include the final terminating char.
I only provide help via the forum - please do not contact me for private consultancy.

Arrch

Just posted this in another thread:



What you need is an array of chars:

Code: [Select]
const int maxLength = 50;
char readString[maxLength];


You also need an index variable (either global or static) that will keep track of where in the array you are.

Code: [Select]
int strIndex = 0;

And lastly, you need a character that will signal that you are done transmitting your string. This will depend on what program is sending you the string. The Arduino's Serial Monitor, for example can append '\r' and/or '\n' to the end of each transmission.

Code: [Select]
#define END_OF_STRING '\n'

From there you just need to read a character as you receive it and decide whether to parse the data and reset the array (if it's the END_OF_STRING marker):

Code: [Select]

// Do Something with the string
readString[0] = '\0'; // clear the array
strIndex = 0; // reset the index to 0


or add it to the array:

Code: [Select]
readString[strIndex] = inChar; // put the new char in the array
strIndex++; // increment our index for the next char
readString[strIndex] = '\0'; // null terminate our array to make it a proper string


Palliser

Thank you PeterH and Arrch.
Arrch, I will check your post and start to build the code and post here if I run into issues.

zoomkat

Do the strings sent start with either a "%" or ";" and always end with a "?" ?
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Palliser

It's a standard format B called sentinel.
For track 1: Start sentinel = %
             End sentinel = ?

For track 2: Start sentinel = ;
             End sentinel = ?

Track 3 is virtually unused by the major worldwide networks.

For a better understanding read http://en.wikipedia.org/wiki/Magnetic_stripe_card or google magnetic stripe card sources.

zoomkat

Code posted by others that captures the string between < and >. You could change that to % and ?.

Code: [Select]

String cmd;
String fullCmd;
boolean cmdComplete=false;

void setup () {
  Serial.begin(9600);
cmd="";
Serial.println("start duel delimit");
}

void loop() {
  char c;
  while(Serial.available()) {
    c=Serial.read();
    if (c=='<') {
      cmd="";
    } else if (c=='>') {
      fullCmd=cmd;
      cmd="";
      cmdComplete=true;
      break;
    } else {
       cmd+=c;
    }
  }
  if (cmdComplete==true) {
    Serial.println('<' + fullCmd + "_OK>");
    cmdComplete=false;
  }
}

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Palliser

Thanks zoomkat for the code. I really didn't have issues to capture few characters. My challenge is to capture/save and use them for validation purposes. Initially I thought to use a bar code reader sample but the one provided by Arrch looks like a good approach.

zoomkat

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Go Up