Closed killdaclick closed 9 years ago
If you write debug messages on the serial bus whereas you have Modbus devices connected on this bus, I'm not surprised you have communication issues!
PS: write() function has finished but your messages send garbage on the bus and it disturbs other devices which certainly sends unexpected data (that why reading fails). You can enable the debug mode to see that.
Consider following code:
as you can see flag Kernel::MSG_LEVEL::DONT_LOG_TO_FILE is comment out in that example and everything is working fine. When we uncomment the flag method Kernel::message() logs everything to opened file using linux write() function, which causes function modbus_read_registers() to timeout always even if timeout are set to high values like 10 seconds.
Again commenting out write() or uncommenting Kernel::MSG_LEVEL::DONT_LOG_TO_FILE make libmodbus responsive again.
As I understand libmodbus uses write() to send data (??) so I assume that write() function does not finish writing to file descriptor and modbus_read_registers() is timedout?