Git Product home page Git Product logo

Comments (5)

dgoo2308 avatar dgoo2308 commented on July 18, 2024 2

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

3cky avatar 3cky commented on July 18, 2024 1

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.

3cky avatar 3cky commented on July 18, 2024 1

@dgoo2308 I've pushed the fix for RTU broadcast address writing, please test.

from mbusd.

dgoo2308 avatar dgoo2308 commented on July 18, 2024 1

@3cky

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.

dgoo2308 avatar dgoo2308 commented on July 18, 2024

@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)

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.