Hi All,
I am trying to assemble an array of bytes for transmission via rs485, and am getting a compile error when I try
"Message[7] = now.day" ....... the error message is " error: argument of type 'uint8_t (DateTime::)()const' does not match 'byte'
I have the following in my code ..
// setup an instance of DateTime class from RTClib
DateTime now;
byte Message [39]; // message to office unit
Q. How do I do the conversion to byte ...
Thanks for any/all input
Hi CharlieD
Does it help if you change to this?
uint8_t Message [39];
And could you post your code and the error message using code tags (the "#" button above the row of smileys).
Regards
Ray
Hi Ray
It probably would, but all the rest of the data is already declared and used as byte, and I am trying to use Nick Gammon's library which has nice error detection and crc etc ... don't want to re-write his stuff - that is a bit beyond me !!
My code, at the moment, is a huge compilation of PN532 card-reading & writing and loads of other stuff - I will cut it down to only the part that is causing this issue, and post it shortly
Thanks for your help,
Charlie
OK, understand.
Try this.
Message[7] = (byte)now.day;
Thanks, but tried that already ... get this error message ...
RS485test.ino: In function 'void MakeMessage()':
RS485test:64: error: invalid use of member (did you forget the '&' ?)
OK, probably need to see the code, then
Ok, here you go ... not code that I am proud of, but it does illustrate the problem ... it is Message[7] to Message[13] which are the problem
Cheers
#include <RS485_protocol.h>
#include "RTClib.h"
#include <SoftwareSerial.h>
#include <Wire.h>
#define Xmit_Pin A1
#define Rec_Pin A2
#define Enable_Pin A3
#define RS485_Rate 9600
#define Serial_Monitor_Rate 19200
SoftwareSerial RS485 (Rec_Pin,Xmit_Pin);
// callback routines
void fWrite (const byte what){
// rs485.print (what);
Serial.print(what, HEX);
Serial.print(',');
}
int fAvailable (){
// return rs485.available ();
return Serial.available ();
}
int fRead (){
// return rs485.read ();
return Serial.read ();
}
// define the Real Time Clock object
RTC_DS1307 RTC;
int RS485TxPin = A3; // pin A3 to enable RS485 Transmitter
byte Message [39]; // message to office unit
unsigned int NewCounts [9];
// setup an instance of DateTime class from RTClib
DateTime now;
uint8_t OldUid[7] = {
1,2,3,4,0,0,0};
String OldSupplierName = "Old Suplier Name"; // 16 chars
unsigned int OldCounts[9] = {
1,2,3,4,5,6,7,8,9};
void setup() {
RS485.begin(RS485_Rate);
pinMode (Enable_Pin, OUTPUT); // driver output enable
Serial.begin(Serial_Monitor_Rate);
pinMode(Xmit_Pin, OUTPUT); // Tx
pinMode(Rec_Pin , INPUT); // Rx
RS485.begin(9600);
Serial.println(F("RS485test !"));
Wire.begin();
RTC.begin();
}
void MakeMessage (void){
now = RTC.now();
Message[0] = 0xAA; // to assist with message sync
Message[1] = 3; // Target = Office
Message[2] = 1; // Source, 1 = Grader, 2 = Door
Message[3] = OldUid[0];
Message[4] = OldUid[1];
Message[5] = OldUid[2];
Message[6] = OldUid[3];
// Message[7] = (byte(now.day));
// Message[8] = now.month;
// Message[9] = now.year;
// Message[10] = now.year;
// Message[11] = now.hour;
// Message[12] = now.minute;
// Message[13] = now.second;
for (int i=0; i<16; i++){
Message[i+14] = OldSupplierName[i];
}
for (int i=0; i<9; i++){
Message[i+31] = OldCounts[i];
}
}
void loop(){
MakeMessage();
digitalWrite (Enable_Pin, HIGH); // enable sending
sendMsg (fWrite, Message, sizeof Message);
Serial.println("Got here !");
digitalWrite (Enable_Pin, LOW); // disable sending
byte buf [10];
byte received = recvMsg (fAvailable, fRead, buf, sizeof buf);
Serial.println(received);
delay(2000);
}
Hi there
I think day, month, etc are methods of the DateTime class. So try changing those lines to look like this:
Message[7] = now.day();
Message[8] = now.month();
Message[9] = now.year();
etc
Regards
Ray
system
June 15, 2014, 1:14pm
9
// Message[7] = (byte(now.day));
(May(be)) you (need) (some more) useless parentheses. in there. Maybe you need to get a clue about how a cast works. Hackscribble showed what the code was supposed to look like.
Ray, thanks for that .. you fixed it
Paul, wow
Cheers