begin()

Description

Initialize the ModbusMaster object and assign it to the Serial class or the IPAddress class.

Syntax

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

Parameters

bus1/bus2: ModbusMaster object.

mode: Specifies the communication mode of the ModbusMaster object. Its arguments are MODBUS_RTU, MODBUS_ASCII, or MODBUS_TCP.

serial: specifies the Serial class as the transmission channel.

modbus_server_ip: specifies the IPAddress class 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

20

21

#include <Ethernet.h>

#include <Modbus86.h>

 

ModbusMaster bus1;

ModbusMaster bus2;

 

IPAddress SlaveIP(192,168,3,59);

 

void setup()

{

    Serial1.begin(115200);

    bus1.begin(MODBUS_RTU, Serial1);

    // bus1.begin(MODBUS_ASCII, Serial1);

     

    Ethernet.begin();

    bus2.begin(MODBUS_TCP, SlaveIP);   

}

 

void loop()

{

}

See Also

ModbusMasterNode::attach()
ModbusSlave::begin()


 

Library Reference

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.