Downloading and Starting the CODESYS Application on the Controller
Requirement: The controller is started.
In CODESYS, create a standard project: click the command. In the New Project dialog, select the Standard Project template and specify a name and location. Then in the Standard Project dialog, select the respective controller.
In the device tree (Devices view) of the new project, there is now an entry for the controller (Device (...)), and below it an application with a POU (PLC_PRG (PRG) and a task MainTask which calls PLC_PRG).
In
PLC_PRG
, write a simple program (for example, a counter).PROGRAM PLC_PRG VAR iCount: INT; END_VAR iCount := iCount+1;
Establish a connection to the controller. To do this, use the Communication Settings tab of the device editor. You can open it by double-clicking the Device (...) entry in the device tree.
Normally, the gateway is already active now. If this is not the case, then check the status and explicitly start the gateway if necessary. Then, on the Communication tab, click the Scan Network command.
The Select Device dialog opens with the detected devices. In case your controller is not found, make sure that it was correctly installed and started.
Select the detected controller and click OK.
If the controller is not found, then check the following:
On the Communication Settings tab, in the Device → Options menu, disable the Filter Network Scans by Target ID option.
If your device is displayed now, then you have an incorrect
TargetID
. Your componentSysTargetOEM
might not have been loaded correctly.Is your device connected to your network?
By default, communication takes place with your device via UDP. When you use this communication method, your device has to be in the same subnetwork as your host. Both devices require the exact same configured network mask.
At startup, you can check the network settings for the messages of the runtime system. For example, they should be as follows:
1287759127: Cmp=CmpBlkDrvUdp, Class=1, Error=0, Info=6, pszInfo=Network interface: <ipaddress>192.168.101.41</ipaddress>
<subnetmask>255.255.252.0</subnetmask>
CODESYS tries to authenticate itself on this target system and get a communication channel. The connection is established.
Click
.The dialog to confirm the download of the application opens.
Perform the download and start the application. The application is processed on your device.
In the
PLC_PRG
program, check whether or not the counter is running.