YARP
Yet Another Robot Platform
SerialDeviceDriver.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2007 Alexandre Bernardino
4  * Copyright (C) 2007 Carlos Beltran-Gonzalez
5  * Copyright (C) 2007 Francesco Giovannini
6  * All rights reserved.
7  *
8  * This software may be modified and distributed under the terms of the
9  * BSD-3-Clause license. See the accompanying LICENSE file for details.
10  */
11 
12 #ifndef SerialDeviceDriverh
13 #define SerialDeviceDriverh
14 
15 #include <yarp/dev/DeviceDriver.h>
16 #include <yarp/dev/ISerialDevice.h>
17 #include <yarp/os/Bottle.h>
18 
19 #include <stdio.h>
20 
21 #include <ace/DEV_Connector.h>
22 #include <ace/TTY_IO.h>
23 // In one the ACE headers there is a definition of "main" for WIN32
24 # ifdef main
25 # undef main
26 # endif
27 
28 
29 using namespace yarp::os;
30 
32 {
33 public:
34  char CommChannel[100]; // Contains the name of the com port "COM1", "COM2" (windows) or "/etc/stty0", "/dev/stty1" (linux), etc...
35  ACE_TTY_IO::Serial_Params SerialParams;
71 };
72 
81 {
82 private:
84  void operator=(const SerialDeviceDriver&);
85 
86  ACE_TTY_IO _serial_dev;
87  ACE_DEV_Connector _serialConnector;
88  bool verbose; // If enabled (1), the data sent/received by the serial device is print on screen
89  char line_terminator_char1;
90  char line_terminator_char2;
91 
92 public:
94 
95  virtual ~SerialDeviceDriver();
96 
97  bool open(yarp::os::Searchable& config) override;
98 
104  bool open(SerialDeviceDriverSettings& config);
105 
106  bool close() override;
107 
113  bool send(const Bottle& msg) override;
114  bool send(char *msg, size_t size) override;
115  //bool putMessage(Bottle& msg, bool waitreply, double replytimeout, Bottle& reply, char *replydelimiter, int replysize );
121  bool receive(Bottle& msg) override;
127  int receiveChar(char& chr) override;
128 
135  int receiveBytes(unsigned char* bytes, const int size) override;
136 
143  int receiveLine(char* line, const int MaxLineLength) override;
144 
150  bool setDTR(bool value) override;
151 
156  int flush() override;
157 };
158 
159 #endif
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
yarp::dev::ISerialDevice
A generic interface to serial port devices.
Definition: ISerialDevice.h:28
SerialDeviceDriver
serialport: A basic Serial Communications Link (RS232, USB).
Definition: SerialDeviceDriver.h:81
ISerialDevice.h
SerialDeviceDriverSettings::SerialParams
ACE_TTY_IO::Serial_Params SerialParams
Definition: SerialDeviceDriver.h:35
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
SerialDeviceDriverSettings
Definition: SerialDeviceDriver.h:32
Bottle.h
DeviceDriver.h