Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Manufacturing Technology >> Industrial Technology

Defining Custom Arrays in Native Function Blocks – A Practical Guide

Why This Post?

In fact, this post was created because when I was developing the Native Function Block, I found that it was impossible to use an array of custom structures. Or to put it another way, it's a pity that the official GitHub of PLCnext doesn't have tutorials of this type. If you use the C# tutorial to create a custom array in Native Function Block, you will find that you can't compile it successfully, or setting the array values in PLCnext Engineer has no response. The example in the case just happens to be related to the database, that's all.

Demo description

https://github.com/Leeable/UserDefineArray_NativeFB/tree/Master

Requirements

$ plcncli --version
plcncli 23.6.0.1450 (23.6.0.1450)

STEP1

STEP2

ArrayCplus.cs

STEP3

Open the terminal in the ArrayTestCpp folder and enter the following.

$ plcncli generate code

After generating the code, locate the ArrayTest-cli32.h and ArrayTest-cli64.h files in the src directory, and find the places where #error is indicated.

We need to remove the comments and improve the code. Click to navigate to InArrayFB-cli.cpp and modify the implementation.

IntArrayFB-cli.cpp

STEP4

In ArrayCplus.cpp, enter the following code. Contents containing strings must be initialized in the process rather than in the Init region; initializing them in the Init region will not work, resulting in the inability to write values to sName and sAttribute through Engineer.

ArrayCplus-cli.cpp

STEP5

Open the terminal in the ArrayTestCpp folder and enter the following.

$ plcncli build all
$ plcncli deploy

STEP6

Open the PLCnext Engineer and load the ArrayTest.pcwlx add an variable to the ArrayTest named arr

Now it can work

Questions

Note:

The Makers Blog shows applications and user stories of community members that are not tested or reviewed by Phoenix Contact. Use them at your own risk.


Industrial Technology

  1. How 5G Is Revolutionizing Smart Factories
  2. Exploring 6G: The Future of Ultra-Fast Connectivity
  3. Driving Smarter Food Safety: A Strategic Partnership
  4. Top 7 Smart Warehouse Technologies You Should Adopt Now
  5. Navigating the Food & Beverage Industry: Challenges & Opportunities for 2024
  6. PCB Slots: Reliable, Efficient Component Fixing for Precise Electronics Assembly
  7. U.S. Manufacturing Reshoring: Current Trends and Impact
  8. Revolutionary Tech Eliminates Counterfeit Products from Supply Chains Worldwide
  9. Integrating ISO 9001 into Manufacturing Strategy: Driving Quality and Growth
  10. Bevel Protractor Explained: How It Measures Angles and Why It Matters