io_control.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * FSRobo-R Package BSDL
3 * ---------
4 * Copyright (C) 2019 FUJISOFT. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its contributors
14 * may be used to endorse or promote products derived from this software without
15 * specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *********************************************************************/
28 
32 #include "ros/ros.h"
34 #include <string>
35 
36 
38 
44 using std::vector;
45 
46 
47 namespace fsrobo_r_driver
48 {
49 namespace io_control
50 {
51 
53 {
54  connection_ = connection;
55  return true;
56 }
57 
58 bool IOControl::setIO(shared_int fun, shared_int address, std::vector<shared_int> &data)
59 {
60  SetIOReply reply;
61 
62  if (!sendAndReceive(fun, address, data, reply))
63  {
64  ROS_ERROR("Failed to send WRITE_SINGLE_IO command");
65  return false;
66  }
67 
68  return (reply.getResultCode() == SetIOReplyResults::SUCCESS);
69 }
70 
71 bool IOControl::sendAndReceive(shared_int fun, shared_int address, vector<shared_int> &data, SetIOReply &reply)
72 {
73  SimpleMessage req, res;
74  SetIO set_io;
75  SetIOMessage set_io_msg;
76  SetIOReplyMessage set_io_reply;
77 
78  set_io.init(fun, address, data);
79  set_io_msg.init(set_io);
80  set_io_msg.toRequest(req);
81 
82  if (!this->connection_->sendAndReceiveMsg(req, res))
83  {
84  ROS_ERROR("Failed to send SetIO message");
85  return false;
86  }
87 
88  set_io_reply.init(res);
89  reply.copyFrom(set_io_reply.reply_);
90 
91  return true;
92 }
93 
94 }
95 
96 }
bool setIO(industrial::shared_types::shared_int fun, industrial::shared_types::shared_int, std::vector< industrial::shared_types::shared_int > &data)
Writes to a single IO point on the controller.
Definition: io_control.cpp:58
fsrobo_r_driver::simple_message::io_control_reply::SetIOReply reply_
void init()
Initializes a empty write single io command.
Definition: set_io.cpp:53
Class encapsulated FSRobo-R set io reply message generation methods (either to or from a industrial::...
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
virtual bool toRequest(industrial::simple_message::SimpleMessage &msg)
Class encapsulated FSRobo-R set io message generation methods (either to or from a industrial::simple...
industrial::shared_types::shared_int getResultCode() const
Returns the result code.
Definition: set_io_reply.h:117
bool sendAndReceiveMsg(industrial::simple_message::SimpleMessage &send, industrial::simple_message::SimpleMessage &recv, bool verbose=false)
void copyFrom(SetIOReply &src)
Copies the passed in value.
Class encapsulated set io reply data. These messages are sent by the FSRobo-R controller in response ...
Definition: set_io_reply.h:73
bool sendAndReceive(industrial::shared_types::shared_int address, industrial::shared_types::shared_int value, std::vector< industrial::shared_types::shared_int > &data, SetIOReply &reply)
Definition: io_control.cpp:71
Class encapsulated write single io data. FSRobo-R specific interface to set IO element on the control...
Definition: set_io.h:60
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
bool init(SmplMsgConnection *connection)
Definition: io_control.cpp:52
#define ROS_ERROR(...)


fsrobo_r_driver
Author(s): F-ROSROBO
autogenerated on Sun Feb 9 2020 03:58:29