YARP
Yet Another Robot Platform
SerialDeviceDriver.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2007 Alexandre Bernardino
4  * SPDX-FileCopyrightText: 2007 Carlos Beltran-Gonzalez
5  * SPDX-FileCopyrightText: 2007 Francesco Giovannini
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef SerialDeviceDriverh
10 #define SerialDeviceDriverh
11 
12 #include <yarp/dev/DeviceDriver.h>
13 #include <yarp/dev/ISerialDevice.h>
14 #include <yarp/os/Bottle.h>
15 
16 #include <stdio.h>
17 
18 #include <ace/DEV_Connector.h>
19 #include <ace/TTY_IO.h>
20 // In one the ACE headers there is a definition of "main" for WIN32
21 # ifdef main
22 # undef main
23 # endif
24 
25 
26 using namespace yarp::os;
27 
29 {
30 public:
31  char CommChannel[100]; // Contains the name of the com port "COM1", "COM2" (windows) or "/etc/stty0", "/dev/stty1" (linux), etc...
32  ACE_TTY_IO::Serial_Params SerialParams;
68 };
69 
78 {
79 private:
81  void operator=(const SerialDeviceDriver&);
82 
83  ACE_TTY_IO _serial_dev;
84  ACE_DEV_Connector _serialConnector;
85  bool verbose; // If enabled (1), the data sent/received by the serial device is print on screen
86  char line_terminator_char1;
87  char line_terminator_char2;
88 
89 public:
91 
92  virtual ~SerialDeviceDriver();
93 
94  bool open(yarp::os::Searchable& config) override;
95 
101  bool open(SerialDeviceDriverSettings& config);
102 
103  bool close() override;
104 
110  bool send(const Bottle& msg) override;
111  bool send(char *msg, size_t size) override;
112  //bool putMessage(Bottle& msg, bool waitreply, double replytimeout, Bottle& reply, char *replydelimiter, int replysize );
118  bool receive(Bottle& msg) override;
124  int receiveChar(char& chr) override;
125 
132  int receiveBytes(unsigned char* bytes, const int size) override;
133 
140  int receiveLine(char* line, const int MaxLineLength) override;
141 
147  bool setDTR(bool value) override;
148 
153  int flush() override;
154 };
155 
156 #endif
ACE_TTY_IO::Serial_Params SerialParams
serialport: A basic Serial Communications Link (RS232, USB).
Interface implemented by all device drivers.
Definition: DeviceDriver.h:35
A generic interface to serial port devices.
Definition: ISerialDevice.h:25
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
A base class for nested structures that can be searched.
Definition: Searchable.h:66
An interface to the operating system, including Port based communication.