Description

begin() – starts the CAN2SER communication. In case the CAN2SER instance uses handshaking (see constructor) this will start sending handshake and alive messages to the peer (e.g. the PC can2ser monitor).

Syntax

myExampleSerial.begin();

Parameters

None

Returns

Nothing

Example Code

The following example creates a second CAN2SER object that can be used just like Serial for communications to the PC-CAN2SER-Monitors. The new CAN2SER object will use channel 1 whereas Serial uses channel 0 by default.

// Create the additional global object
CAN2SER SerialPC2(&MCAN0, &BOOTLOADER_SETTING, 1, false);

void setup()
{  
  // Start the new serial connection
  SerialPC2.begin();

  // Wait for the user to open 2x can2ser-monitor windows
  while (!Serial || !SerialPC2) 
  {
    yield(); // maintain CAN traffic handling in the meanwhile
  }
  // Send 'hello' through both link channels
  Serial.println("Hello PC. Here is Serial");
  Serial2.println("Hello PC. Here is Serial2");
}

void loop () 
{
}

Notes and Warnings

The instance that is created by default Serial would not need to be started with a begin() call because this is also already done by the start-up code before the void setup() routine starts. If begin() is called again, it would resend a ‘start’ handshake message, resets the rotating message counter and the RX status. This would not affect communication at all, but may be used in cases where the RX status indicates that there has been a problem receiving messages.
Note: begin() does not clear any internal rx/tx buffers. Use end() if you like to clear the buffers before a fresh begin().

See also

Example to create a serial link between two devices
Example to create an additional link to the PC
CAN2SER Class