19#define MAX_FLUSHED_BYTES 10000
30 line_terminator_char1 =
'\r';
31 line_terminator_char2 =
'\n';
55 if (_serial_dev.control (ACE_TTY_IO::SETPARAMS, &config.
SerialParams) == -1)
68 this->verbose = (config.
check(
"verbose",
Value(1),
"Specifies if the device is in verbose mode (0/1).").asInt32())>0;
69 config2.SerialParams.baudrate = config.
check(
"baudrate",
Value(9600),
"Specifies the baudrate at which the communication port operates.").asInt32();
70 config2.SerialParams.xonlim = config.
check(
"xonlim",
Value(0),
"Specifies the minimum number of bytes in input buffer before XON char is sent. Negative value indicates that default value should be used (Win32)").asInt32();
71 config2.SerialParams.xofflim = config.
check(
"xofflim",
Value(0),
"Specifies the maximum number of bytes in input buffer before XOFF char is sent. Negative value indicates that default value should be used (Win32). ").asInt32();
75 config2.SerialParams.readmincharacters = config.
check(
"readmincharacters",
Value(1),
"Specifies the minimum number of characters for non-canonical read (POSIX).").asInt32();
76 config2.SerialParams.readtimeoutmsec = config.
check(
"readtimeoutmsec",
Value(100),
"Specifies the time to wait before returning from read. Negative value means infinite timeout.").asInt32();
78 std::string temp = config.
check(
"paritymode",
Value(
"EVEN"),
"Specifies the parity mode (EVEN, ODD, NONE). POSIX supports even and odd parity. Additionally Win32 supports mark and space parity modes.").asString();
79 config2.SerialParams.paritymode = temp.c_str();
80 config2.SerialParams.ctsenb = config.
check(
"ctsenb",
Value(0),
"Enable & set CTS mode. Note that RTS & CTS are enabled/disabled together on some systems (RTS/CTS is enabled if either <code>ctsenb</code> or <code>rtsenb</code> is set).").asInt32();
81 config2.SerialParams.rtsenb = config.
check(
"rtsenb",
Value(0),
"Enable & set RTS mode. Note that RTS & CTS are enabled/disabled together on some systems (RTS/CTS is enabled if either <code>ctsenb</code> or <code>rtsenb</code> is set).\n- 0 = Disable RTS.\n- 1 = Enable RTS.\n- 2 = Enable RTS flow-control handshaking (Win32).\n- 3 = Specifies that RTS line will be high if bytes are available for transmission.\nAfter transmission RTS will be low (Win32).").asInt32();
82 config2.SerialParams.xinenb = config.
check(
"xinenb",
Value(0),
"Enable/disable software flow control on input.").asInt32();
83 config2.SerialParams.xoutenb = config.
check(
"xoutenb",
Value(0),
"Enable/disable software flow control on output.").asInt32();
84 config2.SerialParams.modem = config.
check(
"modem",
Value(0),
"Specifies if device is a modem (POSIX). If not set modem status lines are ignored. ").asInt32();
85 config2.SerialParams.rcvenb = config.
check(
"rcvenb",
Value(0),
"Enable/disable receiver (POSIX).").asInt32();
86 config2.SerialParams.dsrenb = config.
check(
"dsrenb",
Value(0),
"Controls whether DSR is disabled or enabled (Win32).").asInt32();
87 config2.SerialParams.dtrdisable = config.
check(
"dtrdisable",
Value(0),
"Controls whether DTR is disabled or enabled.").asInt32();
88 config2.SerialParams.databits = config.
check(
"databits",
Value(7),
"Data bits. Valid values 5, 6, 7 and 8 data bits. Additionally Win32 supports 4 data bits.").asInt32();
89 config2.SerialParams.stopbits = config.
check(
"stopbits",
Value(1),
"Stop bits. Valid values are 1 and 2.").asInt32();
91 if (config.
check(
"line_terminator_char1",
"line terminator character for receiveLine(), default '\r'")) {
92 line_terminator_char1 = config.
find(
"line_terminator_char1").asInt32();
95 if (config.
check(
"line_terminator_char2",
"line terminator character for receiveLine(), default '\n'")) {
96 line_terminator_char2 = config.
find(
"line_terminator_char2").asInt32();
108 ACE_TTY_IO::Serial_Params arg;
109 int ret = _serial_dev.control(_serial_dev.GETPARAMS, &arg);
113 arg.dtrdisable = !value;
114 ret = _serial_dev.control(_serial_dev.SETPARAMS, &arg);
172 ssize_t
bytes_written = _serial_dev.send_n((
void *)msg, size);
234 return _serial_dev.recv((
void *)bytes, size);
237 for (i = 0; i < size ; ++i)
267 if ((
recv_ch == line_terminator_char1) || (
recv_ch == line_terminator_char2))
#define MAX_FLUSHED_BYTES
ACE_TTY_IO::Serial_Params SerialParams
bool send(const Bottle &msg) override
Sends a string of chars to the serial communications channel.
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
int receiveBytes(unsigned char *bytes, const int size) override
Gets an array of bytes (unsigned char) with size <= 'size' parameter.
int receiveLine(char *line, const int MaxLineLength) override
Gets one line (a sequence of chars with a ending '\n' or '\r') from the receive queue.
bool receive(Bottle &msg) override
Gets the existing chars in the receive queue.
int flush() override
Flushes the internal buffer.
bool setDTR(bool value) override
Enable/Disable DTR protocol.
int receiveChar(char &chr) override
Gets one single char from the receive queue.
virtual ~SerialDeviceDriver()
A simple collection of objects that can be described and transmitted in a portable way.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
A single value (typically within a Bottle).
virtual std::string asString() const
Get string value.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.