Products
  • Running C Code on a PLC

Running C Code on a PLC


Almost all PLC programming makes use of IEC 61131-3 programming languages such as Ladder Diagram, Structured Text, or Function Block Diagram, which can at times limit the functionality of a control system. Fortunately, GE’s PLCs have the option of using C function blocks thanks to the PACSystems C Programmer’s Toolkit, which can allow complex tasks to be handled much easier, ultimately leading to a more streamlined process with greater functionality.

In this Tech Tip, we’ll show you how to create and run blocks of C code on a Rx3i system using Proficy Machine Edition (PME).  

Creating and compiling your code

First, download and install the C Programmer’s Toolkit for PACSystems here.

The next step is to write some code you’d like to run on your PLC. You can do this in any text editor as long as the file is a .c format and is saved in the toolkit’s directory (C:\GE Software\PACSystemsCToolkit\Projects). Here is an example program which scales a 4-20mA signal to a 0-10,000 range (rescaling). 


This program makes use of the Interpolation Formula: 



There are a few things to note here:

  • You must include the PACRCPlc.h file;
  • The main program must be called GefMain;
  • Inputs AND outputs must be in the declaration of GefMain;
  • The datatypes of the inputs and outputs have different syntaxes. For example, a T_REAL32 is the same as a float in normal C;
  • Inputs and outputs must be referenced as pointers when called, and
  • GefMain must always return GEF_EXECUTION_OK.
Once your program is ready, run the Toolkit console and navigate to the directory your program is in. Compile the program by running the compileCPACRX <filename> command. After the program has been successfully compiled, a folder called plc will appear in the directory. Within the plc folder will be a file titled <filename>.gefElf.

Incorporating code into PME

Set up the hardware configuration and communication settings so that you can get online to your PLC. In the Navigator window, expand the Target and then Logic menu to show the Program Blocks. 

 
Right click on Program Blocks and click Add C Block. Select the .gefElf file in the plc folder from earlier. Once the C block has been added, we need to set the input and output parameters for it. Do this by right-clicking the block, in this case Scaling Example, and click properties. In the Inspector window that opens, click the three dots in the parameters section.  

 
Set the input and output parameters for the block. In this example we have an Input which is a REAL, and an Output which is also a REAL.

C blocks are added to programs via CALL functions. Place a call function in a program by selecting where you want the block to appear and type CALL. Once the call block has been placed, double-click it and select the C block you wish to call. Populate the inputs and outputs with variables and we’re done!  

 

Above is the program running on an Rx3i, showing an input of 12.5 being rescaled to an output of 5312.5.

