Description
i_flush()
– sends out all data in the tx-buffer just like the function flush(). It returns 1 if the i_BLOCKING_TIMEOUT (default: 20000 ms) time expired during the attempt to send all data from the tx buffer onto the bus. i_flush() toghether with i_BLOCKING_TIMEOUT allows to react in cases where the CAN bus is blocked (eg. in bus_off state etc.).
Syntax
myExampleSerial.i_flush();
Parameters
None
Returns
0: OK all data from the tx buffer could be sent
1: Failed sending the tx buffer data
Example Code
The following example reduces the i_BLOCKING_TIMEOUT to 1 sec so that we see the effect more quickly. Leave it to its default values of 20 sec in normal circumstances.
void setup()
{
// Wait for the PC can2ser-monitor to send handshakes
while(!Serial) {;}
Serial.println("Hello. Here is the device, I received your handshaking.");
Serial.i_BLOCKING_TIMEOUT = 1000; // interval that we expect handshake/alive mesg.
}
void loop ()
{
Serial.println("Hello PC!");
if(Serial.i_flush() == 0) // LED indicates the PC could receive the data
digitalWrite(LED_BUILTIN, HIGH);
else // LED indicates the tx buffer data could not be delivered
// within the last i_BLOCKING_TIMEOUT milliseconds)
digitalWrite(LED_BUILTIN, LOW);
}