├── .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 | Modbus Master and Slave for Arduino: Class List 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 | 47 |
48 |
49 |
50 |
Class List
51 |
52 |
53 |
Here are the classes, structs, unions and interfaces with brief descriptions:
54 | 55 | 56 | 57 |
oCModbusArduino class library for communicating with Modbus devices over USB/RS232/485 (via RTU protocol)
\Cmodbus_tMaster 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 |
59 |
60 | 61 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /Modbus/documentation/html/bc_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/bc_s.png -------------------------------------------------------------------------------- /Modbus/documentation/html/bdwn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/bdwn.png -------------------------------------------------------------------------------- /Modbus/documentation/html/class_modbus-members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: Member List 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 | 47 |
48 |
49 |
50 |
Modbus Member List
51 |
52 |
53 | 54 |

This is the complete list of members for Modbus, including all inherited members.

55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |
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
76 | 77 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /Modbus/documentation/html/classes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: Class Index 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 | 47 |
48 |
49 |
50 |
Class Index
51 |
52 |
53 |
M
54 | 55 | 57 | 58 | 59 | 60 |
  M  
56 |
modbus_t   
Modbus   
61 |
M
62 |
63 | 64 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /Modbus/documentation/html/closed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/closed.png -------------------------------------------------------------------------------- /Modbus/documentation/html/doxygen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/doxygen.png -------------------------------------------------------------------------------- /Modbus/documentation/html/dynsections.js: -------------------------------------------------------------------------------- 1 | function toggleVisibility(linkObj) 2 | { 3 | var base = $(linkObj).attr('id'); 4 | var summary = $('#'+base+'-summary'); 5 | var content = $('#'+base+'-content'); 6 | var trigger = $('#'+base+'-trigger'); 7 | var src=$(trigger).attr('src'); 8 | if (content.is(':visible')===true) { 9 | content.hide(); 10 | summary.show(); 11 | $(linkObj).addClass('closed').removeClass('opened'); 12 | $(trigger).attr('src',src.substring(0,src.length-8)+'closed.png'); 13 | } else { 14 | content.show(); 15 | summary.hide(); 16 | $(linkObj).removeClass('closed').addClass('opened'); 17 | $(trigger).attr('src',src.substring(0,src.length-10)+'open.png'); 18 | } 19 | return false; 20 | } 21 | 22 | function updateStripes() 23 | { 24 | $('table.directory tr'). 25 | removeClass('even').filter(':visible:even').addClass('even'); 26 | } 27 | function toggleLevel(level) 28 | { 29 | $('table.directory tr').each(function(){ 30 | var l = this.id.split('_').length-1; 31 | var i = $('#img'+this.id.substring(3)); 32 | var a = $('#arr'+this.id.substring(3)); 33 | if (l 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: File List 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 | 46 |
47 |
48 |
49 |
File List
50 |
51 |
52 |
Here is a list of all files with brief descriptions:
53 | 54 | 55 |
\*ModbusRtu.h
56 |
57 |
58 | 59 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2blank.png -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2cl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2cl.png -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2doc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2doc.png -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2folderclosed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2folderclosed.png -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2folderopen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2folderopen.png -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2lastnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2lastnode.png -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2link.png -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2mlastnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2mlastnode.png -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2mnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2mnode.png -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2mo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2mo.png -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2node.png -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2ns.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2ns.png -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2plastnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2plastnode.png -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2pnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2pnode.png -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2splitbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2splitbar.png -------------------------------------------------------------------------------- /Modbus/documentation/html/ftv2vertline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/ftv2vertline.png -------------------------------------------------------------------------------- /Modbus/documentation/html/functions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: Class Members 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 | 47 | 54 |
55 |
56 |
Here is a list of all class members with links to the classes they belong to:
118 |
119 | 120 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /Modbus/documentation/html/functions_func.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: Class Members - Functions 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 | 47 | 54 |
55 |
56 |   103 |
104 | 105 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /Modbus/documentation/html/functions_vars.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: Class Members - Variables 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 | 47 | 54 |
55 |
56 |   73 |
74 | 75 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /Modbus/documentation/html/globals.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: File Members 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 | 46 | 55 | 69 |
70 |
71 |
Here is a list of all file members with links to the files they belong to:
72 | 73 |

- a -

81 | 82 | 83 |

- b -

88 | 89 | 90 |

- c -

104 | 105 | 106 |

- e -

141 | 142 | 143 |

- f -

151 | 152 | 153 |

- i -

158 | 159 | 160 |

- m -

198 | 199 | 200 |

- n -

211 | 212 | 213 |

- r -

218 | 219 | 220 |

- t -

225 |
226 | 227 | 232 | 233 | 234 | -------------------------------------------------------------------------------- /Modbus/documentation/html/globals_defs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: File Members 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 | 46 | 55 |
56 |
57 |   65 |
66 | 67 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /Modbus/documentation/html/globals_enum.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: File Members 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 | 46 | 55 |
56 |
57 |   71 |
72 | 73 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /Modbus/documentation/html/globals_eval.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: File Members 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 | 46 | 55 | 68 |
69 |
70 |   71 | 72 |

- a -

80 | 81 | 82 |

- b -

87 | 88 | 89 |

- c -

100 | 101 | 102 |

- e -

134 | 135 | 136 |

- f -

141 | 142 | 143 |

- i -

148 | 149 | 150 |

- m -

179 | 180 | 181 |

- n -

192 | 193 | 194 |

- r -

199 |
200 | 201 | 206 | 207 | 208 | -------------------------------------------------------------------------------- /Modbus/documentation/html/globals_vars.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: File Members 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 | 46 | 55 |
56 |
57 |   62 |
63 | 64 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /Modbus/documentation/html/group__buffer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: Modbus Buffer Management 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 |
41 |
42 |
43 | Functions
44 |
45 |
Modbus Buffer Management
46 |
47 |
48 | 49 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |

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...
 
66 |

Detailed Description

67 |

Function Documentation

68 | 69 |
70 |
71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 |
uint16_t Modbus::getErrCnt ()
79 |
80 | 81 |

error counter

82 |

Get errors counter value This can be useful to diagnose communication.

83 |
Returns
errors counter
84 | 85 |

Definition at line 386 of file ModbusRtu.h.

86 | 87 |
88 |
89 | 90 |
91 |
92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 |
uint16_t Modbus::getInCnt ()
100 |
101 | 102 |

number of incoming messages

103 |

Get input messages counter value This can be useful to diagnose communication.

104 |
Returns
input messages counter
105 | 106 |

Definition at line 362 of file ModbusRtu.h.

107 | 108 |
109 |
110 | 111 |
112 |
113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 |
uint8_t Modbus::getLastError ()
121 |
122 | 123 |

get last error message

124 |

Get the last error in the protocol processor

125 |

NO_REPLY = 255 Time-out

126 |
Returns
EXC_FUNC_CODE = 1 Function code not available
127 |
128 | EXC_ADDR_RANGE = 2 Address beyond available space for Modbus registers
129 |
130 | EXC_REGS_QUANT = 3 Coils or registers number beyond the available space
131 | 132 |

Definition at line 409 of file ModbusRtu.h.

133 | 134 |
135 |
136 | 137 |
138 |
139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 |
uint16_t Modbus::getOutCnt ()
147 |
148 | 149 |

number of outcoming messages

150 |

Get transmitted messages counter value This can be useful to diagnose communication.

151 |
Returns
transmitted messages counter
152 | 153 |

Definition at line 374 of file ModbusRtu.h.

154 | 155 |
156 |
157 | 158 |
159 |
160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 |
uint8_t Modbus::getState ()
168 |
169 |

Get modbus master state

170 |
Returns
= 0 IDLE, = 1 WAITING FOR ANSWER
171 | 172 |

Definition at line 396 of file ModbusRtu.h.

173 | 174 |
175 |
176 |
177 | 178 | 183 | 184 | 185 | -------------------------------------------------------------------------------- /Modbus/documentation/html/group__discrete.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: Modbus Function Codes for Discrete Coils/Inputs 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 |
41 |
42 |
43 |
Modbus Function Codes for Discrete Coils/Inputs
44 |
45 |
46 |

Detailed Description

47 |
48 | 49 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Modbus/documentation/html/group__loop.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: Modbus Object Management 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 |
41 |
42 |
43 | Functions
44 |
45 |
Modbus Object Management
46 |
47 |
48 | 49 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |

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...
 
64 |

Detailed Description

65 |

Function Documentation

66 | 67 |
68 |
69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 |
boolean Modbus::getTimeOutState ()
77 |
78 | 79 |

get communication watch-dog timer state

80 |

Return communication Watchdog state. It could be usefull to reset outputs if the watchdog is fired.

81 |
Returns
TRUE if millis() > u32timeOut
82 | 83 |

Definition at line 350 of file ModbusRtu.h.

84 | 85 |
86 |
87 | 88 |
89 |
90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 |
int8_t Modbus::poll ()
98 |
99 | 100 |

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 |
Returns
errors counter
105 | 106 |

Definition at line 513 of file ModbusRtu.h.

107 | 108 |
109 |
110 | 111 |
112 |
113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 |
int8_t Modbus::poll (uint16_t * regs,
uint8_t u8size 
)
132 |
133 | 134 |

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 |
Parameters
137 | 138 | 139 | 140 |
*regsregister table for communication exchange
u8sizesize of the register table
141 |
142 |
143 |
Returns
0 if no query, 1..4 if communication error, >4 if correct query processed
144 | 145 |

Definition at line 588 of file ModbusRtu.h.

146 | 147 |
148 |
149 | 150 |
151 |
152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 |
int8_t Modbus::query (modbus_t telegram)
161 |
162 | 163 |

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 |
See Also
modbus_t
166 |
Parameters
167 | 168 | 169 |
modbus_tmodbus telegram structure (id, fct, ...)
170 |
171 |
172 |
Todo:
finish function 15
173 | 174 |

Definition at line 425 of file ModbusRtu.h.

175 | 176 |
177 |
178 |
179 | 180 | 185 | 186 | 187 | -------------------------------------------------------------------------------- /Modbus/documentation/html/group__register.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: Modbus Function Codes for Holding/Input Registers 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 |
41 |
42 |
43 |
Modbus Function Codes for Holding/Input Registers
44 |
45 |
46 |

Detailed Description

47 |
48 | 49 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Modbus/documentation/html/group__setup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: Modbus Object Instantiation/Initialization 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 |
41 |
42 |
43 | Functions
44 |
45 |
Modbus Object Instantiation/Initialization
46 |
47 |
48 | 49 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |

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...
 
67 |

Detailed Description

68 |

Function Documentation

69 | 70 |
71 |
72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 |
void Modbus::begin (long u32speed)
81 |
82 | 83 |

Initialize class object.

84 |

Sets up the serial port using specified baud rate. Call once class has been instantiated, typically within setup().

85 |
See Also
http://arduino.cc/en/Serial/Begin#.Uy4CJ6aKlHY
86 |
Parameters
87 | 88 | 89 | 90 |
speedbaud rate, in standard increments (300..115200)
configdata frame settings (data length, parity and stop bits)
91 |
92 |
93 | 94 |

Definition at line 250 of file ModbusRtu.h.

95 | 96 |
97 |
98 | 99 |
100 |
101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 |
uint8_t Modbus::getID ()
109 |
110 | 111 |

get slave ID between 1 and 247

112 |

Method to read current slave ID address.

113 |
Returns
u8id current slave address between 1 and 247
114 | 115 |

Definition at line 323 of file ModbusRtu.h.

116 | 117 |
118 |
119 | 120 |
121 |
122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 |
Modbus::Modbus ()
130 |
131 | 132 |

Default Constructor for Master through Serial.

133 | 134 |

Definition at line 204 of file ModbusRtu.h.

135 | 136 |
137 |
138 | 139 |
140 |
141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 |
void Modbus::setID (uint8_t u8id)
150 |
151 | 152 |

write new ID for the slave

153 |

Method to write a new slave ID address.

154 |
Parameters
155 | 156 | 157 |
u8idnew slave address between 1 and 247
158 |
159 |
160 | 161 |

Definition at line 310 of file ModbusRtu.h.

162 | 163 |
164 |
165 | 166 |
167 |
168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 |
void Modbus::setTimeOut (uint16_t u16timeOut)
177 |
178 | 179 |

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 |
Parameters
183 | 184 | 185 |
time-outvalue (ms)
186 |
187 |
188 | 189 |

Definition at line 338 of file ModbusRtu.h.

190 | 191 |
192 |
193 |
194 | 195 | 200 | 201 | 202 | -------------------------------------------------------------------------------- /Modbus/documentation/html/index.hhp: -------------------------------------------------------------------------------- 1 | [OPTIONS] 2 | Compatibility=1.1 3 | Full-text search=Yes 4 | Contents file=index.hhc 5 | Default Window=main 6 | Default topic=index.html 7 | Index file=index.hhk 8 | Language=0x409 English (United States) 9 | Title=Modbus Master and Slave for Arduino 10 | 11 | [WINDOWS] 12 | main="Modbus Master and Slave for Arduino","index.hhc","index.hhk","index.html","index.html",,,,,0x23520,,0x10387e,,,,,,,,0 13 | 14 | [FILES] 15 | _modbus_rtu_8h_source.html 16 | _modbus_rtu_8h.html 17 | todo.html 18 | group__setup.html 19 | group__loop.html 20 | group__buffer.html 21 | group__discrete.html 22 | group__register.html 23 | class_modbus.html 24 | class_modbus-members.html 25 | structmodbus__t.html 26 | structmodbus__t-members.html 27 | index.html 28 | pages.html 29 | modules.html 30 | annotated.html 31 | classes.html 32 | functions.html 33 | functions_func.html 34 | functions_vars.html 35 | files.html 36 | globals.html 37 | globals_vars.html 38 | globals_enum.html 39 | globals_eval.html 40 | globals_defs.html 41 | tab_a.png 42 | tab_b.png 43 | tab_h.png 44 | tab_s.png 45 | nav_h.png 46 | nav_f.png 47 | bc_s.png 48 | doxygen.png 49 | closed.png 50 | open.png 51 | bdwn.png 52 | sync_on.png 53 | sync_off.png 54 | ftv2blank.png 55 | ftv2doc.png 56 | ftv2folderclosed.png 57 | ftv2folderopen.png 58 | ftv2ns.png 59 | ftv2mo.png 60 | ftv2cl.png 61 | ftv2lastnode.png 62 | ftv2link.png 63 | ftv2mlastnode.png 64 | ftv2mnode.png 65 | ftv2node.png 66 | ftv2plastnode.png 67 | ftv2pnode.png 68 | ftv2vertline.png 69 | ftv2splitbar.png 70 | -------------------------------------------------------------------------------- /Modbus/documentation/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: Main Page 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 |
41 |
42 |
43 |
Modbus Master and Slave for Arduino Documentation
44 |
45 |
46 |
47 | 48 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /Modbus/documentation/html/modules.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: Modules 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 |
41 |
42 |
43 |
Modules
44 |
45 |
46 |
Here is a list of all modules:
55 |
56 | 57 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /Modbus/documentation/html/nav_f.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/nav_f.png -------------------------------------------------------------------------------- /Modbus/documentation/html/nav_g.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/nav_g.png -------------------------------------------------------------------------------- /Modbus/documentation/html/nav_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/nav_h.png -------------------------------------------------------------------------------- /Modbus/documentation/html/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/open.png -------------------------------------------------------------------------------- /Modbus/documentation/html/pages.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: Related Pages 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 |
41 |
42 |
43 |
Related Pages
44 |
45 |
46 |
Here is a list of all related documentation pages:
47 | 48 | 49 |
\Todo List
50 |
51 |
52 | 53 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Modbus/documentation/html/structmodbus__t-members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: Member List 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 | 47 |
48 |
49 |
50 |
modbus_t Member List
51 |
52 |
53 | 54 |

This is the complete list of members for modbus_t, including all inherited members.

55 | 56 | 57 | 58 | 59 | 60 | 61 |
au16regmodbus_t
u16CoilsNomodbus_t
u16RegAddmodbus_t
u8fctmodbus_t
u8idmodbus_t
62 | 63 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /Modbus/documentation/html/structmodbus__t.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: modbus_t Struct Reference 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 | 47 |
48 |
49 | 52 |
53 |
modbus_t Struct Reference
54 |
55 |
56 | 57 |

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>

61 | 62 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 |

63 | Public Attributes

uint8_t u8id
 
uint8_t u8fct
 
uint16_t u16RegAdd
 
uint16_t u16CoilsNo
 
uint16_t * au16reg
 
75 |

Detailed Description

76 |

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 |

Member Data Documentation

80 | 81 |
82 |
83 | 84 | 85 | 86 | 87 |
uint16_t* modbus_t::au16reg
88 |
89 |

Pointer to memory image in master

90 | 91 |

Definition at line 53 of file ModbusRtu.h.

92 | 93 |
94 |
95 | 96 |
97 |
98 | 99 | 100 | 101 | 102 |
uint16_t modbus_t::u16CoilsNo
103 |
104 |

Number of coils or registers to access

105 | 106 |

Definition at line 52 of file ModbusRtu.h.

107 | 108 |
109 |
110 | 111 |
112 |
113 | 114 | 115 | 116 | 117 |
uint16_t modbus_t::u16RegAdd
118 |
119 |

Address of the first register to access at slave/s

120 | 121 |

Definition at line 51 of file ModbusRtu.h.

122 | 123 |
124 |
125 | 126 |
127 |
128 | 129 | 130 | 131 | 132 |
uint8_t modbus_t::u8fct
133 |
134 |

Function code: 1, 2, 3, 4, 5, 6, 15 or 16

135 | 136 |

Definition at line 50 of file ModbusRtu.h.

137 | 138 |
139 |
140 | 141 |
142 |
143 | 144 | 145 | 146 | 147 |
uint8_t modbus_t::u8id
148 |
149 |

Slave address between 1 and 247. 0 means broadcast

150 | 151 |

Definition at line 49 of file ModbusRtu.h.

152 | 153 |
154 |
155 |
The documentation for this struct was generated from the following file: 158 |
159 | 160 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /Modbus/documentation/html/sync_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/sync_off.png -------------------------------------------------------------------------------- /Modbus/documentation/html/sync_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/sync_on.png -------------------------------------------------------------------------------- /Modbus/documentation/html/tab_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/tab_a.png -------------------------------------------------------------------------------- /Modbus/documentation/html/tab_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/tab_b.png -------------------------------------------------------------------------------- /Modbus/documentation/html/tab_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/tab_h.png -------------------------------------------------------------------------------- /Modbus/documentation/html/tab_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/documentation/html/tab_s.png -------------------------------------------------------------------------------- /Modbus/documentation/html/tabs.css: -------------------------------------------------------------------------------- 1 | .tabs, .tabs2, .tabs3 { 2 | background-image: url('tab_b.png'); 3 | width: 100%; 4 | z-index: 101; 5 | font-size: 13px; 6 | font-family: 'Lucida Grande',Geneva,Helvetica,Arial,sans-serif; 7 | } 8 | 9 | .tabs2 { 10 | font-size: 10px; 11 | } 12 | .tabs3 { 13 | font-size: 9px; 14 | } 15 | 16 | .tablist { 17 | margin: 0; 18 | padding: 0; 19 | display: table; 20 | } 21 | 22 | .tablist li { 23 | float: left; 24 | display: table-cell; 25 | background-image: url('tab_b.png'); 26 | line-height: 36px; 27 | list-style: none; 28 | } 29 | 30 | .tablist a { 31 | display: block; 32 | padding: 0 20px; 33 | font-weight: bold; 34 | background-image:url('tab_s.png'); 35 | background-repeat:no-repeat; 36 | background-position:right; 37 | color: #283A5D; 38 | text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.9); 39 | text-decoration: none; 40 | outline: none; 41 | } 42 | 43 | .tabs3 .tablist a { 44 | padding: 0 10px; 45 | } 46 | 47 | .tablist a:hover { 48 | background-image: url('tab_h.png'); 49 | background-repeat:repeat-x; 50 | color: #fff; 51 | text-shadow: 0px 1px 1px rgba(0, 0, 0, 1.0); 52 | text-decoration: none; 53 | } 54 | 55 | .tablist li.current a { 56 | background-image: url('tab_a.png'); 57 | background-repeat:repeat-x; 58 | color: #fff; 59 | text-shadow: 0px 1px 1px rgba(0, 0, 0, 1.0); 60 | } 61 | -------------------------------------------------------------------------------- /Modbus/documentation/html/todo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Modbus Master and Slave for Arduino: Todo List 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | 17 | 18 | 19 | 25 | 26 | 27 |
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 |
28 |
29 | 30 | 31 | 40 |
41 |
42 |
43 |
Todo List
44 |
45 |
46 |
47 |
Member Modbus::query (modbus_t telegram)
48 |
finish function 15
49 |
50 |
51 | 52 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Modbus/documentation/latex/Makefile: -------------------------------------------------------------------------------- 1 | all: refman.pdf 2 | 3 | pdf: refman.pdf 4 | 5 | refman.pdf: clean refman.tex 6 | pdflatex refman 7 | makeindex refman.idx 8 | pdflatex refman 9 | latex_count=5 ; \ 10 | while egrep -s 'Rerun (LaTeX|to get cross-references right)' refman.log && [ $$latex_count -gt 0 ] ;\ 11 | do \ 12 | echo "Rerunning latex...." ;\ 13 | pdflatex refman ;\ 14 | latex_count=`expr $$latex_count - 1` ;\ 15 | done 16 | makeindex refman.idx 17 | pdflatex refman 18 | 19 | 20 | clean: 21 | rm -f *.ps *.dvi *.aux *.toc *.idx *.ind *.ilg *.log *.out *.brf *.blg *.bbl refman.pdf 22 | -------------------------------------------------------------------------------- /Modbus/documentation/latex/annotated.tex: -------------------------------------------------------------------------------- 1 | \section{Class List} 2 | Here are the classes, structs, unions and interfaces with brief descriptions\-:\begin{DoxyCompactList} 3 | \item\contentsline{section}{\hyperlink{class_modbus}{Modbus} \\*Arduino class library for communicating with \hyperlink{class_modbus}{Modbus} devices over U\-S\-B/\-R\-S232/485 (via R\-T\-U protocol) }{\pageref{class_modbus}}{} 4 | \item\contentsline{section}{\hyperlink{structmodbus__t}{modbus\-\_\-t} \\*Master query structure\-: This includes all the necessary fields to make the Master generate a \hyperlink{class_modbus}{Modbus} query. A Master may keep several of these structures and send them cyclically or use them according to program needs }{\pageref{structmodbus__t}}{} 5 | \end{DoxyCompactList} 6 | -------------------------------------------------------------------------------- /Modbus/documentation/latex/class_modbus.tex: -------------------------------------------------------------------------------- 1 | \hypertarget{class_modbus}{\section{Modbus Class Reference} 2 | \label{class_modbus}\index{Modbus@{Modbus}} 3 | } 4 | 5 | 6 | Arduino class library for communicating with \hyperlink{class_modbus}{Modbus} devices over U\-S\-B/\-R\-S232/485 (via R\-T\-U protocol). 7 | 8 | 9 | 10 | 11 | {\ttfamily \#include $<$Modbus\-Rtu.\-h$>$} 12 | 13 | \subsection*{Public Member Functions} 14 | \begin{DoxyCompactItemize} 15 | \item 16 | \hyperlink{group__setup_ga101809cdd4734537bab58dc315a840b4}{Modbus} () 17 | \begin{DoxyCompactList}\small\item\em Default Constructor for Master through Serial. \end{DoxyCompactList}\item 18 | \hyperlink{class_modbus_afbbf7c81565d8e1ea1cd5890a96e7507}{Modbus} (uint8\-\_\-t u8id, uint8\-\_\-t u8serno) 19 | \item 20 | \hyperlink{class_modbus_a5e23a7b669d0c2d5be1c0054c7c54dca}{Modbus} (uint8\-\_\-t u8id, uint8\-\_\-t u8serno, uint8\-\_\-t u8txenpin) 21 | \item 22 | void \hyperlink{group__setup_ga475a4fa0fac491307b10c4529ad6d2a0}{begin} (long u32speed) 23 | \begin{DoxyCompactList}\small\item\em Initialize class object. \end{DoxyCompactList}\item 24 | void \hyperlink{class_modbus_a4f9673a3d113c49af69cb87b030ef099}{begin} () 25 | \item 26 | void \hyperlink{group__setup_gaf828190ebe24efb1b3b1957429f3872e}{set\-Time\-Out} (uint16\-\_\-t u16timeout) 27 | \begin{DoxyCompactList}\small\item\em write communication watch-\/dog timer \end{DoxyCompactList}\item 28 | uint16\-\_\-t \hyperlink{class_modbus_ac860024db3117a2ef907d0325b2fb7a1}{get\-Time\-Out} () 29 | \begin{DoxyCompactList}\small\item\em get communication watch-\/dog timer value \end{DoxyCompactList}\item 30 | boolean \hyperlink{group__loop_gaf6dd413191ed8a833022046873e0a063}{get\-Time\-Out\-State} () 31 | \begin{DoxyCompactList}\small\item\em get communication watch-\/dog timer state \end{DoxyCompactList}\item 32 | int8\-\_\-t \hyperlink{group__loop_ga19398cabed57b6d085d014af6c149f54}{query} (\hyperlink{structmodbus__t}{modbus\-\_\-t} telegram) 33 | \begin{DoxyCompactList}\small\item\em only for master \end{DoxyCompactList}\item 34 | int8\-\_\-t \hyperlink{group__loop_ga53bde78490c1cd8e3c070a676bdcfb0d}{poll} () 35 | \begin{DoxyCompactList}\small\item\em cyclic poll for master \end{DoxyCompactList}\item 36 | int8\-\_\-t \hyperlink{group__loop_gab3ef20562fc8cee14fc85f7e276890b5}{poll} (uint16\-\_\-t $\ast$regs, uint8\-\_\-t u8size) 37 | \begin{DoxyCompactList}\small\item\em cyclic poll for slave \end{DoxyCompactList}\item 38 | uint16\-\_\-t \hyperlink{group__buffer_ga4fa6ede8df85b7cc70b1282b9547378a}{get\-In\-Cnt} () 39 | \begin{DoxyCompactList}\small\item\em number of incoming messages \end{DoxyCompactList}\item 40 | uint16\-\_\-t \hyperlink{group__buffer_ga6f831ecaf3678c27dafb663a28bf81f0}{get\-Out\-Cnt} () 41 | \begin{DoxyCompactList}\small\item\em number of outcoming messages \end{DoxyCompactList}\item 42 | uint16\-\_\-t \hyperlink{group__buffer_ga6883c7f3ff12f084ed56d559d4e06ed0}{get\-Err\-Cnt} () 43 | \begin{DoxyCompactList}\small\item\em error counter \end{DoxyCompactList}\item 44 | uint8\-\_\-t \hyperlink{group__setup_ga6449894306ff8cc5d4caff09b1b0d1ce}{get\-I\-D} () 45 | \begin{DoxyCompactList}\small\item\em get slave I\-D between 1 and 247 \end{DoxyCompactList}\item 46 | uint8\-\_\-t \hyperlink{group__buffer_ga2f39717d957a929af488c9120488fcdc}{get\-State} () 47 | \item 48 | uint8\-\_\-t \hyperlink{group__buffer_gace7f726db13adc8feeceab987b719531}{get\-Last\-Error} () 49 | \begin{DoxyCompactList}\small\item\em get last error message \end{DoxyCompactList}\item 50 | void \hyperlink{group__setup_ga9bd497e97ac1777d4f0d4171078d60e0}{set\-I\-D} (uint8\-\_\-t u8id) 51 | \begin{DoxyCompactList}\small\item\em write new I\-D for the slave \end{DoxyCompactList}\item 52 | void \hyperlink{class_modbus_a0d80101b650344c712a085c4bb005c4c}{end} () 53 | \begin{DoxyCompactList}\small\item\em finish any communication and release serial communication port \end{DoxyCompactList}\end{DoxyCompactItemize} 54 | 55 | 56 | \subsection{Detailed Description} 57 | Arduino class library for communicating with \hyperlink{class_modbus}{Modbus} devices over U\-S\-B/\-R\-S232/485 (via R\-T\-U protocol). 58 | 59 | Definition at line 141 of file Modbus\-Rtu.\-h. 60 | 61 | 62 | 63 | \subsection{Constructor \& Destructor Documentation} 64 | \hypertarget{class_modbus_afbbf7c81565d8e1ea1cd5890a96e7507}{\index{Modbus@{Modbus}!Modbus@{Modbus}} 65 | \index{Modbus@{Modbus}!Modbus@{Modbus}} 66 | \subsubsection[{Modbus}]{\setlength{\rightskip}{0pt plus 5cm}Modbus\-::\-Modbus ( 67 | \begin{DoxyParamCaption} 68 | \item[{uint8\-\_\-t}]{u8id, } 69 | \item[{uint8\-\_\-t}]{u8serno} 70 | \end{DoxyParamCaption} 71 | )}}\label{class_modbus_afbbf7c81565d8e1ea1cd5890a96e7507} 72 | 73 | 74 | Definition at line 218 of file Modbus\-Rtu.\-h. 75 | 76 | \hypertarget{class_modbus_a5e23a7b669d0c2d5be1c0054c7c54dca}{\index{Modbus@{Modbus}!Modbus@{Modbus}} 77 | \index{Modbus@{Modbus}!Modbus@{Modbus}} 78 | \subsubsection[{Modbus}]{\setlength{\rightskip}{0pt plus 5cm}Modbus\-::\-Modbus ( 79 | \begin{DoxyParamCaption} 80 | \item[{uint8\-\_\-t}]{u8id, } 81 | \item[{uint8\-\_\-t}]{u8serno, } 82 | \item[{uint8\-\_\-t}]{u8txenpin} 83 | \end{DoxyParamCaption} 84 | )}}\label{class_modbus_a5e23a7b669d0c2d5be1c0054c7c54dca} 85 | 86 | 87 | Definition at line 234 of file Modbus\-Rtu.\-h. 88 | 89 | 90 | 91 | \subsection{Member Function Documentation} 92 | \hypertarget{class_modbus_a4f9673a3d113c49af69cb87b030ef099}{\index{Modbus@{Modbus}!begin@{begin}} 93 | \index{begin@{begin}!Modbus@{Modbus}} 94 | \subsubsection[{begin}]{\setlength{\rightskip}{0pt plus 5cm}void Modbus\-::begin ( 95 | \begin{DoxyParamCaption} 96 | {} 97 | \end{DoxyParamCaption} 98 | )}}\label{class_modbus_a4f9673a3d113c49af69cb87b030ef099} 99 | 100 | 101 | Definition at line 299 of file Modbus\-Rtu.\-h. 102 | 103 | \hypertarget{class_modbus_a0d80101b650344c712a085c4bb005c4c}{\index{Modbus@{Modbus}!end@{end}} 104 | \index{end@{end}!Modbus@{Modbus}} 105 | \subsubsection[{end}]{\setlength{\rightskip}{0pt plus 5cm}void Modbus\-::end ( 106 | \begin{DoxyParamCaption} 107 | {} 108 | \end{DoxyParamCaption} 109 | )}}\label{class_modbus_a0d80101b650344c712a085c4bb005c4c} 110 | 111 | 112 | finish any communication and release serial communication port 113 | 114 | \hypertarget{class_modbus_ac860024db3117a2ef907d0325b2fb7a1}{\index{Modbus@{Modbus}!get\-Time\-Out@{get\-Time\-Out}} 115 | \index{get\-Time\-Out@{get\-Time\-Out}!Modbus@{Modbus}} 116 | \subsubsection[{get\-Time\-Out}]{\setlength{\rightskip}{0pt plus 5cm}uint16\-\_\-t Modbus\-::get\-Time\-Out ( 117 | \begin{DoxyParamCaption} 118 | {} 119 | \end{DoxyParamCaption} 120 | )}}\label{class_modbus_ac860024db3117a2ef907d0325b2fb7a1} 121 | 122 | 123 | get communication watch-\/dog timer value 124 | 125 | 126 | 127 | The documentation for this class was generated from the following file\-:\begin{DoxyCompactItemize} 128 | \item 129 | \hyperlink{_modbus_rtu_8h}{Modbus\-Rtu.\-h}\end{DoxyCompactItemize} 130 | -------------------------------------------------------------------------------- /Modbus/documentation/latex/files.tex: -------------------------------------------------------------------------------- 1 | \section{File List} 2 | Here is a list of all files with brief descriptions\-:\begin{DoxyCompactList} 3 | \item\contentsline{section}{\hyperlink{_modbus_rtu_8h}{Modbus\-Rtu.\-h} }{\pageref{_modbus_rtu_8h}}{} 4 | \end{DoxyCompactList} 5 | -------------------------------------------------------------------------------- /Modbus/documentation/latex/group__buffer.tex: -------------------------------------------------------------------------------- 1 | \hypertarget{group__buffer}{\section{Modbus Buffer Management} 2 | \label{group__buffer}\index{Modbus Buffer Management@{Modbus Buffer Management}} 3 | } 4 | \subsection*{Functions} 5 | \begin{DoxyCompactItemize} 6 | \item 7 | uint16\-\_\-t \hyperlink{group__buffer_ga4fa6ede8df85b7cc70b1282b9547378a}{Modbus\-::get\-In\-Cnt} () 8 | \begin{DoxyCompactList}\small\item\em number of incoming messages \end{DoxyCompactList}\item 9 | uint16\-\_\-t \hyperlink{group__buffer_ga6f831ecaf3678c27dafb663a28bf81f0}{Modbus\-::get\-Out\-Cnt} () 10 | \begin{DoxyCompactList}\small\item\em number of outcoming messages \end{DoxyCompactList}\item 11 | uint16\-\_\-t \hyperlink{group__buffer_ga6883c7f3ff12f084ed56d559d4e06ed0}{Modbus\-::get\-Err\-Cnt} () 12 | \begin{DoxyCompactList}\small\item\em error counter \end{DoxyCompactList}\item 13 | uint8\-\_\-t \hyperlink{group__buffer_ga2f39717d957a929af488c9120488fcdc}{Modbus\-::get\-State} () 14 | \item 15 | uint8\-\_\-t \hyperlink{group__buffer_gace7f726db13adc8feeceab987b719531}{Modbus\-::get\-Last\-Error} () 16 | \begin{DoxyCompactList}\small\item\em get last error message \end{DoxyCompactList}\end{DoxyCompactItemize} 17 | 18 | 19 | \subsection{Detailed Description} 20 | 21 | 22 | \subsection{Function Documentation} 23 | \hypertarget{group__buffer_ga6883c7f3ff12f084ed56d559d4e06ed0}{\index{Modbus Buffer Management@{Modbus Buffer Management}!get\-Err\-Cnt@{get\-Err\-Cnt}} 24 | \index{get\-Err\-Cnt@{get\-Err\-Cnt}!Modbus Buffer Management@{Modbus Buffer Management}} 25 | \subsubsection[{get\-Err\-Cnt}]{\setlength{\rightskip}{0pt plus 5cm}uint16\-\_\-t Modbus\-::get\-Err\-Cnt ( 26 | \begin{DoxyParamCaption} 27 | {} 28 | \end{DoxyParamCaption} 29 | )}}\label{group__buffer_ga6883c7f3ff12f084ed56d559d4e06ed0} 30 | 31 | 32 | error counter 33 | 34 | Get errors counter value This can be useful to diagnose communication. 35 | 36 | \begin{DoxyReturn}{Returns} 37 | errors counter 38 | \end{DoxyReturn} 39 | 40 | 41 | Definition at line 386 of file Modbus\-Rtu.\-h. 42 | 43 | \hypertarget{group__buffer_ga4fa6ede8df85b7cc70b1282b9547378a}{\index{Modbus Buffer Management@{Modbus Buffer Management}!get\-In\-Cnt@{get\-In\-Cnt}} 44 | \index{get\-In\-Cnt@{get\-In\-Cnt}!Modbus Buffer Management@{Modbus Buffer Management}} 45 | \subsubsection[{get\-In\-Cnt}]{\setlength{\rightskip}{0pt plus 5cm}uint16\-\_\-t Modbus\-::get\-In\-Cnt ( 46 | \begin{DoxyParamCaption} 47 | {} 48 | \end{DoxyParamCaption} 49 | )}}\label{group__buffer_ga4fa6ede8df85b7cc70b1282b9547378a} 50 | 51 | 52 | number of incoming messages 53 | 54 | Get input messages counter value This can be useful to diagnose communication. 55 | 56 | \begin{DoxyReturn}{Returns} 57 | input messages counter 58 | \end{DoxyReturn} 59 | 60 | 61 | Definition at line 362 of file Modbus\-Rtu.\-h. 62 | 63 | \hypertarget{group__buffer_gace7f726db13adc8feeceab987b719531}{\index{Modbus Buffer Management@{Modbus Buffer Management}!get\-Last\-Error@{get\-Last\-Error}} 64 | \index{get\-Last\-Error@{get\-Last\-Error}!Modbus Buffer Management@{Modbus Buffer Management}} 65 | \subsubsection[{get\-Last\-Error}]{\setlength{\rightskip}{0pt plus 5cm}uint8\-\_\-t Modbus\-::get\-Last\-Error ( 66 | \begin{DoxyParamCaption} 67 | {} 68 | \end{DoxyParamCaption} 69 | )}}\label{group__buffer_gace7f726db13adc8feeceab987b719531} 70 | 71 | 72 | get last error message 73 | 74 | Get the last error in the protocol processor 75 | 76 | N\-O\-\_\-\-R\-E\-P\-L\-Y = 255 Time-\/out \begin{DoxyReturn}{Returns} 77 | E\-X\-C\-\_\-\-F\-U\-N\-C\-\_\-\-C\-O\-D\-E = 1 Function code not available 78 | 79 | E\-X\-C\-\_\-\-A\-D\-D\-R\-\_\-\-R\-A\-N\-G\-E = 2 Address beyond available space for \hyperlink{class_modbus}{Modbus} registers 80 | 81 | E\-X\-C\-\_\-\-R\-E\-G\-S\-\_\-\-Q\-U\-A\-N\-T = 3 Coils or registers number beyond the available space 82 | \end{DoxyReturn} 83 | 84 | 85 | Definition at line 409 of file Modbus\-Rtu.\-h. 86 | 87 | \hypertarget{group__buffer_ga6f831ecaf3678c27dafb663a28bf81f0}{\index{Modbus Buffer Management@{Modbus Buffer Management}!get\-Out\-Cnt@{get\-Out\-Cnt}} 88 | \index{get\-Out\-Cnt@{get\-Out\-Cnt}!Modbus Buffer Management@{Modbus Buffer Management}} 89 | \subsubsection[{get\-Out\-Cnt}]{\setlength{\rightskip}{0pt plus 5cm}uint16\-\_\-t Modbus\-::get\-Out\-Cnt ( 90 | \begin{DoxyParamCaption} 91 | {} 92 | \end{DoxyParamCaption} 93 | )}}\label{group__buffer_ga6f831ecaf3678c27dafb663a28bf81f0} 94 | 95 | 96 | number of outcoming messages 97 | 98 | Get transmitted messages counter value This can be useful to diagnose communication. 99 | 100 | \begin{DoxyReturn}{Returns} 101 | transmitted messages counter 102 | \end{DoxyReturn} 103 | 104 | 105 | Definition at line 374 of file Modbus\-Rtu.\-h. 106 | 107 | \hypertarget{group__buffer_ga2f39717d957a929af488c9120488fcdc}{\index{Modbus Buffer Management@{Modbus Buffer Management}!get\-State@{get\-State}} 108 | \index{get\-State@{get\-State}!Modbus Buffer Management@{Modbus Buffer Management}} 109 | \subsubsection[{get\-State}]{\setlength{\rightskip}{0pt plus 5cm}uint8\-\_\-t Modbus\-::get\-State ( 110 | \begin{DoxyParamCaption} 111 | {} 112 | \end{DoxyParamCaption} 113 | )}}\label{group__buffer_ga2f39717d957a929af488c9120488fcdc} 114 | Get modbus master state 115 | 116 | \begin{DoxyReturn}{Returns} 117 | = 0 I\-D\-L\-E, = 1 W\-A\-I\-T\-I\-N\-G F\-O\-R A\-N\-S\-W\-E\-R 118 | \end{DoxyReturn} 119 | 120 | 121 | Definition at line 396 of file Modbus\-Rtu.\-h. 122 | 123 | -------------------------------------------------------------------------------- /Modbus/documentation/latex/group__discrete.tex: -------------------------------------------------------------------------------- 1 | \hypertarget{group__discrete}{\section{Modbus Function Codes for Discrete Coils/\-Inputs} 2 | \label{group__discrete}\index{Modbus Function Codes for Discrete Coils/\-Inputs@{Modbus Function Codes for Discrete Coils/\-Inputs}} 3 | } 4 | 5 | 6 | \subsection{Detailed Description} 7 | -------------------------------------------------------------------------------- /Modbus/documentation/latex/group__loop.tex: -------------------------------------------------------------------------------- 1 | \hypertarget{group__loop}{\section{Modbus Object Management} 2 | \label{group__loop}\index{Modbus Object Management@{Modbus Object Management}} 3 | } 4 | \subsection*{Functions} 5 | \begin{DoxyCompactItemize} 6 | \item 7 | boolean \hyperlink{group__loop_gaf6dd413191ed8a833022046873e0a063}{Modbus\-::get\-Time\-Out\-State} () 8 | \begin{DoxyCompactList}\small\item\em get communication watch-\/dog timer state \end{DoxyCompactList}\item 9 | int8\-\_\-t \hyperlink{group__loop_ga19398cabed57b6d085d014af6c149f54}{Modbus\-::query} (\hyperlink{structmodbus__t}{modbus\-\_\-t} telegram) 10 | \begin{DoxyCompactList}\small\item\em only for master \end{DoxyCompactList}\item 11 | int8\-\_\-t \hyperlink{group__loop_ga53bde78490c1cd8e3c070a676bdcfb0d}{Modbus\-::poll} () 12 | \begin{DoxyCompactList}\small\item\em cyclic poll for master \end{DoxyCompactList}\item 13 | int8\-\_\-t \hyperlink{group__loop_gab3ef20562fc8cee14fc85f7e276890b5}{Modbus\-::poll} (uint16\-\_\-t $\ast$regs, uint8\-\_\-t u8size) 14 | \begin{DoxyCompactList}\small\item\em cyclic poll for slave \end{DoxyCompactList}\end{DoxyCompactItemize} 15 | 16 | 17 | \subsection{Detailed Description} 18 | 19 | 20 | \subsection{Function Documentation} 21 | \hypertarget{group__loop_gaf6dd413191ed8a833022046873e0a063}{\index{Modbus Object Management@{Modbus Object Management}!get\-Time\-Out\-State@{get\-Time\-Out\-State}} 22 | \index{get\-Time\-Out\-State@{get\-Time\-Out\-State}!Modbus Object Management@{Modbus Object Management}} 23 | \subsubsection[{get\-Time\-Out\-State}]{\setlength{\rightskip}{0pt plus 5cm}boolean Modbus\-::get\-Time\-Out\-State ( 24 | \begin{DoxyParamCaption} 25 | {} 26 | \end{DoxyParamCaption} 27 | )}}\label{group__loop_gaf6dd413191ed8a833022046873e0a063} 28 | 29 | 30 | get communication watch-\/dog timer state 31 | 32 | Return communication Watchdog state. It could be usefull to reset outputs if the watchdog is fired. 33 | 34 | \begin{DoxyReturn}{Returns} 35 | T\-R\-U\-E if millis() $>$ u32time\-Out 36 | \end{DoxyReturn} 37 | 38 | 39 | Definition at line 350 of file Modbus\-Rtu.\-h. 40 | 41 | \hypertarget{group__loop_ga53bde78490c1cd8e3c070a676bdcfb0d}{\index{Modbus Object Management@{Modbus Object Management}!poll@{poll}} 42 | \index{poll@{poll}!Modbus Object Management@{Modbus Object Management}} 43 | \subsubsection[{poll}]{\setlength{\rightskip}{0pt plus 5cm}int8\-\_\-t Modbus\-::poll ( 44 | \begin{DoxyParamCaption} 45 | {} 46 | \end{DoxyParamCaption} 47 | )}}\label{group__loop_ga53bde78490c1cd8e3c070a676bdcfb0d} 48 | 49 | 50 | cyclic poll for master 51 | 52 | $\ast$$\ast$$\ast$ Only for \hyperlink{class_modbus}{Modbus} Master $\ast$$\ast$$\ast$ This method checks if there is any incoming answer if pending. If there is no answer, it would change Master state to C\-O\-M\-\_\-\-I\-D\-L\-E. This method must be called only at loop section. Avoid any delay() function. 53 | 54 | Any incoming data would be redirected to au16regs pointer, as defined in its \hyperlink{structmodbus__t}{modbus\-\_\-t} query telegram. 55 | 56 | nothing \begin{DoxyReturn}{Returns} 57 | errors counter 58 | \end{DoxyReturn} 59 | 60 | 61 | Definition at line 513 of file Modbus\-Rtu.\-h. 62 | 63 | \hypertarget{group__loop_gab3ef20562fc8cee14fc85f7e276890b5}{\index{Modbus Object Management@{Modbus Object Management}!poll@{poll}} 64 | \index{poll@{poll}!Modbus Object Management@{Modbus Object Management}} 65 | \subsubsection[{poll}]{\setlength{\rightskip}{0pt plus 5cm}int8\-\_\-t Modbus\-::poll ( 66 | \begin{DoxyParamCaption} 67 | \item[{uint16\-\_\-t $\ast$}]{regs, } 68 | \item[{uint8\-\_\-t}]{u8size} 69 | \end{DoxyParamCaption} 70 | )}}\label{group__loop_gab3ef20562fc8cee14fc85f7e276890b5} 71 | 72 | 73 | cyclic poll for slave 74 | 75 | $\ast$$\ast$$\ast$ Only for \hyperlink{class_modbus}{Modbus} Slave $\ast$$\ast$$\ast$ 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. 76 | 77 | 78 | \begin{DoxyParams}{Parameters} 79 | {\em $\ast$regs} & register table for communication exchange \\ 80 | \hline 81 | {\em u8size} & size of the register table \\ 82 | \hline 83 | \end{DoxyParams} 84 | \begin{DoxyReturn}{Returns} 85 | 0 if no query, 1..4 if communication error, $>$4 if correct query processed 86 | \end{DoxyReturn} 87 | 88 | 89 | Definition at line 588 of file Modbus\-Rtu.\-h. 90 | 91 | \hypertarget{group__loop_ga19398cabed57b6d085d014af6c149f54}{\index{Modbus Object Management@{Modbus Object Management}!query@{query}} 92 | \index{query@{query}!Modbus Object Management@{Modbus Object Management}} 93 | \subsubsection[{query}]{\setlength{\rightskip}{0pt plus 5cm}int8\-\_\-t Modbus\-::query ( 94 | \begin{DoxyParamCaption} 95 | \item[{{\bf modbus\-\_\-t}}]{telegram} 96 | \end{DoxyParamCaption} 97 | )}}\label{group__loop_ga19398cabed57b6d085d014af6c149f54} 98 | 99 | 100 | only for master 101 | 102 | $\ast$$\ast$$\ast$ Only \hyperlink{class_modbus}{Modbus} Master $\ast$$\ast$$\ast$ Generate a query to an slave with a \hyperlink{structmodbus__t}{modbus\-\_\-t} telegram structure The Master must be in C\-O\-M\-\_\-\-I\-D\-L\-E mode. After it, its state would be C\-O\-M\-\_\-\-W\-A\-I\-T\-I\-N\-G. This method has to be called only in loop() section. 103 | 104 | \begin{DoxySeeAlso}{See Also} 105 | \hyperlink{structmodbus__t}{modbus\-\_\-t} 106 | \end{DoxySeeAlso} 107 | 108 | \begin{DoxyParams}{Parameters} 109 | {\em \hyperlink{structmodbus__t}{modbus\-\_\-t}} & modbus telegram structure (id, fct, ...)\\ 110 | \hline 111 | \end{DoxyParams} 112 | \begin{DoxyRefDesc}{Todo} 113 | \item[\hyperlink{todo__todo000001}{Todo}]finish function 15 \end{DoxyRefDesc} 114 | 115 | 116 | Definition at line 425 of file Modbus\-Rtu.\-h. 117 | 118 | -------------------------------------------------------------------------------- /Modbus/documentation/latex/group__register.tex: -------------------------------------------------------------------------------- 1 | \hypertarget{group__register}{\section{Modbus Function Codes for Holding/\-Input Registers} 2 | \label{group__register}\index{Modbus Function Codes for Holding/\-Input Registers@{Modbus Function Codes for Holding/\-Input Registers}} 3 | } 4 | 5 | 6 | \subsection{Detailed Description} 7 | -------------------------------------------------------------------------------- /Modbus/documentation/latex/group__setup.tex: -------------------------------------------------------------------------------- 1 | \hypertarget{group__setup}{\section{Modbus Object Instantiation/\-Initialization} 2 | \label{group__setup}\index{Modbus Object Instantiation/\-Initialization@{Modbus Object Instantiation/\-Initialization}} 3 | } 4 | \subsection*{Functions} 5 | \begin{DoxyCompactItemize} 6 | \item 7 | \hyperlink{group__setup_ga101809cdd4734537bab58dc315a840b4}{Modbus\-::\-Modbus} () 8 | \begin{DoxyCompactList}\small\item\em Default Constructor for Master through Serial. \end{DoxyCompactList}\item 9 | void \hyperlink{group__setup_ga475a4fa0fac491307b10c4529ad6d2a0}{Modbus\-::begin} (long u32speed) 10 | \begin{DoxyCompactList}\small\item\em Initialize class object. \end{DoxyCompactList}\item 11 | void \hyperlink{group__setup_ga9bd497e97ac1777d4f0d4171078d60e0}{Modbus\-::set\-I\-D} (uint8\-\_\-t u8id) 12 | \begin{DoxyCompactList}\small\item\em write new I\-D for the slave \end{DoxyCompactList}\item 13 | uint8\-\_\-t \hyperlink{group__setup_ga6449894306ff8cc5d4caff09b1b0d1ce}{Modbus\-::get\-I\-D} () 14 | \begin{DoxyCompactList}\small\item\em get slave I\-D between 1 and 247 \end{DoxyCompactList}\item 15 | void \hyperlink{group__setup_gaf828190ebe24efb1b3b1957429f3872e}{Modbus\-::set\-Time\-Out} (uint16\-\_\-t u16timeout) 16 | \begin{DoxyCompactList}\small\item\em write communication watch-\/dog timer \end{DoxyCompactList}\end{DoxyCompactItemize} 17 | 18 | 19 | \subsection{Detailed Description} 20 | 21 | 22 | \subsection{Function Documentation} 23 | \hypertarget{group__setup_ga475a4fa0fac491307b10c4529ad6d2a0}{\index{Modbus Object Instantiation/\-Initialization@{Modbus Object Instantiation/\-Initialization}!begin@{begin}} 24 | \index{begin@{begin}!Modbus Object Instantiation/Initialization@{Modbus Object Instantiation/\-Initialization}} 25 | \subsubsection[{begin}]{\setlength{\rightskip}{0pt plus 5cm}void Modbus\-::begin ( 26 | \begin{DoxyParamCaption} 27 | \item[{long}]{u32speed} 28 | \end{DoxyParamCaption} 29 | )}}\label{group__setup_ga475a4fa0fac491307b10c4529ad6d2a0} 30 | 31 | 32 | Initialize class object. 33 | 34 | Sets up the serial port using specified baud rate. Call once class has been instantiated, typically within setup(). 35 | 36 | \begin{DoxySeeAlso}{See Also} 37 | \href{http://arduino.cc/en/Serial/Begin#.Uy4CJ6aKlHY}{\tt http\-://arduino.\-cc/en/\-Serial/\-Begin\#.\-Uy4\-C\-J6a\-Kl\-H\-Y} 38 | \end{DoxySeeAlso} 39 | 40 | \begin{DoxyParams}{Parameters} 41 | {\em speed} & baud rate, in standard increments (300..115200) \\ 42 | \hline 43 | {\em config} & data frame settings (data length, parity and stop bits) \\ 44 | \hline 45 | \end{DoxyParams} 46 | 47 | 48 | Definition at line 250 of file Modbus\-Rtu.\-h. 49 | 50 | \hypertarget{group__setup_ga6449894306ff8cc5d4caff09b1b0d1ce}{\index{Modbus Object Instantiation/\-Initialization@{Modbus Object Instantiation/\-Initialization}!get\-I\-D@{get\-I\-D}} 51 | \index{get\-I\-D@{get\-I\-D}!Modbus Object Instantiation/Initialization@{Modbus Object Instantiation/\-Initialization}} 52 | \subsubsection[{get\-I\-D}]{\setlength{\rightskip}{0pt plus 5cm}uint8\-\_\-t Modbus\-::get\-I\-D ( 53 | \begin{DoxyParamCaption} 54 | {} 55 | \end{DoxyParamCaption} 56 | )}}\label{group__setup_ga6449894306ff8cc5d4caff09b1b0d1ce} 57 | 58 | 59 | get slave I\-D between 1 and 247 60 | 61 | Method to read current slave I\-D address. 62 | 63 | \begin{DoxyReturn}{Returns} 64 | u8id current slave address between 1 and 247 65 | \end{DoxyReturn} 66 | 67 | 68 | Definition at line 323 of file Modbus\-Rtu.\-h. 69 | 70 | \hypertarget{group__setup_ga101809cdd4734537bab58dc315a840b4}{\index{Modbus Object Instantiation/\-Initialization@{Modbus Object Instantiation/\-Initialization}!Modbus@{Modbus}} 71 | \index{Modbus@{Modbus}!Modbus Object Instantiation/Initialization@{Modbus Object Instantiation/\-Initialization}} 72 | \subsubsection[{Modbus}]{\setlength{\rightskip}{0pt plus 5cm}Modbus\-::\-Modbus ( 73 | \begin{DoxyParamCaption} 74 | {} 75 | \end{DoxyParamCaption} 76 | )}}\label{group__setup_ga101809cdd4734537bab58dc315a840b4} 77 | 78 | 79 | Default Constructor for Master through Serial. 80 | 81 | 82 | 83 | Definition at line 204 of file Modbus\-Rtu.\-h. 84 | 85 | \hypertarget{group__setup_ga9bd497e97ac1777d4f0d4171078d60e0}{\index{Modbus Object Instantiation/\-Initialization@{Modbus Object Instantiation/\-Initialization}!set\-I\-D@{set\-I\-D}} 86 | \index{set\-I\-D@{set\-I\-D}!Modbus Object Instantiation/Initialization@{Modbus Object Instantiation/\-Initialization}} 87 | \subsubsection[{set\-I\-D}]{\setlength{\rightskip}{0pt plus 5cm}void Modbus\-::set\-I\-D ( 88 | \begin{DoxyParamCaption} 89 | \item[{uint8\-\_\-t}]{u8id} 90 | \end{DoxyParamCaption} 91 | )}}\label{group__setup_ga9bd497e97ac1777d4f0d4171078d60e0} 92 | 93 | 94 | write new I\-D for the slave 95 | 96 | Method to write a new slave I\-D address. 97 | 98 | 99 | \begin{DoxyParams}{Parameters} 100 | {\em u8id} & new slave address between 1 and 247 \\ 101 | \hline 102 | \end{DoxyParams} 103 | 104 | 105 | Definition at line 310 of file Modbus\-Rtu.\-h. 106 | 107 | \hypertarget{group__setup_gaf828190ebe24efb1b3b1957429f3872e}{\index{Modbus Object Instantiation/\-Initialization@{Modbus Object Instantiation/\-Initialization}!set\-Time\-Out@{set\-Time\-Out}} 108 | \index{set\-Time\-Out@{set\-Time\-Out}!Modbus Object Instantiation/Initialization@{Modbus Object Instantiation/\-Initialization}} 109 | \subsubsection[{set\-Time\-Out}]{\setlength{\rightskip}{0pt plus 5cm}void Modbus\-::set\-Time\-Out ( 110 | \begin{DoxyParamCaption} 111 | \item[{uint16\-\_\-t}]{u16time\-Out} 112 | \end{DoxyParamCaption} 113 | )}}\label{group__setup_gaf828190ebe24efb1b3b1957429f3872e} 114 | 115 | 116 | write communication watch-\/dog timer 117 | 118 | Initialize time-\/out parameter. 119 | 120 | 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. 121 | 122 | 123 | \begin{DoxyParams}{Parameters} 124 | {\em time-\/out} & value (ms) \\ 125 | \hline 126 | \end{DoxyParams} 127 | 128 | 129 | Definition at line 338 of file Modbus\-Rtu.\-h. 130 | 131 | -------------------------------------------------------------------------------- /Modbus/documentation/latex/modules.tex: -------------------------------------------------------------------------------- 1 | \section{Modules} 2 | Here is a list of all modules\-:\begin{DoxyCompactList} 3 | \item \contentsline{section}{Modbus Object Instantiation/\-Initialization}{\pageref{group__setup}}{} 4 | \item \contentsline{section}{Modbus Object Management}{\pageref{group__loop}}{} 5 | \item \contentsline{section}{Modbus Buffer Management}{\pageref{group__buffer}}{} 6 | \item \contentsline{section}{Modbus Function Codes for Discrete Coils/\-Inputs}{\pageref{group__discrete}}{} 7 | \item \contentsline{section}{Modbus Function Codes for Holding/\-Input Registers}{\pageref{group__register}}{} 8 | \end{DoxyCompactList} 9 | -------------------------------------------------------------------------------- /Modbus/documentation/latex/refman.tex: -------------------------------------------------------------------------------- 1 | \documentclass[twoside]{book} 2 | 3 | % Packages required by doxygen 4 | \usepackage{calc} 5 | \usepackage{doxygen} 6 | \usepackage{graphicx} 7 | \usepackage[utf8]{inputenc} 8 | \usepackage{makeidx} 9 | \usepackage{multicol} 10 | \usepackage{multirow} 11 | \usepackage{textcomp} 12 | \usepackage[table]{xcolor} 13 | 14 | % Font selection 15 | \usepackage[T1]{fontenc} 16 | \usepackage{mathptmx} 17 | \usepackage[scaled=.90]{helvet} 18 | \usepackage{courier} 19 | \usepackage{amssymb} 20 | \usepackage{sectsty} 21 | \renewcommand{\familydefault}{\sfdefault} 22 | \allsectionsfont{% 23 | \fontseries{bc}\selectfont% 24 | \color{darkgray}% 25 | } 26 | \renewcommand{\DoxyLabelFont}{% 27 | \fontseries{bc}\selectfont% 28 | \color{darkgray}% 29 | } 30 | 31 | % Page & text layout 32 | \usepackage{geometry} 33 | \geometry{% 34 | a4paper,% 35 | top=2.5cm,% 36 | bottom=2.5cm,% 37 | left=2.5cm,% 38 | right=2.5cm% 39 | } 40 | \tolerance=750 41 | \hfuzz=15pt 42 | \hbadness=750 43 | \setlength{\emergencystretch}{15pt} 44 | \setlength{\parindent}{0cm} 45 | \setlength{\parskip}{0.2cm} 46 | \makeatletter 47 | \renewcommand{\paragraph}{% 48 | \@startsection{paragraph}{4}{0ex}{-1.0ex}{1.0ex}{% 49 | \normalfont\normalsize\bfseries\SS@parafont% 50 | }% 51 | } 52 | \renewcommand{\subparagraph}{% 53 | \@startsection{subparagraph}{5}{0ex}{-1.0ex}{1.0ex}{% 54 | \normalfont\normalsize\bfseries\SS@subparafont% 55 | }% 56 | } 57 | \makeatother 58 | 59 | % Headers & footers 60 | \usepackage{fancyhdr} 61 | \pagestyle{fancyplain} 62 | \fancyhead[LE]{\fancyplain{}{\bfseries\thepage}} 63 | \fancyhead[CE]{\fancyplain{}{}} 64 | \fancyhead[RE]{\fancyplain{}{\bfseries\leftmark}} 65 | \fancyhead[LO]{\fancyplain{}{\bfseries\rightmark}} 66 | \fancyhead[CO]{\fancyplain{}{}} 67 | \fancyhead[RO]{\fancyplain{}{\bfseries\thepage}} 68 | \fancyfoot[LE]{\fancyplain{}{}} 69 | \fancyfoot[CE]{\fancyplain{}{}} 70 | \fancyfoot[RE]{\fancyplain{}{\bfseries\scriptsize Generated on Tue Sep 9 2014 21:52:15 for Modbus Master and Slave for Arduino by Doxygen }} 71 | \fancyfoot[LO]{\fancyplain{}{\bfseries\scriptsize Generated on Tue Sep 9 2014 21:52:15 for Modbus Master and Slave for Arduino by Doxygen }} 72 | \fancyfoot[CO]{\fancyplain{}{}} 73 | \fancyfoot[RO]{\fancyplain{}{}} 74 | \renewcommand{\footrulewidth}{0.4pt} 75 | \renewcommand{\chaptermark}[1]{% 76 | \markboth{#1}{}% 77 | } 78 | \renewcommand{\sectionmark}[1]{% 79 | \markright{\thesection\ #1}% 80 | } 81 | 82 | % Indices & bibliography 83 | \usepackage{natbib} 84 | \usepackage[titles]{tocloft} 85 | \setcounter{tocdepth}{3} 86 | \setcounter{secnumdepth}{5} 87 | \makeindex 88 | 89 | % Hyperlinks (required, but should be loaded last) 90 | \usepackage{ifpdf} 91 | \ifpdf 92 | \usepackage[pdftex,pagebackref=true]{hyperref} 93 | \else 94 | \usepackage[ps2pdf,pagebackref=true]{hyperref} 95 | \fi 96 | \hypersetup{% 97 | colorlinks=true,% 98 | linkcolor=blue,% 99 | citecolor=blue,% 100 | unicode% 101 | } 102 | 103 | % Custom commands 104 | \newcommand{\clearemptydoublepage}{% 105 | \newpage{\pagestyle{empty}\cleardoublepage}% 106 | } 107 | 108 | 109 | %===== C O N T E N T S ===== 110 | 111 | \begin{document} 112 | 113 | % Titlepage & ToC 114 | \hypersetup{pageanchor=false} 115 | \pagenumbering{roman} 116 | \begin{titlepage} 117 | \vspace*{7cm} 118 | \begin{center}% 119 | {\Large Modbus Master and Slave for Arduino \\[1ex]\large 1.\-2 }\\ 120 | \vspace*{1cm} 121 | {\large Generated by Doxygen 1.8.4}\\ 122 | \vspace*{0.5cm} 123 | {\small Tue Sep 9 2014 21:52:15}\\ 124 | \end{center} 125 | \end{titlepage} 126 | \clearemptydoublepage 127 | \tableofcontents 128 | \clearemptydoublepage 129 | \pagenumbering{arabic} 130 | \hypersetup{pageanchor=true} 131 | 132 | %--- Begin generated contents --- 133 | \chapter{Todo List} 134 | \label{todo} 135 | \hypertarget{todo}{} 136 | \input{todo} 137 | \chapter{Module Index} 138 | \input{modules} 139 | \chapter{Class Index} 140 | \input{annotated} 141 | \chapter{File Index} 142 | \input{files} 143 | \chapter{Module Documentation} 144 | \input{group__setup} 145 | \include{group__loop} 146 | \include{group__buffer} 147 | \include{group__discrete} 148 | \include{group__register} 149 | \chapter{Class Documentation} 150 | \input{class_modbus} 151 | \input{structmodbus__t} 152 | \chapter{File Documentation} 153 | \input{_modbus_rtu_8h} 154 | %--- End generated contents --- 155 | 156 | % Index 157 | \newpage 158 | \phantomsection 159 | \addcontentsline{toc}{part}{Index} 160 | \printindex 161 | 162 | \end{document} 163 | -------------------------------------------------------------------------------- /Modbus/documentation/latex/structmodbus__t.tex: -------------------------------------------------------------------------------- 1 | \hypertarget{structmodbus__t}{\section{modbus\-\_\-t Struct Reference} 2 | \label{structmodbus__t}\index{modbus\-\_\-t@{modbus\-\_\-t}} 3 | } 4 | 5 | 6 | Master query structure\-: This includes all the necessary fields to make the Master generate a \hyperlink{class_modbus}{Modbus} query. A Master may keep several of these structures and send them cyclically or use them according to program needs. 7 | 8 | 9 | 10 | 11 | {\ttfamily \#include $<$Modbus\-Rtu.\-h$>$} 12 | 13 | \subsection*{Public Attributes} 14 | \begin{DoxyCompactItemize} 15 | \item 16 | uint8\-\_\-t \hyperlink{structmodbus__t_af78ad11f93e63022a1c279de7206358c}{u8id} 17 | \item 18 | uint8\-\_\-t \hyperlink{structmodbus__t_a57d1630d4548e5d50d79e206a48b09bc}{u8fct} 19 | \item 20 | uint16\-\_\-t \hyperlink{structmodbus__t_a224ead9ff72467696e94fba9cf06bd3c}{u16\-Reg\-Add} 21 | \item 22 | uint16\-\_\-t \hyperlink{structmodbus__t_a5b9cee9c1a9415d927543f6cf054eb43}{u16\-Coils\-No} 23 | \item 24 | uint16\-\_\-t $\ast$ \hyperlink{structmodbus__t_a36212dd6316cbffb8ea31b2a2f5ae1be}{au16reg} 25 | \end{DoxyCompactItemize} 26 | 27 | 28 | \subsection{Detailed Description} 29 | Master query structure\-: This includes all the necessary fields to make the Master generate a \hyperlink{class_modbus}{Modbus} query. A Master may keep several of these structures and send them cyclically or use them according to program needs. 30 | 31 | Definition at line 48 of file Modbus\-Rtu.\-h. 32 | 33 | 34 | 35 | \subsection{Member Data Documentation} 36 | \hypertarget{structmodbus__t_a36212dd6316cbffb8ea31b2a2f5ae1be}{\index{modbus\-\_\-t@{modbus\-\_\-t}!au16reg@{au16reg}} 37 | \index{au16reg@{au16reg}!modbus_t@{modbus\-\_\-t}} 38 | \subsubsection[{au16reg}]{\setlength{\rightskip}{0pt plus 5cm}uint16\-\_\-t$\ast$ modbus\-\_\-t\-::au16reg}}\label{structmodbus__t_a36212dd6316cbffb8ea31b2a2f5ae1be} 39 | Pointer to memory image in master 40 | 41 | Definition at line 53 of file Modbus\-Rtu.\-h. 42 | 43 | \hypertarget{structmodbus__t_a5b9cee9c1a9415d927543f6cf054eb43}{\index{modbus\-\_\-t@{modbus\-\_\-t}!u16\-Coils\-No@{u16\-Coils\-No}} 44 | \index{u16\-Coils\-No@{u16\-Coils\-No}!modbus_t@{modbus\-\_\-t}} 45 | \subsubsection[{u16\-Coils\-No}]{\setlength{\rightskip}{0pt plus 5cm}uint16\-\_\-t modbus\-\_\-t\-::u16\-Coils\-No}}\label{structmodbus__t_a5b9cee9c1a9415d927543f6cf054eb43} 46 | Number of coils or registers to access 47 | 48 | Definition at line 52 of file Modbus\-Rtu.\-h. 49 | 50 | \hypertarget{structmodbus__t_a224ead9ff72467696e94fba9cf06bd3c}{\index{modbus\-\_\-t@{modbus\-\_\-t}!u16\-Reg\-Add@{u16\-Reg\-Add}} 51 | \index{u16\-Reg\-Add@{u16\-Reg\-Add}!modbus_t@{modbus\-\_\-t}} 52 | \subsubsection[{u16\-Reg\-Add}]{\setlength{\rightskip}{0pt plus 5cm}uint16\-\_\-t modbus\-\_\-t\-::u16\-Reg\-Add}}\label{structmodbus__t_a224ead9ff72467696e94fba9cf06bd3c} 53 | Address of the first register to access at slave/s 54 | 55 | Definition at line 51 of file Modbus\-Rtu.\-h. 56 | 57 | \hypertarget{structmodbus__t_a57d1630d4548e5d50d79e206a48b09bc}{\index{modbus\-\_\-t@{modbus\-\_\-t}!u8fct@{u8fct}} 58 | \index{u8fct@{u8fct}!modbus_t@{modbus\-\_\-t}} 59 | \subsubsection[{u8fct}]{\setlength{\rightskip}{0pt plus 5cm}uint8\-\_\-t modbus\-\_\-t\-::u8fct}}\label{structmodbus__t_a57d1630d4548e5d50d79e206a48b09bc} 60 | Function code\-: 1, 2, 3, 4, 5, 6, 15 or 16 61 | 62 | Definition at line 50 of file Modbus\-Rtu.\-h. 63 | 64 | \hypertarget{structmodbus__t_af78ad11f93e63022a1c279de7206358c}{\index{modbus\-\_\-t@{modbus\-\_\-t}!u8id@{u8id}} 65 | \index{u8id@{u8id}!modbus_t@{modbus\-\_\-t}} 66 | \subsubsection[{u8id}]{\setlength{\rightskip}{0pt plus 5cm}uint8\-\_\-t modbus\-\_\-t\-::u8id}}\label{structmodbus__t_af78ad11f93e63022a1c279de7206358c} 67 | Slave address between 1 and 247. 0 means broadcast 68 | 69 | Definition at line 49 of file Modbus\-Rtu.\-h. 70 | 71 | 72 | 73 | The documentation for this struct was generated from the following file\-:\begin{DoxyCompactItemize} 74 | \item 75 | \hyperlink{_modbus_rtu_8h}{Modbus\-Rtu.\-h}\end{DoxyCompactItemize} 76 | -------------------------------------------------------------------------------- /Modbus/documentation/latex/todo.tex: -------------------------------------------------------------------------------- 1 | 2 | \begin{DoxyRefList} 3 | \item[\label{todo__todo000001}% 4 | \hypertarget{todo__todo000001}{}% 5 | Member \hyperlink{group__loop_ga19398cabed57b6d085d014af6c149f54}{Modbus\-:\-:query} (\hyperlink{structmodbus__t}{modbus\-\_\-t} telegram)]finish function 15 6 | \end{DoxyRefList} -------------------------------------------------------------------------------- /Modbus/examples/MODBUSslave/MODBUSslave.pde: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | /* 7 | This example code shows a quick and dirty way to get an 8 | arduino to talk to a modbus master device with a 9 | device ID of 1 at 9600 baud. 10 | */ 11 | 12 | //Setup the brewtrollers register bank 13 | //All of the data accumulated will be stored here 14 | modbusDevice regBank; 15 | //Create the modbus slave protocol handler 16 | modbusSlave slave; 17 | 18 | void setup() 19 | { 20 | 21 | //Assign the modbus device ID. 22 | regBank.setId(1); 23 | 24 | /* 25 | modbus registers follow the following format 26 | 00001-09999 Digital Outputs, A master device can read and write to these registers 27 | 10001-19999 Digital Inputs, A master device can only read the values from these registers 28 | 30001-39999 Analog Inputs, A master device can only read the values from these registers 29 | 40001-49999 Analog Outputs, A master device can read and write to these registers 30 | 31 | Analog values are 16 bit unsigned words stored with a range of 0-32767 32 | Digital values are stored as bytes, a zero value is OFF and any nonzer value is ON 33 | 34 | It is best to configure registers of like type into contiguous blocks. this 35 | allows for more efficient register lookup and and reduces the number of messages 36 | required by the master to retrieve the data 37 | */ 38 | 39 | //Add Digital Output registers 00001-00016 to the register bank 40 | regBank.add(1); 41 | regBank.add(2); 42 | regBank.add(3); 43 | regBank.add(4); 44 | regBank.add(5); 45 | regBank.add(6); 46 | regBank.add(7); 47 | regBank.add(8); 48 | regBank.add(9); 49 | regBank.add(10); 50 | regBank.add(11); 51 | regBank.add(12); 52 | regBank.add(13); 53 | regBank.add(14); 54 | regBank.add(15); 55 | regBank.add(16); 56 | 57 | //Add Digital Input registers 10001-10008 to the register bank 58 | regBank.add(10001); 59 | regBank.add(10002); 60 | regBank.add(10003); 61 | regBank.add(10004); 62 | regBank.add(10005); 63 | regBank.add(10006); 64 | regBank.add(10007); 65 | regBank.add(10008); 66 | 67 | //Add Analog Input registers 30001-10010 to the register bank 68 | regBank.add(30001); 69 | regBank.add(30002); 70 | regBank.add(30003); 71 | regBank.add(30004); 72 | regBank.add(30005); 73 | regBank.add(30006); 74 | regBank.add(30007); 75 | regBank.add(30008); 76 | regBank.add(30009); 77 | regBank.add(30010); 78 | 79 | //Add Analog Output registers 40001-40020 to the register bank 80 | regBank.add(40001); 81 | regBank.add(40002); 82 | regBank.add(40003); 83 | regBank.add(40004); 84 | regBank.add(40005); 85 | regBank.add(40006); 86 | regBank.add(40007); 87 | regBank.add(40008); 88 | regBank.add(40009); 89 | regBank.add(40010); 90 | regBank.add(40011); 91 | regBank.add(40012); 92 | regBank.add(40013); 93 | regBank.add(40014); 94 | regBank.add(40015); 95 | regBank.add(40016); 96 | regBank.add(40017); 97 | regBank.add(40018); 98 | regBank.add(40019); 99 | regBank.add(40020); 100 | 101 | /* 102 | Assign the modbus device object to the protocol handler 103 | This is where the protocol handler will look to read and write 104 | register data. Currently, a modbus slave protocol handler may 105 | only have one device assigned to it. 106 | */ 107 | slave._device = ®Bank; 108 | 109 | // Initialize the serial port for coms at 9600 baud 110 | slave.setBaud(9600); 111 | } 112 | 113 | void loop() 114 | { 115 | //put some data into the registers 116 | regBank.set(1, 1); 117 | regBank.set(2, 1); 118 | regBank.set(3, 0); 119 | regBank.set(4, 1); 120 | regBank.set(5, 1); 121 | regBank.set(6, 0); 122 | regBank.set(7, 1); 123 | regBank.set(8, 0); 124 | 125 | regBank.set(10001, 1); 126 | regBank.set(10002, 1); 127 | regBank.set(10003, 1); 128 | regBank.set(10004, 1); 129 | regBank.set(10005, 0); 130 | regBank.set(10006, 0); 131 | regBank.set(10007, 0); 132 | regBank.set(10008, 0); 133 | 134 | 135 | regBank.set(30001,1); 136 | regBank.set(30002,2); 137 | regBank.set(30003,3); 138 | regBank.set(30004,4); 139 | regBank.set(30005,5); 140 | regBank.set(30006,6); 141 | regBank.set(30007,7); 142 | regBank.set(30008,8); 143 | regBank.set(30009,9); 144 | regBank.set(30010,10); 145 | 146 | regBank.set(40001,1); 147 | regBank.set(40002,2); 148 | regBank.set(40003,2); 149 | regBank.set(40004,4); 150 | regBank.set(40005,5); 151 | regBank.set(40006,6); 152 | regBank.set(40007,7); 153 | regBank.set(40008,8); 154 | regBank.set(40009,9); 155 | regBank.set(40010,10); 156 | 157 | while(1) 158 | { 159 | //put a random number into registers 1, 10001, 30001 and 40001 160 | regBank.set(1, (byte) random(0, 2)); 161 | regBank.set(10001, (byte) random(0, 2)); 162 | regBank.set(30001, (word) random(0, 32767)); 163 | regBank.set(40001, (word) random(0, 32767)); 164 | 165 | slave.run(); 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /Modbus/examples/RS485_slave/RS485_slave.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * Modbus slave example 3: 3 | * The purpose of this example is to link a data array 4 | * from the Arduino to an external device through RS485. 5 | * 6 | * Recommended Modbus Master: QModbus 7 | * http://qmodbus.sourceforge.net/ 8 | */ 9 | 10 | #include 11 | 12 | // assign the Arduino pin that must be connected to RE-DE RS485 transceiver 13 | #define TXEN 4 14 | 15 | // data array for modbus network sharing 16 | uint16_t au16data[16] = { 17 | 3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, -1 }; 18 | 19 | /** 20 | * Modbus object declaration 21 | * u8id : node id = 0 for master, = 1..247 for slave 22 | * u8serno : serial port (use 0 for Serial) 23 | * u8txenpin : 0 for RS-232 and USB-FTDI 24 | * or any pin number > 1 for RS-485 25 | */ 26 | Modbus slave(1,0,TXEN); // this is slave @1 and RS-485 27 | 28 | void setup() { 29 | slave.begin( 19200 ); // baud-rate at 19200 30 | } 31 | 32 | void loop() { 33 | slave.poll( au16data, 16 ); 34 | } 35 | -------------------------------------------------------------------------------- /Modbus/examples/advanced_master/advanced_master.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * Modbus master example 2: 3 | * The purpose of this example is to query several sets of data 4 | * from an external Modbus slave device. 5 | * The link media can be USB or RS232. 6 | * 7 | * Recommended Modbus slave: 8 | * diagslave http://www.modbusdriver.com/diagslave.html 9 | * 10 | * In a Linux box, run 11 | * "./diagslave /dev/ttyUSB0 -b 19200 -d 8 -s 1 -p none -m rtu -a 1" 12 | * This is: 13 | * serial port /dev/ttyUSB0 at 19200 baud 8N1 14 | * RTU mode and address @1 15 | */ 16 | 17 | #include 18 | 19 | uint16_t au16data[16]; //!< data array for modbus network sharing 20 | uint8_t u8state; //!< machine state 21 | uint8_t u8query; //!< pointer to message query 22 | 23 | /** 24 | * Modbus object declaration 25 | * u8id : node id = 0 for master, = 1..247 for slave 26 | * u8serno : serial port (use 0 for Serial) 27 | * u8txenpin : 0 for RS-232 and USB-FTDI 28 | * or any pin number > 1 for RS-485 29 | */ 30 | Modbus master(0,0,0); // this is master and RS-232 or USB-FTDI 31 | 32 | /** 33 | * This is an structe which contains a query to an slave device 34 | */ 35 | modbus_t telegram[2]; 36 | 37 | unsigned long u32wait; 38 | 39 | void setup() { 40 | // telegram 0: read registers 41 | telegram[0].u8id = 1; // slave address 42 | telegram[0].u8fct = 3; // function code (this one is registers read) 43 | telegram[0].u16RegAdd = 0; // start address in slave 44 | telegram[0].u16CoilsNo = 4; // number of elements (coils or registers) to read 45 | telegram[0].au16reg = au16data; // pointer to a memory array in the Arduino 46 | 47 | // telegram 1: write a single register 48 | telegram[1].u8id = 1; // slave address 49 | telegram[1].u8fct = 6; // function code (this one is write a single register) 50 | telegram[1].u16RegAdd = 4; // start address in slave 51 | telegram[1].u16CoilsNo = 1; // number of elements (coils or registers) to read 52 | telegram[1].au16reg = au16data+4; // pointer to a memory array in the Arduino 53 | 54 | master.begin( 19200 ); // baud-rate at 19200 55 | master.setTimeOut( 5000 ); // if there is no answer in 5000 ms, roll over 56 | u32wait = millis() + 1000; 57 | u8state = u8query = 0; 58 | } 59 | 60 | void loop() { 61 | switch( u8state ) { 62 | case 0: 63 | if (millis() > u32wait) u8state++; // wait state 64 | break; 65 | case 1: 66 | master.query( telegram[u8query] ); // send query (only once) 67 | u8state++; 68 | u8query++; 69 | if (u8query > 2) u8query = 0; 70 | break; 71 | case 2: 72 | master.poll(); // check incoming messages 73 | if (master.getState() == COM_IDLE) { 74 | u8state = 0; 75 | u32wait = millis() + 1000; 76 | } 77 | break; 78 | } 79 | 80 | au16data[4] = analogRead( 0 ); 81 | 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Modbus/examples/advanced_slave/advanced_slave.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * Modbus slave example 2: 3 | * The purpose of this example is to link the Arduino digital and analog 4 | * pins to an external device. 5 | * 6 | * Recommended Modbus Master: QModbus 7 | * http://qmodbus.sourceforge.net/ 8 | */ 9 | 10 | #include 11 | #define ID 1 12 | 13 | Modbus slave(ID, 0, 0); // this is slave ID and RS-232 or USB-FTDI 14 | boolean led; 15 | int8_t state = 0; 16 | unsigned long tempus; 17 | 18 | // data array for modbus network sharing 19 | uint16_t au16data[9]; 20 | 21 | /** 22 | * Setup procedure 23 | */ 24 | void setup() { 25 | io_setup(); // I/O settings 26 | 27 | // start communication 28 | slave.begin( 19200 ); 29 | tempus = millis() + 100; 30 | digitalWrite(13, HIGH ); 31 | } 32 | 33 | /** 34 | * Loop procedure 35 | */ 36 | void loop() { 37 | // poll messages 38 | // blink led pin on each valid message 39 | state = slave.poll( au16data, 9 ); 40 | 41 | if (state > 4) { 42 | tempus = millis() + 50; 43 | digitalWrite(13, HIGH); 44 | } 45 | if (millis() > tempus) digitalWrite(13, LOW ); 46 | 47 | // link the Arduino pins to the Modbus array 48 | io_poll(); 49 | } 50 | 51 | /** 52 | * pin maping: 53 | * 2 - digital input 54 | * 3 - digital input 55 | * 4 - digital input 56 | * 5 - digital input 57 | * 6 - digital output 58 | * 7 - digital output 59 | * 8 - digital output 60 | * 9 - digital output 61 | * 10 - analog output 62 | * 11 - analog output 63 | * 14 - analog input 64 | * 15 - analog input 65 | * 66 | * pin 13 is reserved to show a successful query 67 | */ 68 | void io_setup() { 69 | // define i/o 70 | pinMode(2, INPUT); 71 | pinMode(3, INPUT); 72 | pinMode(4, INPUT); 73 | pinMode(5, INPUT); 74 | pinMode(6, OUTPUT); 75 | pinMode(7, OUTPUT); 76 | pinMode(8, OUTPUT); 77 | pinMode(9, OUTPUT); 78 | pinMode(10, OUTPUT); 79 | pinMode(11, OUTPUT); 80 | pinMode(13, OUTPUT); 81 | 82 | digitalWrite(6, LOW ); 83 | digitalWrite(7, LOW ); 84 | digitalWrite(8, LOW ); 85 | digitalWrite(9, LOW ); 86 | digitalWrite(13, HIGH ); // this is for the UNO led pin 87 | analogWrite(10, 0 ); 88 | analogWrite(11, 0 ); 89 | } 90 | 91 | /** 92 | * Link between the Arduino pins and the Modbus array 93 | */ 94 | void io_poll() { 95 | // get digital inputs -> au16data[0] 96 | bitWrite( au16data[0], 0, digitalRead( 2 )); 97 | bitWrite( au16data[0], 1, digitalRead( 3 )); 98 | bitWrite( au16data[0], 2, digitalRead( 4 )); 99 | bitWrite( au16data[0], 3, digitalRead( 5 )); 100 | 101 | // set digital outputs -> au16data[1] 102 | digitalWrite( 6, bitRead( au16data[1], 0 )); 103 | digitalWrite( 7, bitRead( au16data[1], 1 )); 104 | digitalWrite( 8, bitRead( au16data[1], 2 )); 105 | digitalWrite( 9, bitRead( au16data[1], 3 )); 106 | 107 | // set analog outputs 108 | analogWrite( 10, au16data[2] ); 109 | analogWrite( 11, au16data[3] ); 110 | 111 | // read analog inputs 112 | au16data[4] = analogRead( 0 ); 113 | au16data[5] = analogRead( 1 ); 114 | 115 | // diagnose communication 116 | au16data[6] = slave.getInCnt(); 117 | au16data[7] = slave.getOutCnt(); 118 | au16data[8] = slave.getErrCnt(); 119 | } 120 | -------------------------------------------------------------------------------- /Modbus/examples/simple_master/simple_master.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * Modbus master example 1: 3 | * The purpose of this example is to query an array of data 4 | * from an external Modbus slave device. 5 | * The link media can be USB or RS232. 6 | * 7 | * Recommended Modbus slave: 8 | * diagslave http://www.modbusdriver.com/diagslave.html 9 | * 10 | * In a Linux box, run 11 | * "./diagslave /dev/ttyUSB0 -b 19200 -d 8 -s 1 -p none -m rtu -a 1" 12 | * This is: 13 | * serial port /dev/ttyUSB0 at 19200 baud 8N1 14 | * RTU mode and address @1 15 | */ 16 | 17 | #include 18 | 19 | // data array for modbus network sharing 20 | uint16_t au16data[16]; 21 | uint8_t u8state; 22 | 23 | /** 24 | * Modbus object declaration 25 | * u8id : node id = 0 for master, = 1..247 for slave 26 | * u8serno : serial port (use 0 for Serial) 27 | * u8txenpin : 0 for RS-232 and USB-FTDI 28 | * or any pin number > 1 for RS-485 29 | */ 30 | Modbus master(0,0,0); // this is master and RS-232 or USB-FTDI 31 | 32 | /** 33 | * This is an structe which contains a query to an slave device 34 | */ 35 | modbus_t telegram; 36 | 37 | unsigned long u32wait; 38 | 39 | void setup() { 40 | master.begin( 19200 ); // baud-rate at 19200 41 | master.setTimeOut( 2000 ); // if there is no answer in 2000 ms, roll over 42 | u32wait = millis() + 1000; 43 | u8state = 0; 44 | } 45 | 46 | void loop() { 47 | switch( u8state ) { 48 | case 0: 49 | if (millis() > u32wait) u8state++; // wait state 50 | break; 51 | case 1: 52 | telegram.u8id = 1; // slave address 53 | telegram.u8fct = 3; // function code (this one is registers read) 54 | telegram.u16RegAdd = 1; // start address in slave 55 | telegram.u16CoilsNo = 4; // number of elements (coils or registers) to read 56 | telegram.au16reg = au16data; // pointer to a memory array in the Arduino 57 | 58 | master.query( telegram ); // send query (only once) 59 | u8state++; 60 | break; 61 | case 2: 62 | master.poll(); // check incoming messages 63 | if (master.getState() == COM_IDLE) { 64 | u8state = 0; 65 | u32wait = millis() + 100; 66 | } 67 | break; 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /Modbus/examples/simple_slave/simple_slave.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * Modbus slave example 1: 3 | * The purpose of this example is to link a data array 4 | * from the Arduino to an external device. 5 | * 6 | * Recommended Modbus Master: QModbus 7 | * http://qmodbus.sourceforge.net/ 8 | */ 9 | 10 | #include 11 | 12 | // data array for modbus network sharing 13 | uint16_t au16data[16] = { 14 | 3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, -1 }; 15 | 16 | /** 17 | * Modbus object declaration 18 | * u8id : node id = 0 for master, = 1..247 for slave 19 | * u8serno : serial port (use 0 for Serial) 20 | * u8txenpin : 0 for RS-232 and USB-FTDI 21 | * or any pin number > 1 for RS-485 22 | */ 23 | Modbus slave(1,0,0); // this is slave @1 and RS-232 or USB-FTDI 24 | 25 | void setup() { 26 | slave.begin( 19200 ); // baud-rate at 19200 27 | } 28 | 29 | void loop() { 30 | slave.poll( au16data, 16 ); 31 | } 32 | -------------------------------------------------------------------------------- /Modbus/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Modbus-Master-Slave 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | modbus_t KEYWORD1 9 | 10 | ####################################### 11 | # Methods and Functions (KEYWORD2) 12 | ####################################### 13 | begin KEYWORD2 14 | poll KEYWORD2 15 | getInCnt KEYWORD2 16 | getOutCnt KEYWORD2 17 | getErrCnt KEYWORD2 18 | getID KEYWORD2 19 | getState KEYWORD2 20 | query KEYWORD2 21 | setTimeOut KEYWORD2 22 | 23 | ####################################### 24 | # Instances (KEYWORD2) 25 | ####################################### 26 | Modbus KEYWORD2 27 | 28 | ####################################### 29 | # Constants (LITERAL1) 30 | ####################################### 31 | -------------------------------------------------------------------------------- /Modbus/modbus.h: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef _MODBUSPROTOCOL 3 | #define _MODBUSPROTOCOL 4 | 5 | //Maximum device list for network 6 | #define DEVMAX 10 7 | //Maximum control register que size 8 | #define QUEMAX 10 9 | //Maximum serial wait in micro seconds 10 | #define SERIALMAXDELAY 100 11 | #define SERIALBAUD 9600 12 | //the total silence time needed to signify an EOM or SOM in RTU mode 13 | 14 | //Modbus function codes 15 | #define READ_DO 0x01 16 | #define READ_DI 0x02 17 | #define READ_AO 0x03 18 | #define READ_AI 0x04 19 | 20 | #define WRITE_DO 0x05 21 | #define WRITE_AO 0x06 22 | 23 | #define RTU 0x01 24 | #define ASCII 0x02 25 | 26 | #define MASTER 0x01 27 | #define SLAVE 0x02 28 | 29 | #define DO 0x00 30 | #define DI 0x01 31 | #define AI 0x03 32 | #define AO 0x04 33 | 34 | #endif -------------------------------------------------------------------------------- /Modbus/modbusDevice.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | modbusDevice::modbusDevice(void) 4 | { 5 | _id=NULL; 6 | } 7 | 8 | void modbusDevice::setId(byte id) 9 | { 10 | _id=id; 11 | } 12 | 13 | byte modbusDevice::getId(void) 14 | { 15 | return(_id); 16 | } 17 | -------------------------------------------------------------------------------- /Modbus/modbusDevice.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifndef _MODBUSDEVICE 5 | #define _MODBUSDEVICE 6 | 7 | #include 8 | #include 9 | //#include 10 | 11 | class modbusDevice:public modbusRegBank 12 | { 13 | public: 14 | modbusDevice(void); 15 | void setId(byte id); 16 | byte getId(void); 17 | 18 | private: 19 | byte _id; 20 | }; 21 | #endif 22 | -------------------------------------------------------------------------------- /Modbus/modbusRegBank.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | modbusRegBank::modbusRegBank(void) 5 | { 6 | _digRegs = 0; 7 | _lastDigReg = 0; 8 | _anaRegs = 0; 9 | _lastAnaReg = 0; 10 | } 11 | 12 | 13 | void modbusRegBank::add(word addr) 14 | { 15 | if(addr<20000) 16 | { 17 | modbusDigReg *temp; 18 | 19 | temp = (modbusDigReg *) malloc(sizeof(modbusDigReg)); 20 | temp->address = addr; 21 | temp->value = 0; 22 | temp->next = 0; 23 | 24 | if(_digRegs == 0) 25 | { 26 | _digRegs = temp; 27 | _lastDigReg = _digRegs; 28 | } 29 | else 30 | { 31 | //Assign the last register's next pointer to temp; 32 | _lastDigReg->next = temp; 33 | //then make temp the last register in the list. 34 | _lastDigReg = temp; 35 | } 36 | } 37 | else 38 | { 39 | modbusAnaReg *temp; 40 | 41 | temp = (modbusAnaReg *) malloc(sizeof(modbusAnaReg)); 42 | temp->address = addr; 43 | temp->value = 0; 44 | temp->next = 0; 45 | 46 | if(_anaRegs == 0) 47 | { 48 | _anaRegs = temp; 49 | _lastAnaReg = _anaRegs; 50 | } 51 | else 52 | { 53 | _lastAnaReg->next = temp; 54 | _lastAnaReg = temp; 55 | } 56 | } 57 | } 58 | 59 | word modbusRegBank::get(word addr) 60 | { 61 | if(addr < 20000) 62 | { 63 | modbusDigReg * regPtr; 64 | regPtr = (modbusDigReg *) this->search(addr); 65 | if(regPtr) 66 | return(regPtr->value); 67 | else 68 | return(NULL); 69 | } 70 | else 71 | { 72 | modbusAnaReg * regPtr; 73 | regPtr = (modbusAnaReg *) this->search(addr); 74 | if(regPtr) 75 | return(regPtr->value); 76 | else 77 | return(NULL); 78 | } 79 | } 80 | 81 | void modbusRegBank::set(word addr, word value) 82 | { 83 | //for digital data 84 | if(addr < 20000) 85 | { 86 | modbusDigReg * regPtr; 87 | //search for the register address 88 | regPtr = (modbusDigReg *) this->search(addr); 89 | //if a pointer was returned the set the register value to true if value is non zero 90 | if(regPtr) 91 | if(value) 92 | regPtr->value = 0xFF; 93 | else 94 | regPtr->value = 0x00; 95 | } 96 | else 97 | { 98 | modbusAnaReg * regPtr; 99 | //search for the register address 100 | regPtr = (modbusAnaReg *) this->search(addr); 101 | //if found then assign the register value to the new value. 102 | if(regPtr) 103 | regPtr->value = value; 104 | } 105 | } 106 | 107 | void * modbusRegBank::search(word addr) 108 | { 109 | //if the requested address is 0-19999 110 | //use a digital register pointer assigned to the first digital register 111 | //else use a analog register pointer assigned the first analog register 112 | 113 | if(addr < 20000) 114 | { 115 | modbusDigReg *regPtr = _digRegs; 116 | 117 | //if there is no register configured, bail 118 | if(regPtr == 0) 119 | return(0); 120 | 121 | //scan through the linked list until the end of the list or the register is found. 122 | //return the pointer. 123 | do 124 | { 125 | if(regPtr->address == addr) 126 | return(regPtr); 127 | regPtr = regPtr->next; 128 | } 129 | while(regPtr); 130 | } 131 | else 132 | { 133 | modbusAnaReg *regPtr = _anaRegs; 134 | 135 | //if there is no register configured, bail 136 | if(regPtr == 0) 137 | return(0); 138 | 139 | //scan through the linked list until the end of the list or the register is found. 140 | //return the pointer. 141 | do 142 | { 143 | if(regPtr->address == addr) 144 | return(regPtr); 145 | regPtr = regPtr->next; 146 | } 147 | while(regPtr); 148 | } 149 | return(0); 150 | } 151 | 152 | 153 | -------------------------------------------------------------------------------- /Modbus/modbusRegBank.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #ifndef _MODBUSREGBANK 6 | #define _MODBUSREGBANK 7 | 8 | #include 9 | //#include 10 | 11 | 12 | struct modbusDigReg 13 | { 14 | word address; 15 | byte value; 16 | 17 | modbusDigReg *next; 18 | }; 19 | 20 | struct modbusAnaReg 21 | { 22 | word address; 23 | word value; 24 | 25 | modbusAnaReg *next; 26 | }; 27 | 28 | class modbusRegBank 29 | { 30 | public: 31 | 32 | modbusRegBank(void); 33 | 34 | void add(word); 35 | word get(word); 36 | void set(word, word); 37 | 38 | private: 39 | void * search(word); 40 | 41 | modbusDigReg *_digRegs, 42 | *_lastDigReg; 43 | 44 | modbusAnaReg *_anaRegs, 45 | *_lastAnaReg; 46 | }; 47 | #endif 48 | -------------------------------------------------------------------------------- /Modbus/modbusSlave.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include // Modbus RTU pins D7(13),D8(15) RX,TX 6 | SoftwareSerial swSer(13, 15, false, 256); 7 | 8 | modbusSlave::modbusSlave() 9 | { 10 | } 11 | /* 12 | Set the Serial Baud rate. 13 | Reconfigure the UART for 8 data bits, no parity, and 1 stop bit. 14 | and flush the serial port. 15 | */ 16 | void modbusSlave::setBaud(word baud) 17 | { 18 | _baud = baud; 19 | //calculate the time perdiod for 3 characters for the given bps in ms. 20 | _frameDelay = 24000/_baud; 21 | 22 | swSer.begin(baud); 23 | 24 | // defaults to 8-bit, no parity, 1 stop bit 25 | //clear parity, stop bits, word length 26 | // UCSR0C = UCSR0C & B11000001; 27 | // UCSR0B = UCSR0B & B11111011; 28 | 29 | //Set word length to 8 bits 30 | // UCSR0C = UCSR0C | B00000110; 31 | 32 | //No parity 33 | // UCSR0C = UCSR0C | B00000000; 34 | 35 | //1 Stop bit 36 | // UCSR0C = UCSR0C | B00000100; 37 | 38 | swSer.flush(); 39 | } 40 | 41 | /* 42 | Retrieve the serial baud rate 43 | */ 44 | word modbusSlave::getBaud(void) 45 | { 46 | return(_baud); 47 | } 48 | 49 | /* 50 | Generates the crc for the current message in the buffer. 51 | */ 52 | 53 | void modbusSlave::calcCrc(void) 54 | { 55 | byte CRCHi = 0xFF, 56 | CRCLo = 0x0FF, 57 | Index, 58 | msgLen, 59 | *msgPtr; 60 | 61 | msgLen = _len-2; 62 | msgPtr = _msg; 63 | 64 | while(msgLen--) 65 | { 66 | Index = CRCHi ^ *msgPtr++; 67 | CRCHi = CRCLo ^ _auchCRCHi[Index]; 68 | CRCLo = _auchCRCLo[Index]; 69 | } 70 | _crc = (CRCHi << 8) | CRCLo; 71 | } 72 | 73 | /* 74 | Checks the UART for query data 75 | */ 76 | void modbusSlave::checkSerial(void) 77 | { 78 | //while there is more data in the UART than when last checked 79 | while(swSer.available()> _len) 80 | { 81 | //update the incoming query message length 82 | _len = swSer.available(); 83 | //Wait for 3 bytewidths of data (SOM/EOM) 84 | // delayMicroseconds(RTUFRAMETIME); 85 | delay(_frameDelay); 86 | //Check the UART again 87 | } 88 | } 89 | 90 | /* 91 | Copies the contents of the UART to a buffer 92 | */ 93 | void modbusSlave::serialRx(void) 94 | { 95 | byte i; 96 | 97 | //allocate memory for the incoming query message 98 | _msg = (byte*) malloc(_len); 99 | 100 | //copy the query byte for byte to the new buffer 101 | for (i=0 ; i < _len ; i++) 102 | _msg[i] = swSer.read(); 103 | } 104 | 105 | /* 106 | Generates a query reply message for Digital In/Out status update queries. 107 | */ 108 | void modbusSlave::getDigitalStatus(byte funcType, word startreg, word numregs) 109 | { 110 | //initialize the bit counter to 0 111 | byte bitn =0; 112 | 113 | //if the function is to read digital inputs then add 10001 to the start register 114 | //else add 1 to the start register 115 | if(funcType == READ_DI) 116 | startreg += 10001; 117 | else 118 | startreg += 1; 119 | 120 | //determine the message length 121 | //for each group of 8 registers the message length increases by 1 122 | _len = numregs/8; 123 | //if there is at least one incomplete byte's worth of data 124 | //then add 1 to the message length for the partial byte. 125 | if(numregs%8) 126 | _len++; 127 | //allow room for the Device ID byte, Function type byte, data byte count byte, and crc word 128 | _len +=5; 129 | 130 | //allocate memory of the appropriate size for the message 131 | _msg = (byte *) malloc(_len); 132 | 133 | //write the slave device ID 134 | _msg[0] = _device->getId(); 135 | //write the function type 136 | _msg[1] = funcType; 137 | //set the data byte count 138 | _msg[2] = _len-5; 139 | 140 | //For the quantity of registers queried 141 | while(numregs--) 142 | { 143 | //if a value is found for the current register, set bit number bitn of msg[3] 144 | //else clear it 145 | if(_device->get(startreg)) 146 | bitSet(_msg[3], bitn); 147 | else 148 | bitClear(_msg[3], bitn); 149 | //increment the bit index 150 | bitn++; 151 | //increment the register 152 | startreg++; 153 | } 154 | 155 | //generate the crc for the query reply and append it 156 | this->calcCrc(); 157 | _msg[_len - 2] = _crc >> 8; 158 | _msg[_len - 1] = _crc & 0xFF; 159 | } 160 | 161 | void modbusSlave::getAnalogStatus(byte funcType, word startreg, word numregs) 162 | { 163 | word val; 164 | word i = 0; 165 | 166 | //if the function is to read analog inputs then add 30001 to the start register 167 | //else add 40001 to the start register 168 | if(funcType == READ_AI) 169 | startreg += 30001; 170 | else 171 | startreg += 40001; 172 | 173 | //calculate the query reply message length 174 | //for each register queried add 2 bytes 175 | _len = numregs * 2; 176 | //allow room for the Device ID byte, Function type byte, data byte count byte, and crc word 177 | _len += 5; 178 | 179 | //allocate memory for the query response 180 | _msg = (byte *) malloc(_len); 181 | 182 | //write the device ID 183 | _msg[0] = _device->getId(); 184 | //write the function type 185 | _msg[1] = funcType; 186 | //set the data byte count 187 | _msg[2] = _len - 5; 188 | 189 | //for each register queried 190 | while(numregs--) 191 | { 192 | //retrieve the value from the register bank for the current register 193 | val = _device->get(startreg+i); 194 | //write the high byte of the register value 195 | _msg[3 + i * 2] = val >> 8; 196 | //write the low byte of the register value 197 | _msg[4 + i * 2] = val & 0xFF; 198 | //increment the register 199 | i++; 200 | } 201 | 202 | //generate the crc for the query reply and append it 203 | this->calcCrc(); 204 | _msg[_len - 2] = _crc >> 8; 205 | _msg[_len - 1] = _crc & 0xFF; 206 | } 207 | 208 | void modbusSlave::setStatus(byte funcType, word reg, word val) 209 | { 210 | //Set the query response message length 211 | //Device ID byte, Function byte, Register byte, Value byte, CRC word 212 | _len = 8; 213 | //allocate memory for the message buffer. 214 | _msg = (byte *) malloc(_len); 215 | 216 | 217 | //write the device ID 218 | _msg[0] = _device->getId(); 219 | //if the function type is a digital write 220 | if(funcType == WRITE_DO) 221 | { 222 | //Add 1 to the register value and set it's value to val 223 | _device->set(reg + 1, val); 224 | //write the function type to the response message 225 | _msg[1] = WRITE_DO; 226 | } 227 | else 228 | { 229 | //else add 40001 to the register and set it's value to val 230 | _device->set(reg + 40001, val); 231 | 232 | //write the function type of the response message 233 | _msg[1] = WRITE_AO; 234 | } 235 | 236 | //write the register number high byte value 237 | _msg[2] = reg >> 8; 238 | //write the register number low byte value 239 | _msg[3] = reg & 0xFF; 240 | //write the control value's high byte 241 | _msg[4] = val >> 8; 242 | //write the control value's low byte 243 | _msg[5] = val & 0xFF; 244 | 245 | //calculate the crc for the query reply and append it. 246 | this->calcCrc(); 247 | _msg[_len - 2]= _crc >> 8; 248 | _msg[_len - 1]= _crc & 0xFF; 249 | } 250 | 251 | void modbusSlave::run(void) 252 | { 253 | 254 | byte deviceId; 255 | byte funcType; 256 | word field1; 257 | word field2; 258 | 259 | int i; 260 | 261 | //initialize mesasge length 262 | _len = 0; 263 | 264 | //check for data in the recieve buffer 265 | this->checkSerial(); 266 | 267 | //if there is nothing in the recieve buffer, bail. 268 | if(_len == 0) 269 | { 270 | return; 271 | } 272 | 273 | //retrieve the query message from the serial uart 274 | this->serialRx(); 275 | 276 | //if the message id is not 255, and 277 | // and device id does not match bail 278 | if( (_msg[0] != 0xFF) && 279 | (_msg[0] != _device->getId()) ) 280 | { 281 | return; 282 | } 283 | //calculate the checksum of the query message minus the checksum it came with. 284 | this->calcCrc(); 285 | 286 | //if the checksum does not match, ignore the message 287 | if ( _crc != ((_msg[_len - 2] << 8) + _msg[_len - 1])) 288 | return; 289 | 290 | //copy the function type from the incoming query 291 | funcType = _msg[1]; 292 | 293 | //copy field 1 from the incoming query 294 | field1 = (_msg[2] << 8) | _msg[3]; 295 | 296 | //copy field 2 from the incoming query 297 | field2 = (_msg[4] << 8) | _msg[5]; 298 | 299 | //free the allocated memory for the query message 300 | free(_msg); 301 | //reset the message length; 302 | _len = 0; 303 | 304 | //generate query response based on function type 305 | switch(funcType) 306 | { 307 | case READ_DI: 308 | this->getDigitalStatus(funcType, field1, field2); 309 | break; 310 | case READ_DO: 311 | this->getDigitalStatus(funcType, field1, field2); 312 | break; 313 | case READ_AI: 314 | this->getAnalogStatus(funcType, field1, field2); 315 | break; 316 | case READ_AO: 317 | this->getAnalogStatus(funcType, field1, field2); 318 | break; 319 | case WRITE_DO: 320 | this->setStatus(funcType, field1, field2); 321 | break; 322 | case WRITE_AO: 323 | this->setStatus(funcType, field1, field2); 324 | break; 325 | default: 326 | return; 327 | break; 328 | } 329 | 330 | //if a reply was generated 331 | if(_len) 332 | { 333 | int i; 334 | //send the reply to the serial UART 335 | //Senguino doesn't support a bulk serial write command.... 336 | for(i = 0 ; i < _len ; i++) 337 | swSer.write(_msg[i]); 338 | //free the allocated memory for the reply message 339 | free(_msg); 340 | //reset the message length 341 | _len = 0; 342 | } 343 | } 344 | -------------------------------------------------------------------------------- /Modbus/modbusSlave.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trialcommand/ESP8266-Modbus-RTU-Slave/a7f7dd1ac13a088469c7d2ef02c09147f9cd4958/Modbus/modbusSlave.h -------------------------------------------------------------------------------- /SoftwareSerial/SoftwareSerial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | SoftwareSerial.cpp - Implementation of the Arduino software serial for ESP8266. 4 | Copyright (c) 2015-2016 Peter Lerup. All rights reserved. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | */ 21 | 22 | #include 23 | 24 | // The Arduino standard GPIO routines are not enough, 25 | // must use some from the Espressif SDK as well 26 | extern "C" { 27 | #include "gpio.h" 28 | } 29 | 30 | #include 31 | 32 | #define MAX_PIN 15 33 | 34 | // As the Arduino attachInterrupt has no parameter, lists of objects 35 | // and callbacks corresponding to each possible GPIO pins have to be defined 36 | SoftwareSerial *ObjList[MAX_PIN+1]; 37 | 38 | void ICACHE_RAM_ATTR sws_isr_0() { ObjList[0]->rxRead(); }; 39 | void ICACHE_RAM_ATTR sws_isr_1() { ObjList[1]->rxRead(); }; 40 | void ICACHE_RAM_ATTR sws_isr_2() { ObjList[2]->rxRead(); }; 41 | void ICACHE_RAM_ATTR sws_isr_3() { ObjList[3]->rxRead(); }; 42 | void ICACHE_RAM_ATTR sws_isr_4() { ObjList[4]->rxRead(); }; 43 | void ICACHE_RAM_ATTR sws_isr_5() { ObjList[5]->rxRead(); }; 44 | // Pin 6 to 11 can not be used 45 | void ICACHE_RAM_ATTR sws_isr_12() { ObjList[12]->rxRead(); }; 46 | void ICACHE_RAM_ATTR sws_isr_13() { ObjList[13]->rxRead(); }; 47 | void ICACHE_RAM_ATTR sws_isr_14() { ObjList[14]->rxRead(); }; 48 | void ICACHE_RAM_ATTR sws_isr_15() { ObjList[15]->rxRead(); }; 49 | 50 | static void (*ISRList[MAX_PIN+1])() = { 51 | sws_isr_0, 52 | sws_isr_1, 53 | sws_isr_2, 54 | sws_isr_3, 55 | sws_isr_4, 56 | sws_isr_5, 57 | NULL, 58 | NULL, 59 | NULL, 60 | NULL, 61 | NULL, 62 | NULL, 63 | sws_isr_12, 64 | sws_isr_13, 65 | sws_isr_14, 66 | sws_isr_15 67 | }; 68 | 69 | SoftwareSerial::SoftwareSerial(int receivePin, int transmitPin, bool inverse_logic, unsigned int buffSize) { 70 | m_rxValid = m_txValid = m_txEnableValid = false; 71 | m_buffer = NULL; 72 | m_invert = inverse_logic; 73 | m_overflow = false; 74 | m_rxEnabled = false; 75 | if (isValidGPIOpin(receivePin)) { 76 | m_rxPin = receivePin; 77 | m_buffSize = buffSize; 78 | m_buffer = (uint8_t*)malloc(m_buffSize); 79 | if (m_buffer != NULL) { 80 | m_rxValid = true; 81 | m_inPos = m_outPos = 0; 82 | pinMode(m_rxPin, INPUT); 83 | ObjList[m_rxPin] = this; 84 | enableRx(true); 85 | } 86 | } 87 | if (isValidGPIOpin(transmitPin)) { 88 | m_txValid = true; 89 | m_txPin = transmitPin; 90 | pinMode(m_txPin, OUTPUT); 91 | digitalWrite(m_txPin, !m_invert); 92 | } 93 | // Default speed 94 | begin(9600); 95 | } 96 | 97 | SoftwareSerial::~SoftwareSerial() { 98 | enableRx(false); 99 | if (m_rxValid) 100 | ObjList[m_rxPin] = NULL; 101 | if (m_buffer) 102 | free(m_buffer); 103 | } 104 | 105 | bool SoftwareSerial::isValidGPIOpin(int pin) { 106 | return (pin >= 0 && pin <= 5) || (pin >= 12 && pin <= MAX_PIN); 107 | } 108 | 109 | void SoftwareSerial::begin(long speed) { 110 | // Use getCycleCount() loop to get as exact timing as possible 111 | m_bitTime = ESP.getCpuFreqMHz()*1000000/speed; 112 | } 113 | 114 | long SoftwareSerial::baudRate() { 115 | return ESP.getCpuFreqMHz()*1000000/m_bitTime; 116 | } 117 | 118 | void SoftwareSerial::setTransmitEnablePin(int transmitEnablePin) { 119 | if (isValidGPIOpin(transmitEnablePin)) { 120 | m_txEnableValid = true; 121 | m_txEnablePin = transmitEnablePin; 122 | pinMode(m_txEnablePin, OUTPUT); 123 | digitalWrite(m_txEnablePin, LOW); 124 | } else { 125 | m_txEnableValid = false; 126 | } 127 | } 128 | 129 | void SoftwareSerial::enableRx(bool on) { 130 | if (m_rxValid) { 131 | if (on) 132 | attachInterrupt(m_rxPin, ISRList[m_rxPin], m_invert ? RISING : FALLING); 133 | else 134 | detachInterrupt(m_rxPin); 135 | m_rxEnabled = on; 136 | } 137 | } 138 | 139 | int SoftwareSerial::read() { 140 | if (!m_rxValid || (m_inPos == m_outPos)) return -1; 141 | uint8_t ch = m_buffer[m_outPos]; 142 | m_outPos = (m_outPos+1) % m_buffSize; 143 | return ch; 144 | } 145 | 146 | int SoftwareSerial::available() { 147 | if (!m_rxValid) return 0; 148 | int avail = m_inPos - m_outPos; 149 | if (avail < 0) avail += m_buffSize; 150 | return avail; 151 | } 152 | 153 | #define WAIT { while (ESP.getCycleCount()-start < wait); wait += m_bitTime; } 154 | 155 | size_t SoftwareSerial::write(uint8_t b) { 156 | if (!m_txValid) return 0; 157 | 158 | if (m_invert) b = ~b; 159 | // Disable interrupts in order to get a clean transmit 160 | cli(); 161 | if (m_txEnableValid) digitalWrite(m_txEnablePin, HIGH); 162 | unsigned long wait = m_bitTime; 163 | digitalWrite(m_txPin, HIGH); 164 | unsigned long start = ESP.getCycleCount(); 165 | // Start bit; 166 | digitalWrite(m_txPin, LOW); 167 | WAIT; 168 | for (int i = 0; i < 8; i++) { 169 | digitalWrite(m_txPin, (b & 1) ? HIGH : LOW); 170 | WAIT; 171 | b >>= 1; 172 | } 173 | // Stop bit 174 | digitalWrite(m_txPin, HIGH); 175 | WAIT; 176 | if (m_txEnableValid) digitalWrite(m_txEnablePin, LOW); 177 | sei(); 178 | return 1; 179 | } 180 | 181 | void SoftwareSerial::flush() { 182 | m_inPos = m_outPos = 0; 183 | } 184 | 185 | bool SoftwareSerial::overflow() { 186 | bool res = m_overflow; 187 | m_overflow = false; 188 | return res; 189 | } 190 | 191 | int SoftwareSerial::peek() { 192 | if (!m_rxValid || (m_inPos == m_outPos)) return -1; 193 | return m_buffer[m_outPos]; 194 | } 195 | 196 | void ICACHE_RAM_ATTR SoftwareSerial::rxRead() { 197 | // Advance the starting point for the samples but compensate for the 198 | // initial delay which occurs before the interrupt is delivered 199 | unsigned long wait = m_bitTime + m_bitTime/3 - 500; 200 | unsigned long start = ESP.getCycleCount(); 201 | uint8_t rec = 0; 202 | for (int i = 0; i < 8; i++) { 203 | WAIT; 204 | rec >>= 1; 205 | if (digitalRead(m_rxPin)) 206 | rec |= 0x80; 207 | } 208 | if (m_invert) rec = ~rec; 209 | // Stop bit 210 | WAIT; 211 | // Store the received value in the buffer unless we have an overflow 212 | int next = (m_inPos+1) % m_buffSize; 213 | if (next != m_outPos) { 214 | m_buffer[m_inPos] = rec; 215 | m_inPos = next; 216 | } else { 217 | m_overflow = true; 218 | } 219 | // Must clear this bit in the interrupt register, 220 | // it gets set even when interrupts are disabled 221 | GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << m_rxPin); 222 | } 223 | -------------------------------------------------------------------------------- /SoftwareSerial/SoftwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | SoftwareSerial.h 3 | 4 | SoftwareSerial.cpp - Implementation of the Arduino software serial for ESP8266. 5 | Copyright (c) 2015-2016 Peter Lerup. All rights reserved. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | 21 | */ 22 | 23 | #ifndef SoftwareSerial_h 24 | #define SoftwareSerial_h 25 | 26 | #include 27 | #include 28 | 29 | 30 | // This class is compatible with the corresponding AVR one, 31 | // the constructor however has an optional rx buffer size. 32 | // Speed up to 115200 can be used. 33 | 34 | 35 | class SoftwareSerial : public Stream 36 | { 37 | public: 38 | SoftwareSerial(int receivePin, int transmitPin, bool inverse_logic = false, unsigned int buffSize = 64); 39 | ~SoftwareSerial(); 40 | 41 | void begin(long speed); 42 | long baudRate(); 43 | void setTransmitEnablePin(int transmitEnablePin); 44 | 45 | bool overflow(); 46 | int peek(); 47 | 48 | virtual size_t write(uint8_t byte); 49 | virtual int read(); 50 | virtual int available(); 51 | virtual void flush(); 52 | operator bool() {return m_rxValid || m_txValid;} 53 | 54 | // Disable or enable interrupts on the rx pin 55 | void enableRx(bool on); 56 | 57 | void rxRead(); 58 | 59 | // AVR compatibility methods 60 | bool listen() { enableRx(true); return true; } 61 | void end() { stopListening(); } 62 | bool isListening() { return m_rxEnabled; } 63 | bool stopListening() { enableRx(false); return true; } 64 | 65 | using Print::write; 66 | 67 | private: 68 | bool isValidGPIOpin(int pin); 69 | 70 | // Member variables 71 | int m_rxPin, m_txPin, m_txEnablePin; 72 | bool m_rxValid, m_rxEnabled; 73 | bool m_txValid, m_txEnableValid; 74 | bool m_invert; 75 | bool m_overflow; 76 | unsigned long m_bitTime; 77 | unsigned int m_inPos, m_outPos; 78 | int m_buffSize; 79 | uint8_t *m_buffer; 80 | 81 | }; 82 | 83 | // If only one tx or rx wanted then use this as parameter for the unused pin 84 | #define SW_SERIAL_UNUSED_PIN -1 85 | 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Software serial multple serial test 3 | 4 | Receives from the hardware serial, sends to software serial. 5 | Receives from software serial, sends to hardware serial. 6 | 7 | The circuit: 8 | * RX is digital pin 10 (connect to TX of other device) 9 | * TX is digital pin 11 (connect to RX of other device) 10 | 11 | Note: 12 | Not all pins on the Mega and Mega 2560 support change interrupts, 13 | so only the following can be used for RX: 14 | 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 15 | 16 | Not all pins on the Leonardo support change interrupts, 17 | so only the following can be used for RX: 18 | 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). 19 | 20 | created back in the mists of time 21 | modified 25 May 2012 22 | by Tom Igoe 23 | based on Mikal Hart's example 24 | 25 | This example code is in the public domain. 26 | 27 | */ 28 | #include 29 | 30 | SoftwareSerial mySerial(10, 11); // RX, TX 31 | 32 | void setup() 33 | { 34 | // Open serial communications and wait for port to open: 35 | Serial.begin(57600); 36 | while (!Serial) { 37 | ; // wait for serial port to connect. Needed for Leonardo only 38 | } 39 | 40 | 41 | Serial.println("Goodnight moon!"); 42 | 43 | // set the data rate for the SoftwareSerial port 44 | mySerial.begin(4800); 45 | mySerial.println("Hello, world?"); 46 | } 47 | 48 | void loop() // run over and over 49 | { 50 | if (mySerial.available()) 51 | Serial.write(mySerial.read()); 52 | if (Serial.available()) 53 | mySerial.write(Serial.read()); 54 | } 55 | 56 | -------------------------------------------------------------------------------- /SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Software serial multple serial test 3 | 4 | Receives from the two software serial ports, 5 | sends to the hardware serial port. 6 | 7 | In order to listen on a software port, you call port.listen(). 8 | When using two software serial ports, you have to switch ports 9 | by listen()ing on each one in turn. Pick a logical time to switch 10 | ports, like the end of an expected transmission, or when the 11 | buffer is empty. This example switches ports when there is nothing 12 | more to read from a port 13 | 14 | The circuit: 15 | Two devices which communicate serially are needed. 16 | * First serial device's TX attached to digital pin 2, RX to pin 3 17 | * Second serial device's TX attached to digital pin 4, RX to pin 5 18 | 19 | Note: 20 | Not all pins on the Mega and Mega 2560 support change interrupts, 21 | so only the following can be used for RX: 22 | 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 23 | 24 | Not all pins on the Leonardo support change interrupts, 25 | so only the following can be used for RX: 26 | 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). 27 | 28 | created 18 Apr. 2011 29 | modified 25 May 2012 30 | by Tom Igoe 31 | based on Mikal Hart's twoPortRXExample 32 | 33 | This example code is in the public domain. 34 | 35 | */ 36 | 37 | #include 38 | // software serial #1: TX = digital pin 10, RX = digital pin 11 39 | SoftwareSerial portOne(10,11); 40 | 41 | // software serial #2: TX = digital pin 8, RX = digital pin 9 42 | // on the Mega, use other pins instead, since 8 and 9 don't work on the Mega 43 | SoftwareSerial portTwo(8,9); 44 | 45 | void setup() 46 | { 47 | // Open serial communications and wait for port to open: 48 | Serial.begin(9600); 49 | while (!Serial) { 50 | ; // wait for serial port to connect. Needed for Leonardo only 51 | } 52 | 53 | 54 | // Start each software serial port 55 | portOne.begin(9600); 56 | portTwo.begin(9600); 57 | } 58 | 59 | void loop() 60 | { 61 | // By default, the last intialized port is listening. 62 | // when you want to listen on a port, explicitly select it: 63 | portOne.listen(); 64 | Serial.println("Data from port one:"); 65 | // while there is data coming in, read it 66 | // and send to the hardware serial port: 67 | while (portOne.available() > 0) { 68 | char inByte = portOne.read(); 69 | Serial.write(inByte); 70 | } 71 | 72 | // blank line to separate data from the two ports: 73 | Serial.println(); 74 | 75 | // Now listen on the second port 76 | portTwo.listen(); 77 | // while there is data coming in, read it 78 | // and send to the hardware serial port: 79 | Serial.println("Data from port two:"); 80 | while (portTwo.available() > 0) { 81 | char inByte = portTwo.read(); 82 | Serial.write(inByte); 83 | } 84 | 85 | // blank line to separate data from the two ports: 86 | Serial.println(); 87 | } 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /SoftwareSerial/examples/swsertest/swsertest.ino: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | SoftwareSerial swSer(14, 12, false, 256); 5 | 6 | void setup() { 7 | Serial.begin(115200); 8 | swSer.begin(115200); 9 | 10 | Serial.println("\nSoftware serial test started"); 11 | 12 | for (char ch = ' '; ch <= 'z'; ch++) { 13 | swSer.write(ch); 14 | } 15 | swSer.println(""); 16 | 17 | } 18 | 19 | void loop() { 20 | while (swSer.available() > 0) { 21 | Serial.write(swSer.read()); 22 | } 23 | while (Serial.available() > 0) { 24 | swSer.write(Serial.read()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /SoftwareSerial/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map for NewSoftSerial 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | NewSoftSerial KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | begin KEYWORD2 16 | end KEYWORD2 17 | read KEYWORD2 18 | available KEYWORD2 19 | isListening KEYWORD2 20 | overflow KEYWORD2 21 | flush KEYWORD2 22 | listen KEYWORD2 23 | 24 | ####################################### 25 | # Constants (LITERAL1) 26 | ####################################### 27 | 28 | --------------------------------------------------------------------------------