├── .gitattributes ├── .gitignore ├── ESP8266ModbusRTUSlave_example └── ESP8266ModbusRTUSlave.ino ├── Modbus ├── Doxyfile ├── LICENSE.md ├── MODBUS library 0.01b.txt ├── MODIFICVADA │ └── ModbusRtu.h ├── README.md ├── config ├── documentation │ ├── html │ │ ├── _modbus_rtu_8h.html │ │ ├── _modbus_rtu_8h_source.html │ │ ├── annotated.html │ │ ├── bc_s.png │ │ ├── bdwn.png │ │ ├── class_modbus-members.html │ │ ├── class_modbus.html │ │ ├── classes.html │ │ ├── closed.png │ │ ├── doxygen.css │ │ ├── doxygen.png │ │ ├── dynsections.js │ │ ├── files.html │ │ ├── ftv2blank.png │ │ ├── ftv2cl.png │ │ ├── ftv2doc.png │ │ ├── ftv2folderclosed.png │ │ ├── ftv2folderopen.png │ │ ├── ftv2lastnode.png │ │ ├── ftv2link.png │ │ ├── ftv2mlastnode.png │ │ ├── ftv2mnode.png │ │ ├── ftv2mo.png │ │ ├── ftv2node.png │ │ ├── ftv2ns.png │ │ ├── ftv2plastnode.png │ │ ├── ftv2pnode.png │ │ ├── ftv2splitbar.png │ │ ├── ftv2vertline.png │ │ ├── functions.html │ │ ├── functions_func.html │ │ ├── functions_vars.html │ │ ├── globals.html │ │ ├── globals_defs.html │ │ ├── globals_enum.html │ │ ├── globals_eval.html │ │ ├── globals_vars.html │ │ ├── group__buffer.html │ │ ├── group__discrete.html │ │ ├── group__loop.html │ │ ├── group__register.html │ │ ├── group__setup.html │ │ ├── index.hhc │ │ ├── index.hhk │ │ ├── index.hhp │ │ ├── index.html │ │ ├── modules.html │ │ ├── nav_f.png │ │ ├── nav_g.png │ │ ├── nav_h.png │ │ ├── open.png │ │ ├── pages.html │ │ ├── structmodbus__t-members.html │ │ ├── structmodbus__t.html │ │ ├── sync_off.png │ │ ├── sync_on.png │ │ ├── tab_a.png │ │ ├── tab_b.png │ │ ├── tab_h.png │ │ ├── tab_s.png │ │ ├── tabs.css │ │ └── todo.html │ ├── latex │ │ ├── Makefile │ │ ├── _modbus_rtu_8h.tex │ │ ├── annotated.tex │ │ ├── class_modbus.tex │ │ ├── doxygen.sty │ │ ├── files.tex │ │ ├── group__buffer.tex │ │ ├── group__discrete.tex │ │ ├── group__loop.tex │ │ ├── group__register.tex │ │ ├── group__setup.tex │ │ ├── modules.tex │ │ ├── refman.tex │ │ ├── structmodbus__t.tex │ │ └── todo.tex │ └── rtf │ │ └── refman.rtf ├── examples │ ├── MODBUSslave │ │ └── MODBUSslave.pde │ ├── RS485_slave │ │ └── RS485_slave.ino │ ├── advanced_master │ │ └── advanced_master.ino │ ├── advanced_slave │ │ └── advanced_slave.ino │ ├── simple_master │ │ └── simple_master.ino │ └── simple_slave │ │ └── simple_slave.ino ├── keywords.txt ├── modbus.h ├── modbusDevice.cpp ├── modbusDevice.h ├── modbusRegBank.cpp ├── modbusRegBank.h ├── modbusSlave.cpp └── modbusSlave.h └── SoftwareSerial ├── SoftwareSerial.cpp ├── SoftwareSerial.h ├── examples ├── SoftwareSerialExample │ └── SoftwareSerialExample.ino ├── TwoPortReceive │ └── TwoPortReceive.ino └── swsertest │ └── swsertest.ino └── keywords.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /ESP8266ModbusRTUSlave_example/ESP8266ModbusRTUSlave.ino: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/ESP8266ModbusRTUSlave_example/ESP8266ModbusRTUSlave.ino -------------------------------------------------------------------------------- /Modbus/MODBUS library 0.01b.txt: -------------------------------------------------------------------------------- 1 | Beta 2 | Written by Jason Vreeland [CodeRage] 3 | Released 3/7/2010 under GNU license -------------------------------------------------------------------------------- /Modbus/README.md: -------------------------------------------------------------------------------- 1 | README.txt 2 | 3 | libmodbus is a library that provides a Serial Modbus implementation for Arduino. 4 | 5 | A primary goal was to enable industrial communication for the Arduino in order to link it to industrial devices such as HMIs, CNCs, PLCs, temperature regulators or speed drives. 6 | 7 | LIBRARY CONTENTS 8 | ================================================================= 9 | LICENSE.txt GNU Licence file 10 | keywords.txt Arduino IDE colouring syntax 11 | 12 | /documentation 13 | Library documentation generated with Doxygen. 14 | 15 | /examples 16 | Sample sketches to implement miscellaneous settings: 17 | 18 | /examples/advanced_slave Modbus slave node, which links Arduino pins to the Modbus port. 19 | /examples/RS485_slave Modbus slave adapted to the RS485 port 20 | /examples/simple_master Modbus master node with a single query 21 | /examples/simple_slave Modbus slave node with a link array 22 | 23 | INSTALLATION PROCEDURE 24 | ================================================================= 25 | Refer to this documentation to Install this library: 26 | 27 | http://arduino.cc/en/Guide/Libraries 28 | 29 | Starting with version 1.0.5, you can install 3rd party libraries in the IDE. 30 | 31 | Do not unzip the downloaded library, leave it as is. 32 | 33 | In the Arduino IDE, navigate to Sketch > Import Library. At the top of the drop down list, select the option to "Add Library". 34 | 35 | You will be prompted to select this zipped library. 36 | 37 | Return to the Sketch > Import Library menu. You should now see the library at the bottom of the drop-down menu. It is ready to be used in your sketch. 38 | 39 | The zip file will have been expanded in the libraries folder in your Arduino sketches directory. 40 | 41 | NB : the library will be available to use in sketches, but examples for the library will not be exposed in the File > Examples until after the IDE has restarted. 42 | 43 | 44 | KNOWN ISSUES 45 | ================================================================= 46 | It is not compatible with ARDUINO LEONARDO and not tested under ARDUINO DUE and newer boards. 47 | 48 | TODO List 49 | ================================================================= 50 | Common to Master and Slave: 51 | 52 | 1) Implement other Serial settings: parity, stop bits, ... 53 | 54 | 2) End frame delay, also known as T35 55 | 56 | 3) Test it with several Arduino boards: UNO, Mega, etc.. 57 | 58 | 4) Extend it to Leonardo 59 | 60 | Master: 61 | 62 | 1) Function code 1 and 2 still not implemented 63 | 64 | 2) Function code 15 still not implement 65 | 66 | 3) Other codes under development 67 | 68 | -------------------------------------------------------------------------------- /Modbus/documentation/html/annotated.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
![]() ![]() | Arduino class library for communicating with Modbus devices over USB/RS232/485 (via RTU protocol) |
![]() ![]() | 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 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
This is the complete list of members for Modbus, including all inherited members.
55 |begin(long u32speed) | Modbus | |
begin() | Modbus | |
end() | Modbus | |
getErrCnt() | Modbus | |
getID() | Modbus | |
getInCnt() | Modbus | |
getLastError() | Modbus | |
getOutCnt() | Modbus | |
getState() | Modbus | |
getTimeOut() | Modbus | |
getTimeOutState() | Modbus | |
Modbus() | Modbus | |
Modbus(uint8_t u8id, uint8_t u8serno) | Modbus | |
Modbus(uint8_t u8id, uint8_t u8serno, uint8_t u8txenpin) | Modbus | |
poll() | Modbus | |
poll(uint16_t *regs, uint8_t u8size) | Modbus | |
query(modbus_t telegram) | Modbus | |
setID(uint8_t u8id) | Modbus | |
setTimeOut(uint16_t u16timeout) | Modbus |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
![]() ![]() |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
50 | Functions | |
uint16_t | Modbus::getInCnt () |
number of incoming messages More... | |
uint16_t | Modbus::getOutCnt () |
number of outcoming messages More... | |
uint16_t | Modbus::getErrCnt () |
error counter More... | |
uint8_t | Modbus::getState () |
uint8_t | Modbus::getLastError () |
get last error message More... | |
uint16_t Modbus::getErrCnt | 74 |( | 75 |) | 76 | | 77 | |
error counter
82 |Get errors counter value This can be useful to diagnose communication.
83 |Definition at line 386 of file ModbusRtu.h.
86 | 87 |uint16_t Modbus::getInCnt | 95 |( | 96 |) | 97 | | 98 | |
number of incoming messages
103 |Get input messages counter value This can be useful to diagnose communication.
104 |Definition at line 362 of file ModbusRtu.h.
107 | 108 |uint8_t Modbus::getLastError | 116 |( | 117 |) | 118 | | 119 | |
get last error message
124 |Get the last error in the protocol processor
125 |NO_REPLY = 255 Time-out
126 |Definition at line 409 of file ModbusRtu.h.
133 | 134 |uint16_t Modbus::getOutCnt | 142 |( | 143 |) | 144 | | 145 | |
number of outcoming messages
150 |Get transmitted messages counter value This can be useful to diagnose communication.
151 |Definition at line 374 of file ModbusRtu.h.
154 | 155 |uint8_t Modbus::getState | 163 |( | 164 |) | 165 | | 166 | |
Get modbus master state
170 |Definition at line 396 of file ModbusRtu.h.
173 | 174 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
50 | Functions | |
boolean | Modbus::getTimeOutState () |
get communication watch-dog timer state More... | |
int8_t | Modbus::query (modbus_t telegram) |
only for master More... | |
int8_t | Modbus::poll () |
cyclic poll for master More... | |
int8_t | Modbus::poll (uint16_t *regs, uint8_t u8size) |
cyclic poll for slave More... | |
boolean Modbus::getTimeOutState | 72 |( | 73 |) | 74 | | 75 | |
get communication watch-dog timer state
80 |Return communication Watchdog state. It could be usefull to reset outputs if the watchdog is fired.
81 |Definition at line 350 of file ModbusRtu.h.
84 | 85 |int8_t Modbus::poll | 93 |( | 94 |) | 95 | | 96 | |
cyclic poll for master
101 |*** Only for Modbus Master *** This method checks if there is any incoming answer if pending. If there is no answer, it would change Master state to COM_IDLE. This method must be called only at loop section. Avoid any delay() function.
102 |Any incoming data would be redirected to au16regs pointer, as defined in its modbus_t query telegram.
103 |nothing
104 |Definition at line 513 of file ModbusRtu.h.
107 | 108 |int8_t Modbus::poll | 116 |( | 117 |uint16_t * | 118 |regs, | 119 |
122 | | 123 | | uint8_t | 124 |u8size | 125 |
128 | | ) | 129 |130 | |
cyclic poll for slave
135 |*** Only for Modbus Slave *** This method checks if there is any incoming query Afterwards, it would shoot a validation routine plus a register query Avoid any delay() function !!!! After a successful frame between the Master and the Slave, the time-out timer is reset.
136 |*regs | register table for communication exchange |
u8size | size of the register table |
Definition at line 588 of file ModbusRtu.h.
146 | 147 |int8_t Modbus::query | 155 |( | 156 |modbus_t | 157 |telegram) | 158 | | 159 | |
only for master
164 |*** Only Modbus Master *** Generate a query to an slave with a modbus_t telegram structure The Master must be in COM_IDLE mode. After it, its state would be COM_WAITING. This method has to be called only in loop() section.
165 |modbus_t | modbus telegram structure (id, fct, ...) |
Definition at line 425 of file ModbusRtu.h.
175 | 176 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
50 | Functions | |
Modbus::Modbus () | |
Default Constructor for Master through Serial. More... | |
void | Modbus::begin (long u32speed) |
Initialize class object. More... | |
void | Modbus::setID (uint8_t u8id) |
write new ID for the slave More... | |
uint8_t | Modbus::getID () |
get slave ID between 1 and 247 More... | |
void | Modbus::setTimeOut (uint16_t u16timeout) |
write communication watch-dog timer More... | |
void Modbus::begin | 75 |( | 76 |long | 77 |u32speed) | 78 | | 79 | |
Initialize class object.
84 |Sets up the serial port using specified baud rate. Call once class has been instantiated, typically within setup().
85 | 86 |speed | baud rate, in standard increments (300..115200) |
config | data frame settings (data length, parity and stop bits) |
Definition at line 250 of file ModbusRtu.h.
95 | 96 |uint8_t Modbus::getID | 104 |( | 105 |) | 106 | | 107 | |
get slave ID between 1 and 247
112 |Method to read current slave ID address.
113 |Definition at line 323 of file ModbusRtu.h.
116 | 117 |Modbus::Modbus | 125 |( | 126 |) | 127 | | 128 | |
Default Constructor for Master through Serial.
133 | 134 |Definition at line 204 of file ModbusRtu.h.
135 | 136 |void Modbus::setID | 144 |( | 145 |uint8_t | 146 |u8id) | 147 | | 148 | |
write new ID for the slave
153 |Method to write a new slave ID address.
154 |u8id | new slave address between 1 and 247 |
Definition at line 310 of file ModbusRtu.h.
162 | 163 |void Modbus::setTimeOut | 171 |( | 172 |uint16_t | 173 |u16timeOut) | 174 | | 175 | |
write communication watch-dog timer
180 |Initialize time-out parameter.
181 |Call once class has been instantiated, typically within setup(). The time-out timer is reset each time that there is a successful communication between Master and Slave. It works for both.
182 |time-out | value (ms) |
Definition at line 338 of file ModbusRtu.h.
190 | 191 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
![]() |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
This is the complete list of members for modbus_t, including all inherited members.
55 |au16reg | modbus_t | |
u16CoilsNo | modbus_t | |
u16RegAdd | modbus_t | |
u8fct | modbus_t | |
u8id | modbus_t |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |
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. 58 | More...
59 | 60 |#include <ModbusRtu.h>
63 | Public Attributes | |
uint8_t | u8id |
uint8_t | u8fct |
uint16_t | u16RegAdd |
uint16_t | u16CoilsNo |
uint16_t * | au16reg |
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.
77 | 78 |Definition at line 48 of file ModbusRtu.h.
79 |uint16_t* modbus_t::au16reg | 86 |
Pointer to memory image in master
90 | 91 |Definition at line 53 of file ModbusRtu.h.
92 | 93 |uint16_t modbus_t::u16CoilsNo | 101 |
Number of coils or registers to access
105 | 106 |Definition at line 52 of file ModbusRtu.h.
107 | 108 |uint16_t modbus_t::u16RegAdd | 116 |
Address of the first register to access at slave/s
120 | 121 |Definition at line 51 of file ModbusRtu.h.
122 | 123 |uint8_t modbus_t::u8fct | 131 |
Function code: 1, 2, 3, 4, 5, 6, 15 or 16
135 | 136 |Definition at line 50 of file ModbusRtu.h.
137 | 138 |uint8_t modbus_t::u8id | 146 |
Slave address between 1 and 247. 0 means broadcast
150 | 151 |Definition at line 49 of file ModbusRtu.h.
152 | 153 |
20 | Modbus Master and Slave for Arduino
21 | 1.2
22 |
23 | Arduino library for implementing a Modbus Master or Slave through Serial port
24 | |
25 |