Now you should be able to write more complex code in standard C and incorporate it into your PLC system. 
Select location
Panasonic PLC Training
PANASONIC PLC FP0R TRAINING 1 DAYS IN BRISBANE INCLUDES AFP0RC14RS + FP0R-CABLE-USB TR-PANA-FP0R-QLD
Increase value Decrease value
Panasonic PLC Training
PANASONIC PLC FP0R TRAINING 1 DAYS IN MELBOURNE INCLUDES AFP0RC14RS + FP0R-CABLE-USB TR-PANA-FP0R-VIC
Increase value Decrease value
Panasonic PLC Training
PANASONIC PLC FP0R TRAINING 1 DAYS IN SYDNEY INCLUDES AFP0RC14RS + FP0R-CABLE-USB TR-PANA-FP0R-NSW
Increase value Decrease value
Panasonic PLC Training
PANASONIC PLC FP0R TRAINING 1 DAYS IN PERTH INCLUDE AFP0RC14RS + FP0R-CABLE-USB TR-PANA-FP0R-WA
Increase value Decrease value
Panasonic PLC Training
PANASONIC PLC FP0R TRAINING 1 DAYS IN ADELAIDE INCLUDES AFP0RC14RS + FP0R-CABLE-USB TR-PANA-FP0R-SA
Increase value Decrease value
Panasonic PLC Training
PANASONIC PLC FPX TRAINING 1 DAYS IN BRISBANE INCLUDES AFPX-C30RD + CBLUSB00 TR-PANA-FPX-QLD
Increase value Decrease value
Panasonic PLC Training
PANASONIC PLC FPX TRAINING 1 DAYS IN MELBOURNE INCLUDES AFPX-C30RD + CBLUSB00 TR-PANA-FPX-VIC
Increase value Decrease value
Panasonic PLC Training
PANASONIC PLC FPX TRAINING 1 DAYS IN SYDNEY INCLUDES AFPX-C30RD + CBLUSB00 TR-PANA-FPX-NSW
Increase value Decrease value
Panasonic PLC Training
PANASONIC PLC FPX TRAINING 1 DAYS IN PERTH INCLUDES AFPX-C30RD + CBLUSB00 TR-PANA-FPX-WA
Increase value Decrease value
Panasonic PLC Training
PANASONIC PLC FPX TRAINING 1 DAYS IN ADELAIDE INCLUDES AFPX-C30RD + CBLUSB00 TR-PANA-FPX-SA
Increase value Decrease value
Mission Critical Industrial Ethernet Course
HIRSCHMANN 1DAY TRAINING MISSION CRITICAL IND ETHERNET INCLUDES (942 291-001) TR-ETH-QLD
Increase value Decrease value
Mission Critical Industrial Ethernet Course
HIRSCHMANN 1DAY TRAINING MISSION CRITICAL IND ETHERNET INCLUDES (942 291-001) TR-ETH-VIC
Increase value Decrease value
Mission Critical Industrial Ethernet Course
HIRSCHMANN 1DAY TRAINING MISSION CRITICAL IND ETHERNET INCLUDES (942 291-001) TR-ETH-NSW
Increase value Decrease value
Mission Critical Industrial Ethernet Course
HIRSCHMANN 1DAY TRAINING MISSION CRITICAL IND ETHERNET INCLUDES (942 291-001) TR-ETH-WA
Increase value Decrease value
Mission Critical Industrial Ethernet Course
HIRSCHMANN 1DAY TRAINING MISSION CRITICAL IND ETHERNET INCLUDES (942 291-001) TR-ETH-SA
Increase value Decrease value
Hirschmann Operating System - HiOS Layer 2 Software
HIRSCHMANN HiOS L2 TRAINING 3 DAYS IN BRISBANE INCLUDES 943 993-471 (VOUCHER) TR-HIRS-HIOS2-QLD
Increase value Decrease value
Hirschmann Operating System - HiOS Layer 2 Software
HIRSCHMANN HiOS L2 TRAINING 3 DAYS IN MELBOURNE INCLUDES 943 993-471 (VOUCHER) TR-HIRS-HIOS2-VIC
Increase value Decrease value
Hirschmann Operating System - HiOS Layer 2 Software
HIRSCHMANN HiOS L2 TRAINING 3 DAYS IN SYDNEY INCLUDES 943 993-471 (VOUCHER) TR-HIRS-HIOS2-NSW
Increase value Decrease value
Hirschmann Operating System - HiOS Layer 2 Software
HIRSCHMANN HiOS L2 TRAINING 3 DAYS IN PERTH INCLUDES 943 993-471 (VOUCHER) TR-HIRS-HIOS2-WA
Increase value Decrease value
Hirschmann Operating System - HiOS Layer 2 Software
HIRSCHMANN HiOS L2 TRAINING 3 DAYS IN ADELAIDE INCLUDES 943 993-471 (VOUCHER) TR-HIRS-HIOS2-SA
Increase value Decrease value
Hirschmann Operating System - HiOS Layer 3 Software
HIRSCHMANN HiOS L3 TRAINING 3 DAYS IN BRISBANE INCLUDES 943 993-471 (VOUCHER) TR-HIRS-HIOS3-QLD
Increase value Decrease value
Hirschmann Operating System - HiOS Layer 3 Software
HIRSCHMANN HiOS L3 TRAINING 3 DAYS IN MELBOURNE INCLUDES 943 993-471 (VOUCHER) TR-HIRS-HIOS3-VIC
Increase value Decrease value
Hirschmann Operating System - HiOS Layer 3 Software
HIRSCHMANN HiOS L3 TRAINING 3 DAYS IN SYDNEY INCLUDES 943 993-471 (VOUCHER) TR-HIRS-HIOS3-NSW
Increase value Decrease value
Hirschmann Operating System - HiOS Layer 3 Software
HIRSCHMANN HiOS L3 TRAINING 3 DAYS IN PERTH INCLUDES 943 993-471 (VOUCHER) TR-HIRS-HIOS3-WA
Increase value Decrease value
Hirschmann Operating System - HiOS Layer 3 Software
HIRSCHMANN HiOS L3 TRAINING 3 DAYS IN ADELAIDE INCLUDES 943 993-471 (VOUCHER) TR-HIRS-HIOS3-SA
Increase value Decrease value
Network Management (CP2)
HIRSCHMANN NETWORK TRAINING 2 DAYS IN BRISBANE INCLUDES 943 993-471 (Voucher) TR-HIRS-CP2-QLD
Increase value Decrease value
Network Management (CP2)
HIRSCHMANN NETWORK TRAINING 2 DAYS IN MELBOURNE INCLUDES 943 993-471 (Voucher) TR-HIRS-CP2-VIC
Increase value Decrease value
Network Management (CP2)
HIRSCHMANN NETWORK TRAINING 2 DAYS IN SYDNEY INCLUDES 943 993-471 (Voucher) TR-HIRS-CP2-NSW
Increase value Decrease value
Network Management (CP2)
HIRSCHMANN NETWORK TRAINING 2 DAYS IN PERTH INCLUDES 943 993-471 (Voucher) TR-HIRS-CP2-WA
Increase value Decrease value
Network Management (CP2)
HIRSCHMANN NETWORK TRAINING 2 DAYS IN ADELAIDE INCLUDES 943 993-471 (Voucher) TR-HIRS-CP2-SA
Increase value Decrease value
Industrial Ethernet CT1
HIRSCHMANN CT1 TRAINING 2 DAYS IN BRISBANE INCLUDES 943 993-471 (VOUCHER) TR-HIRS-CT1-QLD
Increase value Decrease value
Industrial Ethernet CT1
HIRSCHMANN CT1 TRAINING 2 DAYS IN MELBOURNE INCLUDES 943 993-471 (VOUCHER) TR-HIRS-CT1-VIC
Increase value Decrease value
Industrial Ethernet CT1
HIRSCHMANN CT1 TRAINING 2 DAYS IN SYDNEY INCLUDES 943 993-471 (VOUCHER) TR-HIRS-CT1-NSW
Increase value Decrease value
Industrial Ethernet CT1
HIRSCHMANN CT1 TRAINING 2 DAYS IN PERTH INCLUDES 943 993-471 (VOUCHER) TR-HIRS-CT1-WA
Increase value Decrease value
Industrial Ethernet CT1
HIRSCHMANN CT1 TRAINING 2 DAYS IN ADELAIDE INCLUDES 943 993-471 (VOUCHER) TR-HIRS-CT1-SA
Increase value Decrease value
Industrial Ethernet CT2
HIRSCHMANN CT2 TRAINING 3 DAYS IN BRISBANE INCLUDES 943 993-471 (VOUCHER) TR-HIRS-CT2-QLD
Increase value Decrease value
Industrial Ethernet CT2
HIRSCHMANN CT2 TRAINING 3 DAYS IN MELBOURNE INCLUDES 943 993-471 (VOUCHER) TR-HIRS-CT2-VIC
Increase value Decrease value
Industrial Ethernet CT2
HIRSCHMANN CT2 TRAINING 3 DAYS IN SYDNEY INCLUDES 943 993-471 (VOUCHER) TR-HIRS-CT2-NSW
Increase value Decrease value
Industrial Ethernet CT2
HIRSCHMANN CT2 TRAINING 3 DAYS IN PERTH INCLUDES 943 993-471 (VOUCHER) TR-HIRS-CT2-WA
Increase value Decrease value
Industrial Ethernet CT2
HIRSCHMANN CT2 TRAINING 3 DAYS IN ADELAIDE INCLUDES 943 993-471 (VOUCHER) TR-HIRS-CT2-SA
Increase value Decrease value
Industrial Routing CT3
HIRSCHMANN CT3 TRAINING 2 DAYS IN BRISBANE INCLUDES 943 993-471 (VOUCHER) TR-HIRS-CT3-QLD
Increase value Decrease value
Industrial Routing CT3
HIRSCHMANN CT3 TRAINING 2 DAYS IN MELBOURNE INCLUDES 943 993-471 (VOUCHER) TR-HIRS-CT3-VIC
Increase value Decrease value
Industrial Routing CT3
HIRSCHMANN CT3 TRAINING 2 DAYS IN SYDNEY INCLUDES 943 993-471 (VOUCHER) TR-HIRS-CT3-NSW
Increase value Decrease value
Industrial Routing CT3
HIRSCHMANN CT3 TRAINING 2 DAYS IN PERTH INCLUDES 943 993-471 (VOUCHER) TR-HIRS-CT3-WA
Increase value Decrease value
Industrial Routing CT3
HIRSCHMANN CT3 TRAINING 2 DAYS IN ADELAIDE INCLUDES 943 993-471 (VOUCHER) TR-HIRS-CT3-SA
Increase value Decrease value
Products to compare:
Comparing Products