SerialTransport Class
(CDP::IO::SerialTransport)The SerialTransport class provides base functionality for communicating using a serialport. It handles the following properties, as read from the configuration file: More...
Header: | #include <IO/SerialTransport.h> |
Inherits: | Transport |
Public Functions
SerialTransport(const std::function<unsigned int( Transport *, char *, unsigned int ) > readCallbackHandler) | |
virtual | ~SerialTransport() |
Serial * | GetTransport() |
Reimplemented Public Functions
virtual void | Close() override |
virtual void | Configure(XMLElementEx *transportElement, CDPComponent *owner) override |
virtual void | FillNodeChildren(CDP::StudioAPI::NodeStream &serializer) const override |
virtual std::string | GetNodeTypeName() const override |
virtual double | GetTimeout() const override |
virtual bool | IsError() override |
virtual bool | IsOpen() const override |
virtual bool | Open(OpenMode mode) override |
virtual unsigned int | Read(char *data, unsigned int length, double timeout = 0.0) override |
virtual unsigned int | Write(const char *data, unsigned int length, double timeout = 0.0) override |
- 12 public functions inherited from CDP::IO::Transport
- 26 public functions inherited from CDP::StudioAPI::CDPNode
- 22 public functions inherited from CDP::StudioAPI::ICDPNode
Additional Inherited Members
- 1 static public member inherited from CDP::IO::Transport
- 1 protected function inherited from CDP::StudioAPI::CDPNode
Detailed Description
The SerialTransport class provides base functionality for communicating using a serialport. It handles the following properties, as read from the configuration file:
SerialTransport Configuration Table
Name | Description |
---|---|
Name | The transport instance name |
ComPort | The comport device to open. On Windows '\\.\COM1' is typically used, and on Linux '/dev/ttyS0' is typically used. |
BaudRate | Serial Port Baudrate to use. Note that some Serial controllers do not accept baudrates larger than 115200. |
DataBits | The number of databits to use (Typically '8') |
Parity | The parity to use (Typically 'None') |
StopBits | The number of stop bits to use (Typically '1') |
Protocol | The software/hardware handshaking protocol to use (Typically 'None') |
MultiDrop | Specifies which kind of multidrop to use, 'None', 'HalfDuplex' or 'FullDuplex' |
Timeout | The (default) timeout in seconds to use when performing Read() and Write() functions on this transport |
Model | the Model name of the Transport |
See also Transport, UDPTransport, and TCPTransport.
Member Function Documentation
SerialTransport::SerialTransport(const std::function<unsigned int( Transport *, char *, unsigned int ) > readCallbackHandler)
Creates the serial class and initializes members.
[virtual]
SerialTransport::~SerialTransport()
Deletes the serial class
[override virtual]
void SerialTransport::Close()
Reimplemented from Transport::Close().
Closes the serial device
[override virtual]
void SerialTransport::Configure(XMLElementEx *transportElement, CDPComponent *owner)
Reimplemented from Transport::Configure().
Maps properties to configuration
[override virtual]
void SerialTransport::FillNodeChildren(CDP::StudioAPI::NodeStream &serializer) const
Reimplemented from CDPNode::FillNodeChildren().
Streams all the serial settings to serializer
[override virtual]
std::string SerialTransport::GetNodeTypeName() const
Reimplemented from ICDPNode::GetNodeTypeName().
Returns "SerialTransport"
[override virtual]
double SerialTransport::GetTimeout() const
Reimplemented from Transport::GetTimeout().
Returns the configured timeout
Serial *SerialTransport::GetTransport()
Returns the underlying serial transport class.
[override virtual]
bool SerialTransport::IsError()
Reimplemented from Transport::IsError().
Not implemented for serial devices as there is no uniform way to detect error. Returns false
[override virtual]
bool SerialTransport::IsOpen() const
Reimplemented from Transport::IsOpen().
Returns the device's open status
[override virtual]
bool SerialTransport::Open(OpenMode mode)
[override virtual]
unsigned int SerialTransport::Read(char *data, unsigned int length, double timeout = 0.0)
Reimplemented from Transport::Read().
Reads length bytes of data from the serial device within timeout [seconds]. If timeout<=0.0, the timeout from the configuration is used. Returns Number of bytes read. It is assumed that data is a buffer that the caller has allocated, and that it is at least length bytes long. Read will block for how long it takes to read the data, or for timeout seconds, whichever comes first.
As Read() is a blocking call, do not call it from a Process() function. See CDPComponent and OSAPIThread for more information about component threads.
[override virtual]
unsigned int SerialTransport::Write(const char *data, unsigned int length, double timeout = 0.0)
Reimplemented from Transport::Write().
Writes length amount of data to serial device Returns Number of bytes written, or 0 on error. It is assumed that data is a buffer that the caller has allocated, and that it is at least length bytes long. Write will block for how long it takes to write the data, or for timeout seconds, whichever comes first.
As Write() is a blocking call, do not call it from a Process() function. See CDPComponent and OSAPIThread for more information about component threads.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.