Sending struct through serial1

I'm using MKRZero to send data to other board through serial1 (both boards have rf module)

I wrote this function to send a struct to the other board but I'm getting error while compling :
void sendRequestToMaster()
{
header_S hdrSend;
hdrSend.sendRecieve = 1;
hdrSend.gatewayID = GATE_WAY;
hdrSend.sensorID = 0;
hdrSend.msgType = AskForSend; // request
hdrSend.msgSize = 0;

  Serial1.write(hdrSend, sizeof(header_S));

}

error massege :

C:\Users\User\Documents\Arduino\GateWaySketches\AskForSend\AskForSend.ino: In function 'void sendRequestToMaster()':

AskForSend:89:46: error: no matching function for call to 'Uart::write(header_S&, unsigned int)'

   Serial1.write(hdrSend, sizeof(header_S));

                                          ^

In file included from C:\Users\User\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.11\variants\mkrzero/variant.h:162:0,

             from C:\Users\User\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.11\cores\arduino/Arduino.h:48,

             from sketch\AskForSend.ino.cpp:1:

C:\Users\User\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.11\cores\arduino/Uart.h:40:12: note: candidate: virtual size_t Uart::write(uint8_t)

 size_t write(const uint8_t data);

        ^~~~~

C:\Users\User\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.11\cores\arduino/Uart.h:40:12: note: candidate expects 1 argument, 2 provided

In file included from C:\Users\User\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.11\cores\arduino/api/ArduinoAPI.h:31:0,

             from C:\Users\User\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.11\cores\arduino/Arduino.h:23,

             from sketch\AskForSend.ino.cpp:1:

C:\Users\User\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.11\cores\arduino/api/Print.h:55:12: note: candidate: size_t arduino::Print::write(const char*, size_t)

 size_t write(const char *buffer, size_t size) {

        ^~~~~

C:\Users\User\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.11\cores\arduino/api/Print.h:55:12: note: no known conversion for argument 1 from 'header_S' to 'const char*'

C:\Users\User\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.11\cores\arduino/api/Print.h:54:20: note: candidate: virtual size_t arduino::Print::write(const uint8_t*, size_t)

 virtual size_t write(const uint8_t *buffer, size_t size);

                ^~~~~

C:\Users\User\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.11\cores\arduino/api/Print.h:54:20: note: no known conversion for argument 1 from 'header_S' to 'const uint8_t* {aka const unsigned char*}'

C:\Users\User\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.11\cores\arduino/api/Print.h:50:12: note: candidate: size_t arduino::Print::write(const char*)

 size_t write(const char *str) {

        ^~~~~

C:\Users\User\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.11\cores\arduino/api/Print.h:50:12: note: candidate expects 1 argument, 2 provided

exit status 1

no matching function for call to 'Uart::write(header_S&, unsigned int)'

How about

(Sorry, I can't remember what sort of pointer write requires, and I'm away from a PC at the moment)

Nope it didn't work.

Try char* instead of void*

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.