Comments (5)
@3cky so sorry for delay, I I'll try to squeeze the test in before my holiday next week otherwise it will be the second week of September.
I did notice for the tests that FC5 broadcast, write coil, is not tested.
from mbusd.
Thanks for pointing to this issue. The problem seems to be more complex though. Since Modbus/TCP neither specifies Unit ID 0 as a broadcast address nor defines the broadcast function at all, some of Modbus/TCP slaves (especially old ones) could use zero ID as a valid unicast slave address. But I agree mbusd should handle zero Unit ID more gracefully. I'll look into it.
from mbusd.
@dgoo2308 I've pushed the fix for RTU broadcast address writing, please test.
from mbusd.
looks very good, I did a quick test with libmodbus
in c:
int main(int argc, const char * argv[])
{
printf("ModBus version: %s\n",LIBMODBUS_VERSION_STRING);
modbus_t * CTX_Broadcast = modbus_new_tcp_pi("mbus-1.local", "502");
if (CTX_Broadcast == NULL) {
fprintf(stderr, "Unable to allocate libmodbus context\n");
return -1;
}
if (modbus_connect(CTX_Broadcast) == -1) {
fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
modbus_free(CTX_Broadcast);
return -1;
}
modbus_set_slave(CTX_Broadcast, 0);
/* output enable broadcast*/
int r=modbus_write_register(CTX_Broadcast,13,0x1);
if (r==-1)
{
fprintf(stderr, "Fail broadcast %s\n", modbus_strerror(errno));
}
modbus_close(CTX_Broadcast);
modbus_free(CTX_Broadcast);
return 0;
}
libmodbus
still complains with Fail broadcast Operation timed out
but that is an other problem to tackle.
results in a nice log without timeouts and no reply.
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn_loop(): select() returns 1
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn_open(): accepting connection from 192.168.1.75
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 queue_new_elem(): length now is 1
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn[192.168.1.75]: state now is CONN_HEADER
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn_loop(): select(): max_sd = 5, t_out = 000060:000000
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn_loop(): select() returns 1
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn[192.168.1.75]: state now is CONN_RQST_FUNC
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn_loop(): select(): max_sd = 5, t_out = 000060:000000
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn_loop(): select() returns 1
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn[192.168.1.75]: read request fc 6
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn[192.168.1.75]: state now is CONN_RQST_TAIL
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn[192.168.1.75]: request: [00][06][00][0d][00][01]
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn[192.168.1.75]: state now is CONN_TTY
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 tty: state now is TTY_RQST
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn_loop(): select(): max_sd = 4, t_out = 000060:000000
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn_loop(): select() returns 1
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 tty: written 8 bytes
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 tty: request written (total 8 bytes)
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn[192.168.1.75]: state now is CONN_HEADER
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 tty: state now is TTY_PAUSE
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn[192.168.1.75]: broadcast request sent
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn_loop(): select(): max_sd = 5, t_out = 000000:100000
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn_loop(): select() returns 0
Aug 30 16:10:06 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 tty: state now is TTY_READY
Aug 30 16:10:07 mbus-1 mbusd[912]: 30 Aug 2020 16:10:06 conn_loop(): select(): max_sd = 5, t_out = 000059:000000
Aug 30 16:10:07 mbus-1 mbusd[912]: 30 Aug 2020 16:10:07 conn_loop(): select() returns 1
Aug 30 16:10:07 mbus-1 mbusd[912]: 30 Aug 2020 16:10:07 conn_close(): closing connection from 192.168.1.75
Aug 30 16:10:07 mbus-1 mbusd[912]: 30 Aug 2020 16:10:07 queue_delete_elem(): length now is 0
Aug 30 16:10:07 mbus-1 mbusd[912]: 30 Aug 2020 16:10:07 conn_loop(): select(): max_sd = 4, t_out = 000060:000000
from mbusd.
@3cky Thanks.
Sorry but I thought mbusd
was to provide a gateway to Modbus RTU
, which (Modbus RTU
) per spec defines that:
- devices should not acknowledged a write on unitId 0
- Clients should not wait for an acknowledge, nor retry a write on unitId 0.
I can say it does get very messy when devices e.g. arduino slaves start an action on a broadcast and repeated broadcasts come in.
PS: thank for sharing this lib, works like a charm.
from mbusd.
Related Issues (20)
- tty: dropped 205 bytes HOT 2
- How to compile in mips architecture HOT 1
- How to read data from multiple RTU slaves? HOT 1
- "error in read()" error messages HOT 7
- service stops working after several hours - looking for help HOT 7
- Support more complex device names HOT 1
- /dev/ttyUSB0 is starting like /dev/ttyS0 HOT 1
- Crash due to missing `logw()` argument HOT 3
- '/W' requires an argument HOT 1
- version 0.5.1. HOT 1
- Modbus RTU - 6 Digit Holding Register HOT 2
- Missing device is retried forever [and blocks anything else] HOT 6
- publish docker image to ghcr & auto-build in github actions
- Add support to modbus ascii
- /dev/ttyS0? HOT 5
- Help with usb to RS485 - SH-U11 HOT 1
- CRC Enable/Disable HOT 3
- mbusd can support modbus function 20 (0x14) Read File Record and function 21 (0x15) Write File Record ..
- Using IOCTL for GPIO control HOT 4
- Make use of Linux RS-485 Support HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mbusd.