serial.listen()

serial.listen(port, delimiter, callback)

Buffers received bytes and calls the callback whenever the delimiter character arrives.

Fills the receive buffer while watching for the delimiter character, then executes the callback with a message object:

Field Meaning
msg.port Port the message arrived on.
msg.ovf true if the receive buffer overflowed — discard the message.
msg.data The received data.

Arguments

NameTypeRequiredDefaultDescription
port number yes 1 = isolated RS-485, 2 = non-isolated RS-485.
delimiter string yes End-of-message character, e.g. "\r".
callback function yes Callback function(msg){ … } — see the field table.

Example

function serialRxCallback(msg){
  print("Received Serial Msg");
  print("Port:", msg.port);
  print("Overflowed:", msg.ovf);
  print("Data:", msg.data);
}

serial.listen(port, "\r", serialRxCallback);