Skip to content

Commit 8af36b8

Browse files
catch modbus send error
1 parent 878a1ea commit 8af36b8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Modbus_TCP_Slave.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ bool Slave::handle_request() {
7575

7676
if (rc > 0) {
7777
// handle request
78-
modbus_reply(modbus, query, rc, mapping);
78+
int ret = modbus_reply(modbus, query, rc, mapping);
79+
if (ret == -1) {
80+
const std::string error_msg = modbus_strerror(errno);
81+
throw std::runtime_error("modbus_reply failed: " + error_msg + ' ' + std::to_string(errno));
82+
}
7983
} else if (rc == -1) {
8084
if (errno == ECONNRESET) return true;
8185

0 commit comments

Comments
 (0)