Hello All,
I am working on a project which is using 2 serial devices, in particular a finger print scanner and a camera as well as both of these devices use the RS232 communication protocol. The communication type they use is packet communication, where you have a header -> command -> data -> etc.. With each packet sent to the device for certain commands there will be an acknowledgement. I have most of this working.. however; I have encountered a small problem.
As I stated above, the devices use packet communication where if I send a command to it then it will acknowledge that command as well as pass some information like: successs/fail. Here is a picture from my logic analyzer:
( the image seems to clip off... go here for the full image: http://i26.tinypic.com/1dyixw.jpg )
Here is some information about the labels:
(ALL TTL LOGIC BELOW)
Tx : This is the data coming from my Arduino Mega to the device
Rx : What the device is sending back (converted from rs232 to TTL using a MAX232 SIPEX IC)
ARR OUT : This is the information I have stored into an array (res) which is defined in the code below...
// This function is to synchronize with the camera
void cam_sync()
{
char test[20];
char res[12]={
0 };
char com[6] = {
0xAA, 0x0D, 0x00, 0x00, 0x00, 0x00 };
int count = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("-Synchronization-");
lcd.setCursor(0,1);
lcd.print("Att Connection");
lcd.setCursor(0,2);
lcd.print("Please wait...");
//delay(1000);
// send until a response is returned
Serial3.flush();
for(int i =0;i<6;i++)
Serial3.print(com[i]);
while(Serial3.available() < 0)
{
for(int i =0;i<6;i++)
Serial3.print(com[i]);
lcd.setCursor(0,3);
lcd.print("Waiting for response");
delay(1000);
count++;
//if(count == 10)
// break;
}
lcd.setCursor(0,3);
lcd.print("Data Found...");
for(int i =0; i<12;i++)
res[i]=char(Serial3.read());
if((res[0] == 0xAA) && (res[1] == 0x0E) && (res[2] == 0x0D) && (res[4] == 0x00) && (res[5] == 0x00)
&& (res[6] == 0xAA) && (res[7] == 0x0D) && (res[8] == 0x00) && (res[9] = 0x00) && (res[10] == 0x00) && (res[11] == 0x00))
{
lcd.setCursor(0,3);
lcd.print("Connection Successful");
delay(4000);
}
// print what is in the array to serial port # 2
for(int i =0; i<12;i++)
Serial2.print(res[i]);
//for(int i =0; i<12;i++)
//Serial.print(res[i]);
Serial3.flush();
delay(5000);
}
When executing this function all I see is "Data Found..." when according to the output of my logic analyzer, it should be going into the if statement that checks all the bytes and outputs "Connection Successful" Here is the datasheet to the camera:
*NOTE XX means that it does not matter what that byte it (According to the datasheet) which can be found here:
http://www.saelig.com/product/BOVI001.htm
I am stumped as to why it's not going into the if statement, if infact all that information is exactly what is output onto the serial port, which i display for debugging purposes.
If anyone could potentially lend a hand to help me solve this problem I would be eternally grateful.
Thanks,
Jox