File Information
Library: IoT/Devices
Package: Generated
Header: IoT/Devices/SerialDeviceRemoteObject.h
Description
This class provides a simple interface for accessing a serial port.
There are two modes of operation for receiving data: polling (blocking) mode (default) and events (callback) mode.
In polling mode, repeatedly call poll() to detect if data is available, then call one of the read() methods to receive available data. The read() methods can also be called if no data is available, but will block until at least one character can be read.
In event mode the class will start a thread that polls and reads available data from the serial port, and fires the lineReceived event whenever something has been read. Since callback mode uses readLine() to receive entire lines (if possible), delimiter characters and timeout can be set via the "delimiters" (string) and "timeout" (double) properties.
Clients of the class can switch between polling and event mode by enabling or disabling the "events" feature:
setFeature("events", true);
Inheritance
Direct Base Classes: ISerialDevice, Poco::RemotingNG::RemoteObject
All Base Classes: IDevice, ISerialDevice, Poco::OSP::Service, Poco::RefCountedObject, Poco::RemotingNG::Identifiable, Poco::RemotingNG::RemoteObject
Member Summary
Member Functions: available, event__lineReceived, event__statusChanged, getFeature, getPropertyBool, getPropertyDouble, getPropertyInt, getPropertyInt16, getPropertyInt64, getPropertyString, getPropertyTimestamp, getRTS, hasFeature, hasProperty, poll, readByte, readLine, readString, reconfigure, remoting__enableEvents, remoting__enableRemoteEvents, remoting__hasEvents, remoting__typeId, setFeature, setPropertyBool, setPropertyDouble, setPropertyInt, setPropertyInt16, setPropertyInt64, setPropertyString, setPropertyTimestamp, setRTS, writeByte, writeString
Inherited Functions: available, duplicate, getFeature, getPropertyBool, getPropertyDouble, getPropertyInt, getPropertyInt16, getPropertyInt64, getPropertyString, getPropertyTimestamp, getRTS, hasFeature, hasProperty, isA, mutex, poll, readByte, readLine, readString, reconfigure, referenceCount, release, remoting__enableEvents, remoting__enableRemoteEvents, remoting__getURI, remoting__hasEvents, remoting__objectId, remoting__setURI, remoting__typeId, setFeature, setPropertyBool, setPropertyDouble, setPropertyInt, setPropertyInt16, setPropertyInt64, setPropertyString, setPropertyTimestamp, setRTS, type, writeByte, writeString
Types Aliases
Ptr
using Ptr = Poco::AutoPtr < SerialDeviceRemoteObject >;
Constructors
SerialDeviceRemoteObject
SerialDeviceRemoteObject(
const Poco::RemotingNG::Identifiable::ObjectId & oid,
Poco::SharedPtr < IoT::Devices::SerialDevice > pServiceObject
);
Creates a SerialDeviceRemoteObject.
Destructor
~SerialDeviceRemoteObject
virtual ~SerialDeviceRemoteObject();
Destroys the SerialDeviceRemoteObject.
Member Functions
available
virtual int available() const;
Returns the number of characters available from the internal buffer.
See also: IoT::Devices::ISerialDevice::available()
getFeature
virtual bool getFeature(
const std::string & name
) const;
Returns true if the feature with the given name is enabled, or false otherwise.
See also: IoT::Devices::IDevice::getFeature()
getPropertyBool
virtual bool getPropertyBool(
const std::string & name
) const;
Returns the value of the device property with the given name.
Throws a Poco::NotFoundException if the property with the given name is unknown.
See also: IoT::Devices::IDevice::getPropertyBool()
getPropertyDouble
virtual double getPropertyDouble(
const std::string & name
) const;
Returns the value of the device property with the given name.
Throws a Poco::NotFoundException if the property with the given name is unknown.
getPropertyInt
virtual int getPropertyInt(
const std::string & name
) const;
Returns the value of the device property with the given name.
Throws a Poco::NotFoundException if the property with the given name is unknown.
See also: IoT::Devices::IDevice::getPropertyInt()
getPropertyInt16
virtual Poco::Int16 getPropertyInt16(
const std::string & name
) const;
Returns the value of the device property with the given name.
Throws a Poco::NotFoundException if the property with the given name is unknown.
getPropertyInt64
virtual Poco::Int64 getPropertyInt64(
const std::string & name
) const;
Returns the value of the device property with the given name.
Throws a Poco::NotFoundException if the property with the given name is unknown.
getPropertyString
virtual std::string getPropertyString(
const std::string & name
) const;
Returns the value of the device property with the given name.
Throws a Poco::NotFoundException if the property with the given name is unknown.
getPropertyTimestamp
virtual Poco::Timestamp getPropertyTimestamp(
const std::string & name
) const;
Returns the value of the device property with the given name.
Throws a Poco::NotFoundException if the property with the given name is unknown.
getRTS
virtual bool getRTS() const;
Returns the RTS status.
See also: IoT::Devices::ISerialDevice::getRTS()
hasFeature
virtual bool hasFeature(
const std::string & name
) const;
Returns true if the feature with the given name is known, or false otherwise.
See also: IoT::Devices::IDevice::hasFeature()
hasProperty
virtual bool hasProperty(
const std::string & name
) const;
Returns true if the property with the given name exists, or false otherwise.
See also: IoT::Devices::IDevice::hasProperty()
poll
virtual bool poll(
double timeout
);
Waits for data to arrive at the port.
Returns true immediately if data is already in the internal buffer, or if data arrives during the specified time interval (given in seconds), otherwise false.
See also: IoT::Devices::ISerialDevice::poll()
readByte
virtual Poco::UInt8 readByte();
Reads a single character from the port.
If the internal buffer is empty, blocks until data arrives at the port.
See also: IoT::Devices::ISerialDevice::readByte()
readLine
virtual std::string readLine(
const std::string & delimiters,
double timeout
);
Reads a characters from the serial port.
Characters will be read until one of the characters specified in delimiters is encountered, or no character is received for the specified timeout (in seconds).
See also: IoT::Devices::ISerialDevice::readLine()
readString
virtual std::string readString();
Reads what's currently available from the serial port or internal buffer and returns it in data.
If the internal buffer is empty, blocks until data arrives at the port.
reconfigure
virtual void reconfigure(
int baudRate,
const std::string & parameters,
const std::string & flowControl
);
Reconfigures the serial port with the given baud rate and communication parameters.
Baud rate must be one of the following: 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200 or 230400.
Specify -1 for baudRate to use the currently configured speed. Note that not all platforms support all baud rates.
To specify character size, parity and stop bits, use the parameters argument. The parameters argument must be a three character string. The first character specifies the serial line character width in bits (5, 6, 7 or 8). The second char specifies the parity (N for none, E for even, O for odd) and the third character specifies the number of stop bits (1 or 2). Example: "8N1" for 8 bit characters, no parity, 1 stop bit.
To specify flow control, use the flowControl argument. Specify "none" or an empty string for no flow control. Specify "rtscts" for hardware (RTS/CTS) flow control.
remoting__enableEvents
virtual std::string remoting__enableEvents(
Poco::RemotingNG::Listener::Ptr pListener,
bool enable = bool (true)
);
remoting__enableRemoteEvents
virtual void remoting__enableRemoteEvents(
const std::string & protocol
);
remoting__hasEvents
virtual bool remoting__hasEvents() const;
remoting__typeId
virtual const Poco::RemotingNG::Identifiable::TypeId & remoting__typeId() const;
setFeature
virtual void setFeature(
const std::string & name,
bool enable
);
Enables or disables the feature with the given name.
Which features are supported is defined by the actual device implementation.
See also: IoT::Devices::IDevice::setFeature()
setPropertyBool
virtual void setPropertyBool(
const std::string & name,
bool value
);
Sets a device property.
Which properties are supported is defined by the actual device implementation.
See also: IoT::Devices::IDevice::setPropertyBool()
setPropertyDouble
virtual void setPropertyDouble(
const std::string & name,
double value
);
Sets a device property.
Which properties are supported is defined by the actual device implementation.
setPropertyInt
virtual void setPropertyInt(
const std::string & name,
int value
);
Sets a device property.
Which properties are supported is defined by the actual device implementation.
See also: IoT::Devices::IDevice::setPropertyInt()
setPropertyInt16
virtual void setPropertyInt16(
const std::string & name,
Poco::Int16 value
);
Sets a device property.
Which properties are supported is defined by the actual device implementation.
setPropertyInt64
virtual void setPropertyInt64(
const std::string & name,
Poco::Int64 value
);
Sets a device property.
Which properties are supported is defined by the actual device implementation.
setPropertyString
virtual void setPropertyString(
const std::string & name,
const std::string & value
);
Sets a device property.
Which properties are supported is defined by the actual device implementation.
setPropertyTimestamp
virtual void setPropertyTimestamp(
const std::string & name,
Poco::Timestamp value
);
Sets a device property.
Which properties are supported is defined by the actual device implementation.
setRTS
virtual void setRTS(
bool status
);
Manually sets or clears RTS.
See also: IoT::Devices::ISerialDevice::setRTS()
writeByte
virtual void writeByte(
Poco::UInt8 byte
);
Writes the given byte to the port.
See also: IoT::Devices::ISerialDevice::writeByte()
writeString
virtual void writeString(
const std::string & data
);
Writes the given data to the port. Returns the number of characters written.
event__lineReceived
void event__lineReceived(
const std::string & data
);
event__statusChanged
void event__statusChanged(
const IoT::Devices::DeviceStatusChange & data
);