NMEAOnSerial example
Introduction
This guide demonstrates the usage of NMEAOnSerial component in a Linux environment to receive arbitrary data from a command line over a virtual serial connection using CDP Studio, the independent automation software for open PC-based real-time distributed control systems. To use NMEAOnSerial successfully without virtual connections, a serial loopback device or an actual NMEA capable device must be attached to the configured serial port. In this example, a Socat utility program is used to create two virtual serial connections.
Creating Virtual Connections
First, two virtual connections have to be created – one for sending data from terminal and another one for NMEAOnSerial component to receive the data.
- Install Socat utility program. More information about Socat can be found here
- Open the terminal and type
socat pty,link=/tmp/CDPCOM0,raw,echo=0 pty,link=/tmp/CDPCOM1,raw,echo=0
- Leave the terminal open for the testing period
- A similar view should be seen in the terminal
Setting up a Test-system
First we set up a System that the component can be tested in:
Create a system named NMEATest with a Console application named NMEATestApp, then select Configure mode. See How to Create a system for more information.
Adding an NMEAOnSerial Component
- Click on the default application called NMEATestApp
- Click on NMEA0183IO to expand its contents in the Resource tree
- Choose NMEAOnSerial component and add it to the default application
Adding ReceiveData To NMEAOnSerial and Configuring It
- Double-click on the NMEAOnSerial that was added
- Double-click the SerialTransport to navigate into it
- Set the ComPort Value to /tmp/CDPCOM0
- Select the NMEAOnSerial component in the Project tree
- From the Resource tree, double-click ReceiveData inside the NMEA0183IO resource to add it to NMEAOnSerial
- Double-click Receive to navigate into it
- Tick DisableChecksum. We want this disabled to simplify testing with random data
- Set Header to $T. Anything starting with $T, will now be accepted
- From the NMEA0183IO resource in the Resource tree, double-click a String resource to add it
Note: To learn about other configurable values in SerialTransport, click here.
How to Run the Tutorial
To run the tutorial from CDP Studio, select Configure mode, right-click on the system project and select Run & Connect. See the Running and Connecting to the System tutorial for more information.
Testing the System
- Navigate into NMEATestApp NMEAOnSerial Receive
- Open another terminal and type
echo '$T,My first message' > /tmp/CDPCOM1
- Watch how the data appears in the Text Value column
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.