Hey fellow programers.
First of all i would like to thank to this community. It has helped me many times searching through to posts and finding great examples and solutions you all posted.
However now i have a problem i can not figure out even with help of some older posts concerning my current problem.
Situation is following. I have arduino Mega2560 and RFID reader connected via RS232 to TTL.
When i swipe card and read serial port i get 10 bytes saving them in byte receivedchars[10].
Id of the card is located on positions 6,7 and 8.
In one example i got: receivedchars[4] = 136 ; receivedchars[5] = 86 ; receivedchars[6] = 153.
Now i should convert this to 8935065.
I can check this manually by printing those numbers in HEX getting: 88, 56, 99. If i put those numbers in windows calculator as HEX i get correct DEC number of 8935065.
How would you do this inside the code??
My current code is a little messy but this is it:
int TempRFID;
int startMarker = 2;
int endMarker = 3;
const int numchars = 10;
byte receivedchars[numchars];
char numReceived = 0;
boolean newData = false;
//===================================
//= SETUP =
//===================================
// the setup routine runs once when you press reset:
void setup() {
Serial.begin(115200);//moniteur serie
Serial1.begin(9600);
delay(3000); //delai pour ouvrir COM8 apres televersement
//========== LED =========
Serial.println(F("+++ RxBinaryData +++"));
} // FIN de setup
//===================================
//= LOOP =
//===================================
void loop() {
recvcharsWithStartEndMarkers();
showNewData();
} //FIN de loop
//=================================================================================
//====================== AUTRES FONCTIONS ==================================
//================================================================================
void recvcharsWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
byte rb;
while (Serial1.available() > 0 && newData == false) {//Rx: F2 40 05 65 FD 08 08 F6
rb = Serial1.read();
Serial.print(rb);
if (recvInProgress == true) {
if (rb != endMarker) {
receivedchars[ndx] = rb;
ndx++;
if (ndx >= numchars) {
ndx = numchars - 1;
}
}
else {
receivedchars[ndx] = '\0'; // terminate the string
recvInProgress = false;
numReceived = ndx; // save the number for use when printing
ndx = 0;
newData = true;
}
}//FIN de recinprogress true
else if (rb == startMarker) {
recvInProgress = true;
}
}//FIN de while serial1
}// FIN DE FONCTION
//================================================================================
void showNewData() {
if (newData == true) {
Serial.print("Rx (HEX): ");
for (char n = 0; n < numReceived; n++) {
Serial.print(receivedchars[n]);
Serial.print(' ');
}//FIN de serial print N chars
//pr2: display chars
///*
Serial.print("\nchar START: "); Serial.print(startMarker);
Serial.print("\nchar 0: "); Serial.print(receivedchars[0]);
Serial.print("\nchar 1: "); Serial.print(receivedchars[1]);
Serial.print("\nchar 2: "); Serial.print(receivedchars[2]);
Serial.print("\nchar 3: "); Serial.print(receivedchars[3]);
Serial.print("\nchar 4: "); Serial.print(receivedchars[4]);
Serial.print("\nchar 5: "); Serial.print(receivedchars[5]);
Serial.print("\nchar 6: "); Serial.print(receivedchars[6]);
Serial.print("\nchar 7: "); Serial.print(receivedchars[7]);
Serial.print("\nchar END: "); Serial.println(endMarker);
//*/
Serial.println();
int nekaj = receivedchars[4];
Serial.println(nekaj);
TempRFID = 0;
for (int n = 4; n < 7; n++){
TempRFID = TempRFID*10 + (receivedchars[n] - '0');
Serial.println(n);
}
Serial.println(TempRFID);
//
newData = false;
}//FIN de new data true
}// FIN DE FONCTION
Thank you all in advance