Hi there,
thank you very much for your time and thank you, that you keep up this forum.
As I am programming sketches for Arduino (the user name gives a hint) I am working with c++ and thats why I am here.
Please don't be angry with me since I am not an IT specialist and I know that there is plenty of stuff I have to learn.
Well, this is my project:
I have an arduino nano which hosts a RFID reader. Once a RFID tag is read the UUID and the data of one sector is supposed to be passed on to a RS485 network. Another station (in fact another arduino nano in the same network) is serving as central to operate the access rights of the RFID tags.
The reader is driven with the following library:
https://github.com/miguelbalboa/rfid
The RS485 protocol library is:
https://github.com/MajenkoLibraries/ICSC
After all I have some issues with the conversion of data types.
To ensure that everything is understandable I will try to include all necessary lines of code.
Once the card is read the following parameters (UUID and length) are available through the library:
mfrc522.uid.uidByte
mfrc522.uid.size
These are meant to be transferred to another variable as well as the data of the sector.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
byte rfidUUID[8], customData[16], transmData[24];
char transmDataChar[24];
void loop(){
regUUID(mfrc522.uid.uidByte, mfrc522.uid.size);
status = mfrc522.MIFARE_Read(blockAddr, buffer, &size);
regCustomData(buffer, size);
if(rfidUUID && customData){ // data set complete, prepare to send
sendRFIDData(rfidUUID, customData);
}
} // end loop
void regUUID(byte *uidByte, byte bufferSize) {
for (byte i = 0; i < 8; i++) {
transmData[i] = uidByte[i];
transmDataChar[i] = (char)uidByte[i];
}
readyToSend = readyToSend +1;
dump_byte_array(uidByte, 8, 'UIDBYTE')
}
void regCustomData(byte *custData, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
transmData[i+8] = custData[i];
}
readyToSend = readyToSend +1;
}
// data acquisition complete, send data to bus
void sendRFIDData(byte *uuid, byte *customId) {
// first converting the data to one char array: 8 + 16 + 1 terminating = 25 bytes
Serial.println("data in sending function");
for (int i = 0; i < 24; i ++){
if (i<8){
transmData[i] = uuid[i];
Serial.print(i); Serial.print(": \t"); Serial.println(uuid[i], HEX);
} else if (i > 7){
transmData[i] = customId[i-8];
} else if (i > 23){
transmData[i] = '\0';
}
// send data:
ICSC.send(1, 'C', 24, (char*)&transmData);
}
|
So my problem on this code is:
it is compiled without an error - however, the UUID is not transferred to the transmData. At least, I can't see it in the serial monitor output.
It would be very helpful for me if some of your pros would have a look at my lines of code. Please let me know if some additional information is needed.
Any suggestions are welcome!
Thank you very much, kduino
ps:
A second issue is that when I transfer the data over the bus, I have to cast it to char and I get a total mess of data output on the other side. What I don't understand is that I have i.e. 3B as HEX corresponding to ";" as char. But why there are negative numbers coming out of the transmission?
How can I transform a tag ID (i.e. 78 3B 87 A2) to a char when every character has only one byte????
I printed out the DEC and HEX data and there are negative numbers as well although it is written everywhere that theoretically char and byte is the same information. I would come to this when the first challenge is solved... Or it will be solved together.