Lydia - Printhead
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ModbusRtu.h File Reference
#include <inttypes.h>
#include "Arduino.h"
#include "Print.h"
#include <SoftwareSerial.h>
#include "enums.h"
#include "./utils.h"

Go to the source code of this file.

Classes

class  Modbus
 Arduino class library for communicating with Modbus devices over USB/RS232/485 (via RTU protocol). More...
 
struct  modbus_t
 Master query structure: This includes all the necessary fields to make the Master generate a Modbus query. A Master may keep several of these structures and send them cyclically or use them according to program needs. More...
 

Macros

#define MAX_BUFFER   64
 maximum size for the communication buffer in bytes More...
 
#define RS485_CLEAR_DE   RS485_PORT_REG &= ~RS485_PIN_DE
 
#define RS485_CLEAR_RE   RS485_PORT_REG &= ~RS485_PIN_RE
 
#define RS485_DIR_REG   DDRJ
 
#define RS485_PIN_DE   0b01000000
 
#define RS485_PIN_RE   0b00100000
 
#define RS485_PORT_REG   PORTJ
 
#define RS485_SET_DE   RS485_PORT_REG |= RS485_PIN_DE
 
#define RS485_SET_RE   RS485_PORT_REG |= RS485_PIN_RE
 
#define T35   5
 

Enumerations

enum  { RESPONSE_SIZE = 6, EXCEPTION_SIZE = 3, CHECKSUM_SIZE = 2 }
 
enum  {
  NO_REPLY = 255, EXC_FUNC_CODE = 1, EXC_ADDR_RANGE = 2, EXC_REGS_QUANT = 3,
  EXC_EXECUTE = 4
}
 
enum  COM_STATES { COM_IDLE = 0, COM_WAITING = 1 }
 
enum  ERR_LIST {
  ERR_NOT_MASTER = -1, ERR_POLLING = -2, ERR_BUFF_OVERFLOW = -3, ERR_BAD_CRC = -4,
  ERR_EXCEPTION = -5
}
 
enum  MESSAGE {
  ID = 0, FUNC, ADD_HI, ADD_LO,
  NB_HI, NB_LO, BYTE_CNT
}
 Indexes to telegram frame positions. More...
 

Variables

const unsigned char fctsupported []
 

Detailed Description

Version
1.21 (modified by CONTROLLINO team)
Date
2016.02.21 (2017.03.30)
Author
Samuel Marco i Armengol (Thank you, Samuel!) @contact samma.nosp@m.rcoa.nosp@m.rmeng.nosp@m.ol@g.nosp@m.mail..nosp@m.com @contribution Helium6072

@description Arduino library for communicating with Modbus devices over RS232/USB/485 via RTU protocol.

Further information: http://modbus.org/ http://modbus.org/docs/Modbus_over_serial_line_V1_02.pdf

@license This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; version 2.1 of the License.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Definition in file ModbusRtu.h.

Macro Definition Documentation

◆ MAX_BUFFER

#define MAX_BUFFER   64

maximum size for the communication buffer in bytes

Definition at line 57 of file ModbusRtu.h.

◆ RS485_CLEAR_DE

#define RS485_CLEAR_DE   RS485_PORT_REG &= ~RS485_PIN_DE

Definition at line 51 of file ModbusRtu.h.

◆ RS485_CLEAR_RE

#define RS485_CLEAR_RE   RS485_PORT_REG &= ~RS485_PIN_RE

Definition at line 52 of file ModbusRtu.h.

◆ RS485_DIR_REG

#define RS485_DIR_REG   DDRJ

Definition at line 49 of file ModbusRtu.h.

◆ RS485_PIN_DE

#define RS485_PIN_DE   0b01000000

Definition at line 47 of file ModbusRtu.h.

◆ RS485_PIN_RE

#define RS485_PIN_RE   0b00100000

Definition at line 48 of file ModbusRtu.h.

◆ RS485_PORT_REG

#define RS485_PORT_REG   PORTJ

Definition at line 50 of file ModbusRtu.h.

◆ RS485_SET_DE

#define RS485_SET_DE   RS485_PORT_REG |= RS485_PIN_DE

Definition at line 53 of file ModbusRtu.h.

◆ RS485_SET_RE

#define RS485_SET_RE   RS485_PORT_REG |= RS485_PIN_RE

Definition at line 54 of file ModbusRtu.h.

◆ T35

#define T35   5

Definition at line 56 of file ModbusRtu.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
RESPONSE_SIZE 
EXCEPTION_SIZE 
CHECKSUM_SIZE 

Definition at line 79 of file ModbusRtu.h.

80 {
81  RESPONSE_SIZE = 6,
82  EXCEPTION_SIZE = 3,
83  CHECKSUM_SIZE = 2
84 };

