Introduction

Intended audience

Process experts and system integrators who want to develop solutions based on the modeling of industrial continuous processes with the LIBPF™ enabling technology.

Scope

Give a basic, step-by-step tutorial for your first “Hello, world!” program with LIBPF™.

Prerequisites

  1. Basic C++ skills

  2. properly configured Windows or Linux LIBPF™ development workstation

  3. downloaded and installed the LIBPF™ SDK.

Step-by-step

  1. Create a new C++ file with this content:

    #include <libpf/utility/diagnostic.h> // for the diagnostic macro
    #include <libpf/utility/Error.h> // for Error
    #include <libpf/Libpf.h> // for components, initializeLibpf and uninitializeLibpf
    
    static const int verbosityFile = 0;
    static const int verbosityInstance = 0;
    
    int main(int /* argc */, char * /*argv */ []) {
      const int verbosityLocal = 0;
      diagnostic(0, "Entered");
      try {
        // initializations
        initializeLibpf();
    
        diagnostic(0, "Hello, world !");
    
        uninitializeLibpf();
        return 0;
      } // try
      catch (Error &e) {
        uninitializeLibpf();
        e.append(CURRENT_FUNCTION);
        std::cerr << "****************************** Fatal LIBPF error! ******************************" << std::endl;
        std::cerr << e.message() << std::endl;
        return -1;
      } // catch
    } // main
    
  2. copy the supplied kernel.vcxproj to helloworld.vcxproj

  3. open the new Visual Studio project, add new C++ file to the project, see Step-by-step guide: adding new files to a LIBPF project

  4. compile & run; expected output:

    LIBPF is correctly activated for site com.example_1.0 on this computer.
    main * Entered
    * ****************** LIBPF 01.00.2193 [2015/06/07 15:28:37] ******************
    * (C) Copyright 2004-2015 Paolo Greppi simevo s.r.l.
    * ****************************************************************************
    * All rights reserved; do not distribute without permission.
    * ****************************************************************************
    
    main * Hello, world !
    

Explanation

  • the include statements pull in the required declarations from the library; as a bare minimum you will need:

    • libpf/utility/diagnostic.h for the diagnostic system

    • libpf/utility/Error.h for the Error class, and exception handling

    • libpf/Libpf.h for initializeLibpf and uninitializeLibpf

  • some variables are required to allow the operation of diagnostic system - see the related paragraph in the LIBPF™ SDK Developer manual:

  • verbosityFile is an integer variable that is to be defined in each compilation unit

  • verbosityLocal is an integer variable that must be defined in each function (therefore also in main)

  • verbosityInstance is an integer variable that should be defined in each class; since the main function is not a class member function, a dummy verbosityInstance should be defined too.

  • the try block try {...} contains commands that can result in exceptions from the library - see the related paragraph in the LIBPF™ SDK Developer manual.

  • the catch block catch (Error & e) {...} contains the commands that must be run when an unrecoverable exception has been thrown and you must exit the program immediately; note that the uninitializeLibpf command is repeated here to exit gratefully.

  • the initializations for the libraries must be performed before any functionality is used, this is done by calling the initializeLibpf function

  • at the end of the work call the uninitializeLibpf function to clean up

  • the actual hallo world statement is done with a call to the diagnostic system:

    diagnostic(0, "Hello, world !");
    

    with a verbosity level 0, which is for important messages that are printed during normal operation.

How to get on

  1. Proceed to the other tutorials