begin()

Description

Initializes a ModbusSlave object and specifies the mode and channel.

Syntax

bus1.begin(mode, serial) bus2.begin(mode)

Parameters

bus1/bus2: ModbusSlave object.

mode: specifies the communication mode of the ModbusSlave object, and its arguments are MODBUS_RTU, MODBUS_ASCII, or MODBUS_TCP.

serial: When mode is specified as MODBUS_RTU or MODBUS_ASCII, the Serial class must be specified as the transmission channel.

Return

bool: If successful, return true, otherwise return false

Example

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

#include <Ethernet.h>

#include <Modbus86.h>

 

ModbusSlave bus1;

ModbusSlave bus2;

 

void setup()

{

    Serial1.begin(115200);

    bus1.begin(MODBUS_RTU, Serial1);

    // bus1.begin(MODBUS_ASCII, Serial1);

     

    Ethernet.begin();

    bus2.begin(MODBUS_TCP);

}

 

void loop()

{

}

See Also

ModbusSlaveNode::attach()
ModbusMaster::begin()


Library Reference Home Page

The text in the 86Duino reference is modified from the Arduino reference and is licensed under the Creative Commons Attribution-ShareAlike 3.0 License. The code examples in the reference have been released into the public domain.