Skip to content

Commit 1742e7f

Browse files
flush stdout after each modbus receive/reply when --monitor is enabled
1 parent 05e9a8b commit 1742e7f

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/Modbus_TCP_Client_poll.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

203205
struct timeout_t {
@@ -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)

src/Modbus_TCP_Client_poll.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class Client_Poll {
2828
const std::size_t max_clients;
2929
std::vector<struct pollfd> poll_fds;
3030

31+
bool debug = false; //!< modbus debugging enabled
32+
3133
modbus_t *modbus; //!< modbus object (see libmodbus library)
3234
modbus_mapping_t
3335
*mappings[MAX_CLIENT_IDS]; //!< modbus data objects (one per possible client id) (see libmodbus library)

0 commit comments

Comments
 (0)