RS485 Lib - compiler warnings

Hallo Nick,

best thanks for your lib, but I have compiler warnings with my Sketch. I do not unterstand this.
RS485 non blocking version

Info only. Please to interchange "const int bufferSize_ and byte* date_ in your Header File.
because, RS485::bufferSize_’ will be initialized after [-Wreorder]

Your examples compile error free.

My problem is ?

SendNonBlocking.ino:22:1: warning: no return statement in function returning non-void [-Wreturn-type]

}

^

size_t fWrite (const byte what) {
Serial2.write (what);
}

/*
 * DanBus Test Sende Sketch zum Daten Sendem mit dem Nick Gammon NonBlocking RS485 Librarier
 * Die Daten sind in einem BYTE Struct aus 6 Bytes
 * Das 1. Byte Empfangs Adresse
 * Das 2. Byte ist die Funktion auf dem Slave Node
 * Das Byte 3...6 sind Nutzdaten für die Funktionen  
*/

#include <RS485_non_blocking.h>

#define DriverPinDB 44
#define LEDPin 13
#define interval 5000

unsigned long lmillis = 0;
byte runs = 0;
unsigned long lmillisDebug = 0;

size_t fWrite (const byte what) {
  Serial2.write (what);
}

RS485 myChannel (NULL, NULL, fWrite, 8);

// definieren Nachricht
struct {
  byte adress;
  byte function;
  byte wert[4];
} message;




void setup() {
  // Pin Handling
  pinMode (DriverPinDB, OUTPUT);
  pinMode (LEDPin, OUTPUT);
  myChannel.begin();

  Serial2.begin(38400);  // definieren der Serial_2 Geschwindigkeit für die RS485
  
}

void loop() {
  
  // Poll Message every 5 secondes switch Adresses every Transmit
  if (millis() - lmillis >= interval) {
    if ((runs % 2) == 0) {
      message.function = 111;
      for (byte i = 0; i < 4; i++) {
        message.wert[i] = 110 + i;
      }
      sendMessage(1);
    }
    else {
      message.function = 222;
      for (byte i = 0; i < 4; i++) {
        message.wert[i] = 0 + (i*22);
      }
      sendMessage(2);
    }
    lmillis = millis();
    runs = runs + 1;
    digitalWrite(LEDPin, HIGH);   // Set onboard LED High for showing of transmitting
  }
  
  if (millis() - lmillis > 500) // Set onboard LED to low
    digitalWrite(LEDPin, LOW);
    
} // Ende der loop

void sendMessage(byte ADR) {
  message.adress = ADR;
  digitalWrite (DriverPinDB, HIGH);  // enable sending
  myChannel.sendMsg ((byte *) &message, sizeof message); // Send my Message
  while (!(UCSR2A & (1 << UDRE2)))
    UCSR2A |= 1 << TXC2;
  while (!(UCSR2A & (1 << TXC2)));  // Warten bis der Puffer des Serial2 leer ist
  digitalWrite (DriverPinDB, LOW);  // disable sending
}

Doc_Arduino:
Hallo Nick,

best thanks for your lib, but I have compiler warnings with my Sketch. I do not unterstand this.
RS485 non blocking version

Info only. Please to interchange "const int bufferSize_ and byte* date_ in your Header File.
because, RS485::bufferSize_’ will be initialized after [-Wreorder]

Your examples compile error free.

My problem is ?

/*
  • DanBus Test Sende Sketch zum Daten Sendem mit dem Nick Gammon NonBlocking RS485 Librarier
  • Die Daten sind in einem BYTE Struct aus 6 Bytes
  • Das 1. Byte Empfangs Adresse
  • Das 2. Byte ist die Funktion auf dem Slave Node
  • Das Byte 3…6 sind Nutzdaten für die Funktionen  
    */

#include <RS485_non_blocking.h>

#define DriverPinDB 44
#define LEDPin 13
#define interval 5000

unsigned long lmillis = 0;
byte runs = 0;
unsigned long lmillisDebug = 0;

size_t fWrite (const byte what) {
 Serial2.write (what);
}

RS485 myChannel (NULL, NULL, fWrite, 8);

// definieren Nachricht
struct {
 byte adress;
 byte function;
 byte wert[4];
} message;

void setup() {
 // Pin Handling
 pinMode (DriverPinDB, OUTPUT);
 pinMode (LEDPin, OUTPUT);
 myChannel.begin();

Serial2.begin(38400);  // definieren der Serial_2 Geschwindigkeit für die RS485
 
}

void loop() {
 
 // Poll Message every 5 secondes switch Adresses every Transmit
 if (millis() - lmillis >= interval) {
   if ((runs % 2) == 0) {
     message.function = 111;
     for (byte i = 0; i < 4; i++) {
       message.wert[i] = 110 + i;
     }
     sendMessage(1);
   }
   else {
     message.function = 222;
     for (byte i = 0; i < 4; i++) {
       message.wert[i] = 0 + (i*22);
     }
     sendMessage(2);
   }
   lmillis = millis();
   runs = runs + 1;
   digitalWrite(LEDPin, HIGH);   // Set onboard LED High for showing of transmitting
 }
 
 if (millis() - lmillis > 500) // Set onboard LED to low
   digitalWrite(LEDPin, LOW);
   
} // Ende der loop

void sendMessage(byte ADR) {
 message.adress = ADR;
 digitalWrite (DriverPinDB, HIGH);  // enable sending
 myChannel.sendMsg ((byte *) &message, sizeof message); // Send my Message
 while (!(UCSR2A & (1 << UDRE2)))
   UCSR2A |= 1 << TXC2;
 while (!(UCSR2A & (1 << TXC2)));  // Warten bis der Puffer des Serial2 leer ist
 digitalWrite (DriverPinDB, LOW);  // disable sending
}

When you code a function and specify the function will return a value, then don’t return a value. That is error you will receive.

size_t fWrite (const byte what) {
  Serial2.write (what);
}

This function fWrite() says it will return a size_t value. But, nowhere in the code does it actually return a value.

I would change the type declaration for size_t to something definite, like int. size_t is a compiler defined type that changes depending on flags passed during compile.

int fWrite (const byte what) {
int charsWritten = Serial2.write (what);
return charsWritten;
}

// or 

int fWrite (const byte what) {
return Serial2.write (what);
}

Chuck.

Hallo,

do you know Nicks non blocking Lib? http://www.gammon.com.au/forum/?id=11428

If I change size_t to int, then gives other compiler errors.

RS485 myChannel (NULL, NULL, fWrite, 8);

invalid conversion from 'int ()(byte) {aka int ()(unsigned char)}' to 'RS485::WriteCallback {aka unsigned int (*)(unsigned char)}' [-fpermissive] But. The original Example from Nick compile without errors*.*

I suspect this may be what you want:

size_t fWrite (const byte what) {
  return Serial2.write (what);
}

Hallo,

this is the original function of Nick for send a message.
I think your must read all of Nicks site / Link. Section non blocking.
The best is, Nick can answer self. :slight_smile: Or he is in the outback … :slight_smile:

Edit:
I write my sketch complete new again. Without compiler warnings/errors.