• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Product
    • Design UI
    • Develop
    • Analyze and test
    • Deploy
    • Framework and toolbox
    • Compatibility
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - CDP Core
  • SerialTransport
  • 4.11.14

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
  • List of all members, including inherited members

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
NameDescription
NameThe transport instance name
ComPortThe comport device to open. On Windows '\\.\COM1' is typically used, and on Linux '/dev/ttyS0' is typically used.
BaudRateSerial Port Baudrate to use. Note that some Serial controllers do not accept baudrates larger than 115200.
DataBitsThe number of databits to use (Typically '8')
ParityThe parity to use (Typically 'None')
StopBitsThe number of stop bits to use (Typically '1')
ProtocolThe software/hardware handshaking protocol to use (Typically 'None')
MultiDropSpecifies which kind of multidrop to use, 'None', 'HalfDuplex' or 'FullDuplex'
TimeoutThe (default) timeout in seconds to use when performing Read() and Write() functions on this transport
Modelthe 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.

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

    © Copyright 2022 CDP Technologies. Privacy and cookie policy.

    Return to top