Pages: 1 [2]   Go Down
Author Topic: input from barcode  (Read 1923 times)
0 Members and 1 Guest are viewing this topic.
Barnsley / uk
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

error: 'cardcnt' was not declared in scope
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 634
Posts: 50244
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int bufferLength = 64;


After this: // <-- what's this?


void setup() {

Where did this:
Code:
int cardCnt = sizeof(goodCards)/sizeof(goodCards[0]);
disappear to?
Logged

Barnsley / uk
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

scalar object 'goodCard' requires one element in initialiaer
Logged

Barnsley / uk
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

think i better start again
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 634
Posts: 50244
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm sorry. This:
Code:
char *goodCards = { "3455192327218", "4005209057240", "5060048310337" };
should have been this:
Code:
char *goodCards[] = { "3455192327218", "4005209057240", "5060048310337" };
Logged

Barnsley / uk
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

error: 'cardcnt' was not declared in scope





Code:
/*
Barcode Scanner                                                       
This code reads the input from a ps/2 keyboard or keyboard-like       
device (e.g. a barcode scanner), translates the scan-codes into       
numbers (only numbers from 0 to 9 can be used at the moment)           
It is nowhere near a complete implementation of the ps/2 protocol,     
but it should give you a starting point.                               
mys .// Benjamin Maus ( benjamin.maus <at> allesblinkt.com )         
2007                                                                   
*/
char *goodCards[] = { "3455192327218", "4005209057240", "5060048310337" };
int SCAN_ENTER = 0x5a; int SCAN_BREAK = 0xf0;
int breakActive = 0;
int clockPin = 3; // Clock is only output.
int dataPin = 2; // The data pin is bi-directional
// But at the moment we are only interested in receiving   
int ledPin = 13;  // When a SCAN_ENTER scancode is received the LED blink
int clockValue = 0; byte dataValue;
byte scanCodes[10] = {0x45,0x16,0x1e,0x26,0x25,0x2e,0x36,0x3d,0x3e,0x46}; char characters[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
int quantityCodes = 10;
char buffer[64] = {}; // This saves the characters (for now only numbers)
int bufferPos = 0;
int bufferLength = 64;





void setup() {
pinMode(dataPin, INPUT);                                               
pinMode(clockPin, INPUT);                                             
pinMode(ledPin, OUTPUT);                                               
Serial.begin(9600);                                                   
}

void loop() {
dataValue = dataRead();                                               
// If there is a break code, skip the next byte                       
if (dataValue == SCAN_BREAK) {                                         
breakActive = 1;                                                     
}                                                                     
// Translate the scan codes to numbers                                 
// If there is a match, store it to the buffer                         
for (int i = 0; i < quantityCodes; i++) {                             
byte temp = scanCodes[i];                                           
if(temp == dataValue){                                               
if(!breakActive == 1){                                             
buffer[bufferPos] = characters[i];                               
bufferPos++;                                                     
}                                                                 
}                                                                   
}                                                                     
//Serial.print('*'); // Output an asterix for every byte               
// Print the buffer if SCAN_ENTER is pressed.                         
if(dataValue == SCAN_ENTER){                                           
Serial.print("\nbuffer: ");                                         
// Read the buffer                                                   
int goodMatch = -1;
for(int c=0; c<cardCnt; c++)

{
   if(strcmp(buffer, goodCards[c]) == 0)
   {
      goodMatch = c;
      break;
   }
}

Serial.print("goodMatch  = ");
Serial.println(goodMatch);     // Will print index of good card in array

                int i=0;                          
if (buffer[i] != 0) {                                               
while(buffer[i] != 0) {                                           
Serial.print( buffer[i] );                                       
buffer[i] = 0;                                                   
i++;                                                             
}                                                                 
}                                                                   
Serial.println(" [Enter]");                                         
bufferPos = 0;                                                       
// Blink the LED                                                    
digitalWrite(ledPin, HIGH);                                         
delay(300);                                                         
digitalWrite(ledPin, LOW);                                           
}                                                                     
int goodMatch = -1;

for(int c=0; c<cardCnt; c++)
{
   if(strcmp(buffer, goodCards[c]) == 0)
   {
      goodMatch = c;
      break;
   }
}

Serial.print("goodMatch  = ");
Serial.println(goodMatch);     // Will print index of good card in array// Reset the SCAN_BREAK state if the byte was a normal one             
if(dataValue != SCAN_BREAK){                                           
breakActive = 0;                                                     
}                                                                     
dataValue = 0;                                                         
}

int dataRead() {
byte val = 0;                                                         
// Skip start state and start bit                                     
while (digitalRead(clockPin));  // Wait for LOW.                       
// clock is high when idle                                             
while (!digitalRead(clockPin)); // Wait for HIGH.                     
while (digitalRead(clockPin));  // Wait for LOW.                       
for (int offset = 0; offset < 8; offset++) {                           
while (digitalRead(clockPin));         // Wait for LOW               
val |= digitalRead(dataPin) << offset; // Add to byte               
while (!digitalRead(clockPin));        // Wait for HIGH             
}                                                                     
// Skipping parity and stop bits down here.                           
while (digitalRead(clockPin));           // Wait for LOW.             
while (!digitalRead(clockPin));          // Wait for HIGH.             
while (digitalRead(clockPin));           // Wait for LOW.             
while (!digitalRead(clockPin));          // Wait for HIGH.             
return val;                                                           
}
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 634
Posts: 50244
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

See reply #16 - bottom half.
Logged

Barnsley / uk
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for that but no matter what barcode i scan it prints good match even one's thats not registered
Logged

Barnsley / uk
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



* untitled.bmp (2304.05 KB, 1024x768 - viewed 25 times.)
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 634
Posts: 50244
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One of the scans showed 40052005724. You said that the valid value was 4005209057240. Similar, but not the same. Try putting "40052005724" in the array.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8966
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

will not complile

Change:
Code:
char *goodCards = {"3455192327218", "4005209057240", "5060048310337" };
to
Code:
const int cardCnt = 3;
char *goodCards[cardCnt] = { "3455192327218", "4005209057240", "5060048310337" };
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Barnsley / uk
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For some reason the it is not reading all the number’s … the barcode is 5060048310337 it  reads 5060041033. But this is not a problem as long as if reads the same number for that barcode every time ……. So is this how it should look  ?


* untitled.bmp (2304.05 KB, 1024x768 - viewed 20 times.)
Logged

Pages: 1 [2]   Go Up
Jump to: