PLC Module Guide

The PLC module is not longer supported as of

The PLC module implements custom controller models. This allows modelers to write "C" code that is a) compiled at runtime, b) able to read and write data in other objects, c) able to override or replace the default object PLC code implemented by plc_class, and d) written in a simple, familiar and efficient programming language. The PLC module also implements a network communications object that allows PLC control code objects to communicate with each other.

To define PLC objects you must load the PLC module:

The compiler used by the PLC module depends on the platform on which GridLAB-D is running. For Windows systems, the compiler is MinGW Version 5.1.3, which can be downloaded from SourceForge or from the PNNL GridLAB-D website at http://www.gridlabd.org/downloads/MinGW-5.1.3.exe. On Linux systems, the native compiler is used. The PATH environment variable is used to locate the compiler executable gcc.

The runtime libraries and include files are required for PLC code to be compiled and linked when a model is loaded. These must be specified correctly for your installation. Typically, these are installed in the etc/rt/include and etc/rt/lib folders in the GridLAB-D folder.

PLC objects implement a machine internally which is built from the PLC code. The machine is compiled, linked and converted to a .dll or .so file for Windows or Linux, respectively.

Note: Linux system with enhanced security must permit loading of .so files created by GridLAB-D at runtime. At this time, the simple way to do this is to disable SElinux. A better solution from a security standpoint would be to allow unconfined executables to use libraries that are not labeled texrel_shlib_t, but there seems to be no way to label anonymous libraries before they are created at runtime. See https://svn.pnl.gov/Gridlab-D/ticket/200 for more information about this issue.

Control code
PLC code is implemented in source files with the extension .plc. A PLC controller is defined using a PLC object, with the source property specifying the .plc file from which the controller is compiled:

The basic structure of a PLC controller source file is as follows:

Network communications
PLC object can communicate with each other by referencing the network over which they are linked. Use the comm object to define a communications network and reference it from the PLC objects that are connected to it.

To send a message to another object in PLC code, use the SNDMSG macro: To receive a messages from another object in PLC code, use the RCVMSG macro: