modbus_adapter_sto.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Pilz GmbH & Co. KG
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
19 
20 #include <sstream>
21 
23 
24 namespace prbt_hardware_support
25 {
26 
28  const ModbusApiSpec& api_spec)
29  : api_spec_(api_spec)
30  , update_sto_(std::move(update_sto_func))
31 {
32 }
33 
34 void ModbusAdapterSto::modbusMsgCallback(const ModbusMsgInStampedConstPtr& msg_raw)
35 {
37 
38  if(msg.isDisconnect())
39  {
40  ROS_ERROR("A disconnect from the modbus server happend.");
41  update_sto_(false);
42  return;
43  }
44 
45  try
46  {
48  }
49  catch(const ModbusMsgWrapperException &e)
50  {
51  ROS_ERROR_STREAM(e.what());
52  update_sto_(false);
53  return;
54  }
55 
57  {
58  std::ostringstream os;
59  os << "Received Modbus message of unsupported API Version: "
60  << msg.getVersion()
61  << ", required Version: " << MODBUS_API_VERSION_REQUIRED;
62  ROS_ERROR_STREAM(os.str());
63  update_sto_(false);
64  return;
65  }
66 
67  update_sto_(msg.getSTO());
68 }
69 
70 
71 } // namespace prbt_hardware_support
msg
std::function< void(const bool)> UpdateStoFunc
void modbusMsgCallback(const ModbusMsgInStampedConstPtr &msg_raw)
Called whenever a new modbus messages arrives.
bool getSTO() const
Get the STO from the Modbus message.
static constexpr unsigned int MODBUS_API_VERSION_REQUIRED
bool isDisconnect() const
Check if the Modbus message informs about a disconnect from the server.
virtual void checkStructuralIntegrity() const override
Calls ModbusMsgWrapper::checkStructuralIntegrity().
Wrapper class to add semantic to a raw ModbusMsgInStamped.
Expection thrown upon construction of ModbusMsgWrapperBase of the message does not contain the requir...
#define ROS_ERROR_STREAM(args)
#define ROS_ERROR(...)
ModbusAdapterSto(UpdateStoFunc &&update_sto_func, const ModbusApiSpec &api_spec)
Specifies the meaning of the holding registers.


prbt_hardware_support
Author(s):
autogenerated on Thu Mar 19 2020 03:13:27