/** Instantiate a Context */
rtu_context_ = modbus_new_rtu(device_description_.c_str(), baud_, parity_, data_bit_, stop_bit_);
if (rtu_context_ == nullptr) {
return static_cast<uint32_t>(errno);
}
/** Adding the Slave Address to the Context (Device Connection) */
auto ret = modbus_set_slave(rtu_context_, static_cast<int>(device_address_));
if (ret == -1) {
return static_cast<uint32_t>(errno);
}
SPDLOG_DEBUG("modbus_set_slave ret={}", ret);
/** Connecting to Device */
ret = modbus_connect(rtu_context_);
if (ret == -1) {
return static_cast<uint32_t>(errno);
}
SPDLOG_DEBUG("modbus_connect ret={}", ret);
SPDLOG_DEBUG("Connected");
Actual behavior if applicable
This code above works really good when the servo is ON with the cable connected.
However, when the cable is unplug or the device is off, I was hoping to have an error being returned and definitely NOT see the message "Connected" printed. This is what I get.
libmodbus version
OS and/or distribution
Environment
I am using a
SV2M-220N
servo driver, which I connect via RTUDescription
I have this code
Actual behavior if applicable
This code above works really good when the servo is ON with the cable connected. However, when the cable is unplug or the device is off, I was hoping to have an error being returned and definitely NOT see the message
"Connected"
printed. This is what I get.I only get something different than this, with I provide a
device_description_
that does not exists.Expected behavior or suggestion
To receive errors in the return of the functions
modbus_new_rtu
,modbus_set_slave
andmodbus_connect
according to the online documentation.Steps to reproduce the behavior (commands or source code)
Provided above.
libmodbus output with debug mode enabled
Code with debug set:
Output
PS: The only error I am getting when not having a connection is
connection time out
s from read and write operation.