Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Explained samples

Ivan edited this page Jan 31, 2019 · 2 revisions

Send a broadcast message

This library manage up to 255 addresses, starting from 0 assigned to the master, ending at 254 reserved as broadcast address.

Broadcast messages are managed by all the devices regardless of their address with the only exception of the sender device (this device will not route the message to himself)

This master example will broadcast the stringMessage string

RS485Message *m = new RS485Message();
m->setDestinationAddress(254);
if(m->setStringPayload(stringMessage)){
  master.queueMessage(m);
}
delete m;

Do heavy work on our write slot.

Sometimes can be useful to do some heavy task while we have the write permissions because in this time slot the RS485 bus is stopped and waiting for our response. This tipically is suggested if the heavy work can frooze the arduino.

The return value from the function RS485Master::haveWritePermission() or RS485Slave::haveWritePermission() is here for help us.

In this example, a slave do the heavy work only when

void loop(){
  slave.loop();
  if (slave.haveWritePermission()){
    doHeavyWork();
  }
}

Note that the heavy work cannot use more time than the defined token RTT time or the master will trigger the token regeneration.