Problems with the connection between RFID and APC220

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?

rfid2.pde (1.41 KB)

Sorry,the program is as following:

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;
}

}
}
}

void loop()
{
if (searchCard() != -1) {
if (searchRES[0] == 0x5E && searchRES[1] == 0x97 && searchRES[2] == 0x25 && searchRES[3] == 0xC7) {
Serial1.println(1);
}
if (searchRES[0] == 0x2E && searchRES[1] == 0x05 && searchRES[2] == 0x63 && searchRES[3] == 0x3B) {
Serial1.println(2);
}
}
}

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

You what? You wanna? Want to try that in adult english?

You want to tell us what a APC220 is, and provide a link to it?

Is there any problems with my programs?

Don't you know if there is a problem?