I wanna the RFID model to recognize the RFID number, then to choose which group it belongs to and send the group number to APC220 , after that I can see the group number in Serial Monitor. Is there any problems with my programs? I'm new with Arduino, who can help me?
int val = 0;
int status = 0;
unsigned char searchCMD[] = {0xAA, 0xBB,0x02, 0x20, 0x22};
unsigned char searchRES[4];
void setup()
{
Serial.begin(19200);
Serial2.begin(19200);//input RFID
Serial1.begin(19200);//output APC220
}
int searchCard()
{
Serial2.write(searchCMD, 5);
delay(100);
status = 0;
while(true) {
if (Serial2.available() > 0) {
val = Serial2.read();
switch (status) {
case 0: // parse 0xAA
if (val == 0xAA) status = 1;
break;
case 1: // parse 0xBB
if (val == 0xBB) status = 2;
else return -1;
break;
case 2:
if (val == 0x06) status = 3;
else return -1;
break;
case 3:
if (val == 0x20) status = 4;
else return -1;
break;
case 4:
case 5:
case 6:
case 7:
searchRES[status - 4] = val;
status ++;
break;
case 8:
return 0; // read successfully
break;
default:
return -1;
break;
}