◆ anonymous enum

anonymous enum
Enumerator
NO_REPLY 
EXC_FUNC_CODE 
EXC_ADDR_RANGE 
EXC_REGS_QUANT 
EXC_EXECUTE 

Definition at line 126 of file ModbusRtu.h.

127 {
128  NO_REPLY = 255,
129  EXC_FUNC_CODE = 1,
130  EXC_ADDR_RANGE = 2,
131  EXC_REGS_QUANT = 3,
132  EXC_EXECUTE = 4
133 };

◆ COM_STATES

enum COM_STATES
Enumerator
COM_IDLE 
COM_WAITING 

Definition at line 111 of file ModbusRtu.h.

112 {
113  COM_IDLE = 0,
114  COM_WAITING = 1
115 };

◆ ERR_LIST

enum ERR_LIST
Enumerator
ERR_NOT_MASTER 
ERR_POLLING 
ERR_BUFF_OVERFLOW 
ERR_BAD_CRC 
ERR_EXCEPTION 

Definition at line 117 of file ModbusRtu.h.

118 {
119  ERR_NOT_MASTER = -1,
120  ERR_POLLING = -2,
121  ERR_BUFF_OVERFLOW = -3,
122  ERR_BAD_CRC = -4,
123  ERR_EXCEPTION = -5
124 };

◆ MESSAGE

enum MESSAGE

Indexes to telegram frame positions.

Enumerator
ID 

ID field.

FUNC 

Function code position.

ADD_HI 

Address high byte.

ADD_LO 

Address low byte.

NB_HI 

Number of coils or registers high byte.

NB_LO 

Number of coils or registers low byte.

BYTE_CNT 

byte counter

Definition at line 91 of file ModbusRtu.h.

92 {
93  ID = 0,
94  FUNC,
95  ADD_HI,
96  ADD_LO,
97  NB_HI,
98  NB_LO,
99  BYTE_CNT
100 };

Variable Documentation

◆ fctsupported

const unsigned char fctsupported[]
Initial value:
=
{
MB_FC_READ_COILS,
MB_FC_READ_DISCRETE_INPUT,
MB_FC_READ_REGISTERS,
MB_FC_READ_INPUT_REGISTER,
MB_FC_WRITE_COIL,
MB_FC_WRITE_REGISTER,
MB_FC_WRITE_MULTIPLE_COILS,
MB_FC_WRITE_MULTIPLE_REGISTERS}

Definition at line 135 of file ModbusRtu.h.

EXC_ADDR_RANGE
@ EXC_ADDR_RANGE
Definition: ModbusRtu.h:130
EXC_REGS_QUANT
@ EXC_REGS_QUANT
Definition: ModbusRtu.h:131
COM_IDLE
@ COM_IDLE
Definition: ModbusRtu.h:113
EXC_FUNC_CODE
@ EXC_FUNC_CODE
Definition: ModbusRtu.h:129
NB_HI
@ NB_HI
Number of coils or registers high byte.
Definition: ModbusRtu.h:97
ERR_BAD_CRC
@ ERR_BAD_CRC
Definition: ModbusRtu.h:122
COM_WAITING
@ COM_WAITING
Definition: ModbusRtu.h:114
ERR_NOT_MASTER
@ ERR_NOT_MASTER
Definition: ModbusRtu.h:119
CHECKSUM_SIZE
@ CHECKSUM_SIZE
Definition: ModbusRtu.h:83
ERR_BUFF_OVERFLOW
@ ERR_BUFF_OVERFLOW
Definition: ModbusRtu.h:121
EXC_EXECUTE
@ EXC_EXECUTE
Definition: ModbusRtu.h:132
EXCEPTION_SIZE
@ EXCEPTION_SIZE
Definition: ModbusRtu.h:82
ERR_EXCEPTION
@ ERR_EXCEPTION
Definition: ModbusRtu.h:123
RESPONSE_SIZE
@ RESPONSE_SIZE
Definition: ModbusRtu.h:81
FUNC
@ FUNC
Function code position.
Definition: ModbusRtu.h:94
NO_REPLY
@ NO_REPLY
Definition: ModbusRtu.h:128
ADD_HI
@ ADD_HI
Address high byte.
Definition: ModbusRtu.h:95
ID
@ ID
ID field.
Definition: ModbusRtu.h:93
ERR_POLLING
@ ERR_POLLING
Definition: ModbusRtu.h:120
BYTE_CNT
@ BYTE_CNT
byte counter
Definition: ModbusRtu.h:99
ADD_LO
@ ADD_LO
Address low byte.
Definition: ModbusRtu.h:96
NB_LO
@ NB_LO
Number of coils or registers low byte.
Definition: ModbusRtu.h:98