11/*
22 * Copyright (C) 2022 Nikolas Koesling <nikolas@koesling.info>.
3- * This program is free software. You can redistribute it and/or modify it under the terms of the MIT License.
3+ * This program is free software. You can redistribute it and/or modify it under the terms of the GPLv3 License.
44 */
55
66#include " Modbus_TCP_Client_poll.hpp"
@@ -198,6 +198,8 @@ void Client_Poll::set_debug(bool debug) {
198198 const std::string error_msg = modbus_strerror (errno);
199199 throw std::runtime_error (" failed to enable modbus debugging mode: " + error_msg);
200200 }
201+
202+ this ->debug = debug;
201203}
202204
203205struct timeout_t {
@@ -222,7 +224,7 @@ void Client_Poll::set_byte_timeout(double timeout) {
222224
223225 if (ret != 0 ) {
224226 const std::string error_msg = modbus_strerror (errno);
225- throw std::runtime_error (" modbus_receive failed: " + error_msg + ' ' + std::to_string (errno));
227+ throw std::runtime_error (" modbus_set_byte_timeout failed: " + error_msg + ' ' + std::to_string (errno));
226228 }
227229}
228230
@@ -232,7 +234,7 @@ void Client_Poll::set_response_timeout(double timeout) {
232234
233235 if (ret != 0 ) {
234236 const std::string error_msg = modbus_strerror (errno);
235- throw std::runtime_error (" modbus_receive failed: " + error_msg + ' ' + std::to_string (errno));
237+ throw std::runtime_error (" modbus_set_response_timeout failed: " + error_msg + ' ' + std::to_string (errno));
236238 }
237239}
238240
@@ -380,6 +382,7 @@ Client_Poll::run_t Client_Poll::run(int signal_fd, bool reconnect, int timeout)
380382
381383 uint8_t query[MODBUS_TCP_MAX_ADU_LENGTH];
382384 int rc = modbus_receive (modbus, query);
385+ if (debug) std::cout.flush ();
383386
384387 if (rc > 0 ) {
385388 const auto CLIENT_ID = query[6 ];
@@ -409,6 +412,7 @@ Client_Poll::run_t Client_Poll::run(int signal_fd, bool reconnect, int timeout)
409412
410413 int ret = modbus_reply (modbus, query, rc, mapping);
411414 if (semaphore && semaphore->is_acquired ()) semaphore->post ();
415+ if (debug) std::cout.flush ();
412416
413417 if (ret == -1 ) {
414418 std::cerr << Print_Time::iso << " ERROR: modbus_reply failed: " << modbus_strerror (errno)
0 commit comments