We are Florida, Georgia, Virginia, North Carolina and South Carolina's premiere automation solutions provider and are committed to being an innovative supplier. It is our goal to be an expert in everything that we sell so that we can be a better asset to our customers.
3915 Shopton Rd., Suite 103
Charlotte, NC 28217
Phone: 877.524.6832
sales@cimtec.com
In the first part of this entry, (Part 1) we discussed what the IC695CPL410 is. In this entry, we will work with the CPL410 and write a short example program to get data from the controller side, perform a simple calculation in Python, and then pass the calculated value back to the controller.
What you need to get started
Apart from needing the CPL410 (obviously), you will also need a computer with the latest version of Proficy Machine Edition (PME) which at the time of this entry is version 9.5. Additionally, you will need a way to connect your computer to two of the RJ45 ports on the CPL410. There are several ways to do this including:
1) Cable from your laptop RJ45 port to a DHCP capable router. Note that:
2) Use a DHCP router capable of being a wireless access point and having at least two hardwired ports. The two bullet points above still apply, but this eliminates some of the headache of switching IP addresses in Windows. You just connect your computer to the wireless signal from this router and you are connected to both ports on your CPL410. I have used serval of these devices; the one pictured here is the NETIS N300.
The connection between the two systems is ethernet via LAN1 on the front of the CPL410. To connect to the Linux side of the system, you need a separate connection to the ETH port located on the underside of the CPL410. The default IP for the front LAN1 is 192.168.0.100. The ETH port on the underside works best being connected to a DHCP server. For convenience, I recommend a setup like this one that I use
The CPL410 has a small LED display on the front of it so you can see what address is given to the Linux side.
Warning – code ahead!
The following example assumes some basic knowledge of how to use Proficy Machine Edition (PME).
First, let’s open PME and create a simple project that counts from 0 to 500, then resets back to 0. I’ll set one register(‘MyInt’) to External Read Only and then create another resister(‘PythonDBL’) that is External Read/Write. Note the OPCUA Server is Enabled in the project (this is default).
For this simple application, we also need to make sure that Passwords are Disabled.
I’ll go ahead and Download and Start this project on the CPL410 target.
Now, on to the Linux side. I will assume that you followed Section 5.2.1 in the Quick Start Guide available from here. The Linux side of the CPL410 should be ready for you to login using the password you set.
We will be using the same SSH Client software package called ‘Putty’ used in the QSG – there are other packages out there or you could use a computer running Linux either natively or in a virtual machine in Windows.
Once logged in, create a project directory and change to it.
The CPL410 has Python 2 and Python 3 installed. For this tutorial, we will use Python 3. We will create a very basic script that reads in one tag, doubles it, and writes it to another tag. Now, we will create and open the python script file using the Linux text editor ‘nano’.
And here is our short and sweet script:
Save (Ctrl-O) and exit (Ctrl-X) from nano. When back at the command prompt, execute the program as a Python 3 script:
You should now see both the ‘MyInt’ variable that is generated by the controller and the ‘PythonDBL’ variable created by our script:
You can exit the script at any time by pressing ‘Ctrl-C’. Python is very readable as is, but here is an explanation of what is going on:
If you wish, you can set a watch in PME for the two variables and see that the controller indeed gets the doubled value sent by the Python script.
This is a trivial example, but once you see how to read and write values to the controller side of the CPL410, you can use the power of open platforms like Linux and Python to enhance your control system and give you better insights to your machine data. Future articles will discuss exactly that.
Recent Posts