|
|
hace 5 meses | |
|---|---|---|
| .. | ||
| .settings | hace 6 meses | |
| board | hace 8 meses | |
| figures | hace 1 año | |
| packages | hace 6 meses | |
| rzn | hace 6 meses | |
| rzn_cfg | hace 6 meses | |
| rzn_gen | hace 6 meses | |
| script | hace 6 meses | |
| src | hace 1 año | |
| .api_xml | hace 1 año | |
| .config | hace 6 meses | |
| .cproject | hace 6 meses | |
| .gitignore | hace 1 año | |
| .project | hace 6 meses | |
| .secure_azone | hace 1 año | |
| .secure_rzone | hace 6 meses | |
| .secure_xml | hace 6 meses | |
| Kconfig | hace 6 meses | |
| README.md | hace 5 meses | |
| README_zh.md | hace 5 meses | |
| SConscript | hace 6 meses | |
| SConstruct | hace 1 año | |
| buildinfo.ipcf | hace 6 meses | |
| buildinfo.json | hace 6 meses | |
| configuration.xml | hace 6 meses | |
| envsetup.sh | hace 1 año | |
| mklinks.bat | hace 1 año | |
| mklinks.sh | hace 1 año | |
| ozone_scons.jdebug | hace 1 año | |
| project.ewd | hace 6 meses | |
| project.ewp | hace 6 meses | |
| project.ewt | hace 6 meses | |
| project.eww | hace 1 año | |
| rtconfig.h | hace 6 meses | |
| rtconfig.py | hace 1 año | |
| rzn_cfg.txt | hace 6 meses | |
| template.ewd | hace 1 año | |
| template.ewp | hace 1 año | |
| template.eww | hace 1 año | |
English | 中文
PROFINET is an industrial Ethernet standard developed and promoted by PI (PROFIBUS and PROFINET International) and is widely used in the industrial automation field.
P-Net is an open-source PROFINET implementation, specifically designed for real-time network communication in embedded devices. It is a lightweight PROFINET protocol stack aimed at providing developers with a quick and efficient way to integrate PROFINET functionality into embedded platforms.
In this example, we will use the P-Net software package to implement PROFINET master-slave communication.
Software Environment:
Hardware Environment:
Open the project configuration file configuration.xml and add the r_gamc stack:
Next, click on g_ether0 Ethernet, and configure the interrupt callback function to user_ether0_callback:
Now configure the PHY settings. Select g_ether_phy0, set the common configuration to "User Own Target", change the PHY LSI address to 1 (refer to the schematic for the exact address), and set the PHY initialization callback function to ether_phy_targets_initialize_rtl8211_rgmii(). Also, set the MDIO to GMAC.
Next, configure g_ether_selector0, set the Ethernet mode to "Switch Mode", set the PHY link to "Default Active-Low", and choose "RGMII" for the PHY interface mode.
Configure the Ethernet pin parameters and select the operating mode to RGMII:
Finally, configure ETHER_GMAC:
Double-click to open RT-Thread Settings, search for the p-net package in the search bar and enable it. Below are the related user configuration details:
Next, we need to configure the system to disable DHCP and use a static IP. Click on the component -> enable the lwip stack, and select to disable DHCP:
After completing the above configurations, compile the program and download it to the development board.
Connect the development board to the PC using an Ethernet cable, and configure a static IP on the PC:
Check the IP information on the development board and test connectivity:
CODESYS Overview: CODESYS is a PLC software developed by 3S (Germany), integrating PLC logic, motion control, configuration, display, and other functions. CODESYS, short for Controller Development System, is an industrial automation programming tool based on the IEC 61131-3 standard. It supports various programming languages (e.g., Ladder Diagram, Structured Text, Function Block Diagram) and provides libraries and function modules, making it a widely used platform in industrial automation for developing and debugging PLCs and control systems.
Ensure that you have CODESYS installed. After installation, the following three software components are required:
First, open CODESYS V3.5 SP20 Patch 3, choose New Project -> Projects -> Standard project, configure the project name and location, and click OK:
After the following popup, keep the default Settings (CODESYS Control Win V3 (CODESYS)/x64 (CODESYS)) and click OK:
Note: If you have purchased CODESYS Control RTE SL, select the device: CODESYS Control RTE V3 (CODESYS) / x64 (CODESYS). For evaluation purposes, you can choose CODESYS Control Win V3 (CODESYS) / x64 to create the project.
After creation, you will see the main interface:
Open the following two software components:
Back in CODESYS, double-click Device(CODESYS Control Win V3 x64) -> Communication Settings -> Scan Network:
In the user login window, configure the username and password (customizable):
Check if the gateway and soft PLC devices are online:
GSD (Generic Station Description) files are used for PROFIBUS DP and PROFINET IO communication, describing parameters, diagnostic data, and user-defined data between the PLC and I/O modules.
The GSDML file for this project is located at:
..\src\ports\rtthread\pn_devInstall the GSDML file from the above path: GSDML-V2.4-RT-Labs-P-Net-Sample-App-20220324.xml.
After installation, you should see the P-Net slave description file:
PN_Controller Configuration: Double-click PN_Controller (PN-Controller) -> General, and modify the default slave IP parameters as needed.
P-Net Slave Network Configuration: Double-click P-Net-multiple-module sample app -> General, and modify the IP parameters to match the development board’s IP:
You should see the PN master successfully online:
After the development board is powered on, once the NIC link up is detected, the secondary PN station is automatically started:
Here we use the CODESYS software to test the interaction between the PN master and slave stations.
Back in the CODESYS software, in the left navigation panel, select PN_Controller, right-click and scan the devices. After clicking on the device name, click on "Blink LED":
At this point, the development board (PN slave I/O) will display log outputs, accompanied by the onboard User LED blinking:
In the same device scanning interface, click on the I&M section in the lower left corner, modify the information, and write it to the I&M:
At the same time, PNIO will update the slave station configuration:
We can click to view the I&M again, and we will see that the I&M data has been successfully modified!
First, we click on the left panel under Device -> PLC Logic -> Application -> PLC_PRG (PRG), and use ST language to program the variable and program code:
Variable Definition: These variables define the input state of the button (in_pin_button_LED), the output state of the LED (out_pin_LED), and the state variable controlling whether the LED should blink (flashing). The oscillator state (oscillator_state) and oscillator cycle counter (oscillator_cycles) are used to achieve a timed blinking effect.
PROGRAM PLC_PRG
VAR
in_pin_button_LED: BOOL;
out_pin_LED: BOOL;
in_pin_button_LED_previous: BOOL;
flashing: BOOL := TRUE;
oscillator_state: BOOL := FALSE;
oscillator_cycles: UINT := 0;
END_VAR
Program Definition:
oscillator_cycles increases by 1. When the counter exceeds 200, the counter is reset, and the oscillator_state is toggled (TRUE or FALSE), achieving a periodic change.flashing state is toggled. That is, every time the button is pressed, the LED blinking state is toggled.flashing is TRUE, the LED will blink according to the oscillator state (oscillator_state). If flashing is FALSE, the LED will turn off directly.At the end of each cycle, the current button state is saved in in_pin_button_LED_previous to check the button press event in the next cycle.
oscillator_cycles := oscillator_cycles + 1;
IF oscillator_cycles > 200 THEN
oscillator_cycles := 0;
oscillator_state := NOT oscillator_state;
END_IF
IF in_pin_button_LED = TRUE THEN
IF in_pin_button_LED_previous = FALSE THEN
flashing := NOT flashing;
END_IF
out_pin_LED := TRUE;
ELSIF flashing = TRUE THEN
out_pin_LED := oscillator_state;
ELSE
out_pin_LED := FALSE;
END_IF
in_pin_button_LED_previous := in_pin_button_LED;
The configuration in the project is shown in the image below:
Next, we need to add a built-in IO module. Right-click on P_Net_multi_module_sample_app and add an IO module (DIO 8xLogicLevel), as shown in the image below:
Then, double-click on the DIO_8xLogicLevel node, select the PNIO Module I/O Mapping, edit Input Bit 7 and Output Bit 7, and bind the PLC variables:
Next, click on the Build -> Generate Code in the navigation bar, then select Online -> Login, and run to observe the behavior:
Next, go back to CODESYS, double-click Device -> PLC Logic -> Application and open the PLC_PRG (PRG). At this point, you can dynamically observe the program's running state. For example, if you press and hold the KEY0 on the EtherKit development board, you will find that both in_pin_button_LED and in_pin_button_LED_previous are FALSE. When you release KEY0, you will see that the flashing value toggles once.