Giter VIP home page Giter VIP logo

epsilonrt / modbus-arduino Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andresarmento/modbus-arduino

4.0 4.0 1.0 1.04 MB

A library that allows your Arduino to communicate via Modbus protocol, acting as a slave. Application layer library (OSI 7), used by all implementations over serial line and TCP/IP.

Home Page: https://epsilonrt.github.io/modbus-arduino/

License: BSD 3-Clause "New" or "Revised" License

C++ 61.77% Objective-C 38.23%

modbus-arduino's People

Contributors

andresarmento avatar epsilonrt avatar michal-konopinski avatar skefer avatar tomatlab avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

clam-

modbus-arduino's Issues

Writing more than 2 registers is wrong

When we write 2 registers it works:

~$ mbpoll -a10 -b38400 -P none -t4 -r25 com4 2 1
mbpoll 1.5 - FieldTalk(tm) Modbus(R) Master Simulator
Copyright (c) 2015-2023 Pascal JEAN, https://github.com/epsilonrt/mbpoll
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions; type 'mbpoll -w' for details.

Protocol configuration: Modbus RTU
Slave configuration...: address = [10]
                        start reference = 25, count = 2
Communication.........: com4,      38400-8N1
                        t/o 1.00 s, poll rate 1000 ms
Data type.............: 16-bit register, output (holding) register table

Written 2 references.

But 3 it doesn't work!

~$ mbpoll -a10 -b38400 -P none -t4 -r27 com4 2 0 0 -v
debug enabled
Set mode to RTU for serial port
Set device=com4
3 write data have been found
Set data=2
Word[0]=0x2
Set data=0
Word[1]=0x0
Set data=0
Word[2]=0x0
mbpoll 1.5 - FieldTalk(tm) Modbus(R) Master Simulator
Copyright (c) 2015-2023 Pascal JEAN, https://github.com/epsilonrt/mbpoll
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions; type 'mbpoll -w' for details.

Opening com4 at 38400 bauds (N, 8, 1)
Set response timeout to 1 sec, 0 us
Protocol configuration: Modbus RTU
Slave configuration...: address = [10]
                        start reference = 27, count = 3
Communication.........: com4,      38400-8N1
                        t/o 1.00 s, poll rate 1000 ms
Data type.............: 16-bit register, output (holding) register table

[0A][10][00][1A][00][03][06][00][02][00][00][00][00][A4][7E]
Waiting for a confirmation...
<0A><86><03><73><A3>
ERROR Invalid exception code
Write output (holding) register failed: Invalid exception code

ESP32C3 hang when Coil read 8n's coil

Whole Modbus program hang when read 8 or 16 or 8*n coils using Read Coil Status (FC=01).
However it is normal when read 1-7 ,9-15 , 17-23 , etc.
The loop is still running. Seem something overflow in the program.

2023/04/08 23:17:24 >>> 0E 01 00 00 00 08 3D 33
2023/04/08 23:17:24 < 0E 01 01 2A D3 43 43 4F 52 52 55 50 54 20 48 45 41 50 3A 20 42 61 64 20 74 61 69 6C 20 61 74 20 30 78 33 66 63 39 31 37 34 37 2E 20 45 78 70 65 63 74 65 64 20 30 78 62 61 61 64 35 36 37 38 20 67 6F 74 20 30 78 62 61 61 64 35 36 66 38 0D 0A

warning: 'char* strncpy(char*, const char*, size_t)'

PACKAGES:

  • framework-arduinoteensy @ 1.158.0 (1.58)
  • tool-teensy @ 1.158.0 (1.58)
  • toolchain-gccarmnoneeabi-teensy @ 1.110301.0 (11.3.1)
.pio\libdeps\teensy41\Modbus-Arduino\src\Modbus.cpp: In member function 'void Modbus::reportServerId()':
.pio\libdeps\teensy41\Modbus-Arduino\src\Modbus.cpp:697:13: warning: 'char* strncpy(char*, const char*, size_t)' specified bound depends on the length of the source argument [-Wstringop-truncation]
  697 |     strncpy ( (char *) &_frame[4], _additional_data, strlen (_additional_data));

ESP32C3 hang when Coil read 8n's coil.

Whole Modbus program hang when read 8 or 16 or 8*n coils using Read Coil Status (FC=01).
However it is normal when read 1-7 ,9-15 , 17-23 , etc.
The loop is still running. Seem something overflow in the program.

2023/04/08 23:17:24 >>> 0E 01 00 00 00 08 3D 33
2023/04/08 23:17:24 < 0E 01 01 2A D3 43 43 4F 52 52 55 50 54 20 48 45 41 50 3A 20 42 61 64 20 74 61 69 6C 20 61 74 20 30 78 33 66 63 39 31 37 34 37 2E 20 45 78 70 65 63 74 65 64 20 30 78 62 61 61 64 35 36 37 38 20 67 6F 74 20 30 78 62 61 61 64 35 36 66 38 0D 0A

Speedup in searching TRegister entries

Howdy epsilonrt,

please find attached a patch for a hash based approach in order to map Modbus addresses to a TRegister
struct. In my specific case with 96 holding regs, 96 input regs, 96 coils, 96 discrete inputs I observed a
speedup of factor 5 in my main loop. I believe this is worth the expense of 28 extra RAM bytes in a
Modbus object.

BR,
Christian

modbus.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.