Add SparkplugB to existing CODESYS project

hermsen i-campbell
There is a newer version of this page. You can find it here.



Project Members:

Sparkplug™ and the Sparkplug™ logo are trademarks of the Eclipse Foundation
Copyright © 10/11/19 Eclipse Foundation, Inc. https://www.eclipse.org/legal/efsl.php

Add SparkplugB to an existing CODESYS project

Information and guides
Sparkplug™ information | Preview how-to | Setup a test system with Ignition Primary Host | Add SparkplugB to existing CODESYS project

This page
Introduction | Update | Testing

Introduction

  1. This guide takes the open source project, meatforge and makes its variables available to a SparkplugB SCADA/IIoT Host Node.
  2. If you don’t have a SparkplugB test system up and running, you can use our lightweight Primary Host Node which is demonstrated in our [Preview how-to] or
  3. You can follow the guide at [Setup a test system with Ignition Primary Host].
  4. This guide uses an outdated version of the code, the latest version has been significantly updated and is more user friendly.

Update

  1. Download and open the meatforge project
  2. Update the project to your actual system
  3. Double click Device > Application > Library Manager
  4. Press the Add Library button and add the SparkplugB library
  5. Right click application and Add Object > POU. Call it Sparkplug, Type: Program, Language: ST.
  6. Open the new POU and add an EoN : SparkplugB.FB_Edge_Of_Network_Node;
  7. Click the first line of the implementation part of this POU and press F2 to bring up the Input Assistant. Categories > Instance Calls > EoN > Tick “Insert with arguments” > OK
  8. You should now have this view:
  9. Fill in your server connection settings, eg:
  10. Now there are only a few variables in this project. We need to create a SparkplugB.FB_SimpleValue for each of them, but in an array. Note that each datatype has its own array, and the nature of VAR_IN_OUT means that each array is required.
    PRG_PWM.rDuty: REAL;
    PRG_REGULATOR.rTempSet: REAL;
    SPI_Temperature.rValue : REAL;
    xOut: BOOL;
    a. Declare the necessary arrays. Unused array can be declared with 0 elements =p

    b. Add the new arrays to the EoN call.

    c. Write the names and copy the values in code:

    d. Add a new task for this new POU, or use an existing one.

Testing

  1. Now run it and see if you get the values into your Sparkplug B SCADA / IIoT Host Node