Plugins¶
The library supports I/O plugins in order to enable RPC communication over a range of interfaces. Currently, the following plugins are implemented.
name |
description |
status |
---|---|---|
|
The standard Arduino Serial interface. |
working |
|
The Arduino SoftwareSerial interface. |
untested |
|
RS485 serial interface. |
working |
|
Arduino Ethernet interface. |
untested |
|
Arduino WiFi interface. |
working |
|
I2C / TWI Wire interface. |
untested |
A plugin inherits from Stream
and should override the following
methods.
name |
description |
---|---|
Constructor. |
|
|
Number of bytes available for reading. |
|
Read a single byte or |
|
Preview the next byte. |
|
Write a single byte, return the number of bytes written. |
Usually, the I/O plugin is declared as a global object instance in the sketch
and initialized in the setup()
function. See the RS485 sketch for an
example that uses a custom I/O plugin.
Multiple I/O interfaces¶
It is possible to use multiple I/O interfaces at the same time. This can be done by either serving a different set of methods on each interface or by serving the same set of methods on multiple interfaces.
To serve different methods on each interface, the interface()
function is
simply used multiple times.
Example¶
Suppose we have set up two I/O interfaces named Serial
and
SerialUSB
, we serve different methods on each of the interfaces as
follows.
void loop() {
interface(
Serial,
inc, F("inc: Increment a value. @a: Value. @return: a + 1."));
interface(
SerialUSB,
setLed, F("set_led: Set LED brightness. @brightness: Brightness."));
}
Alternatively, it is possible to serve the same set of methods on multiple
interfaces. This can be done by passing a Tuple of pointers to the interfaces
as the first parameter of the interface()
function.
Example¶
Suppose we have set up two I/O interfaces named Serial
and
SerialUSB
, we serve the same methods on both interfaces by grouping
pointers to these interfaces with the pack()
function as follows.
void loop() {
interface(
pack(&Serial, &SerialUSB),
inc, F("inc: Increment a value. @a: Value. @return: a + 1."));
}
Finally, it is possible to combine both of the strategies described above.