Free ABCIP PLC Communications Using Python

I have been using a GitHub project called pylogix by GitHub user dmroeder to do some basic data retrieval from ControlLogix and CompactLogix PLCs.  While the project has been around for a while there has been some more recent activity and the code has become pretty reliable. I have used it to pull data from PLCs where that data does not change readily, for example recipe data or setpoint data.  Another great use is for turning Raspberry PIs into remote IO devices by having them push data to a PLC.  This can be useful for monitoring a fire pump run status in a remote pump house or for monitoring the temperature and humidity of a control room where there is no PLC and cost is an issue.  I will try to post more examples of industrial uses for Raspberry PIs in the near future, but wanted to give a shout out for this project since it is quite good. https://github.com/dmroeder/pylogix


Recommendations for Trying Linux

I recently sent this to someone interested in trying Linux and figured I would post it here for anyone else: Dan, I recommend Ubuntu for anyone just starting out in Linux on the desktop. https://www.ubuntu.com/download/desktop Use the top one, 18.04.1 LTS (Read the system requirements. If you are installing on something that does not meet these requirements, let me know. There are other distros that work on lower spec PCs.) Installation –  You will need to burn the downloaded iso to a DVD or to a thumbdrive. There are plenty of tutorials online for doing this. I use Etcher to put the image on a thumbdrive. https://www.balena.io/etcher/ You will also need to know how to tell your computer to boot from the installation media (i.e. DVD or thumbdrive) Once you get that far follow these steps https://tutorials.ubuntu.com/tutorial/tutorial-install-ubuntu-desktop?_ga=2.137457650.372567711.1546946782-835315326.1546946782#0 Some things to keep in mind when trying or transitioning to Linux on the desktop:  It is not Windows so things will work differently. (Think of going from Windows to Mac.) I recommend using the stock install for a period of time before breaking your stuff by tweaking and make no mistake, you can tweak the hell out of Linux and there is a ton of information on the internet. When you search the internet for help follow these guidelines: Stick to help for your distro and version (Ubuntu 18.04). Set your search tools to results in the past year. (Old results may contain useless instructions. Linux is updated regularly.) When you find instructions to do something on a forum, don’t forget to look at the comments below. People will often correct instructions or provide alternate solutions in the comments. Compare multiple solutions to a problem before settling on the best course of action. For example, I have found 10 pages of instructions using one method that was accomplished with two commands using another method. If you are really going to make the move, take notes. You will do something and later want to duplicate what you did. The beauty of Linux is that it is free so you can install it again and again. While I am no expert Linux is a passion of mine so feel free to tap me when you need help. The laptop and screen on my desk to the left is running Ubuntu 16.04 and I’ve been using Linux successfully since 2010. Have fun, Dave


Raspberry Pi Setup

RPi Setup for Specific Use Cases I’ve added some notes here to assist with setting up a Raspberry Pi for different use cases.  These notes were consolidated from many other sources and as versions change and things are updated these instructions may not always work, but here they are for anyone’s use. Initial Setup Install using standard Noobs or Rasbpian with Desktop. Using Raspi-Config enable the Camera and SSH for future use. Change the Node Name, change the password, set the localization. Note: You have to scroll up to get the English US keyboard after selecting the US. Drop the background to just grey, no image. Remove all the icons but the terminal from the top panel. Resolution for 7” Monitor Open raspi-config and set the resolution to 28. Add plantfloor User Reference: https://www.raspberrypi.org/documentation/linux/usage/users.md sudo adduser plantfloor Add sudo sudo visudo Find the line under the commented header # User privilege specification: root ALL=(ALL:ALL) ALL Copy this line and switch from root to plantfloor. To allow passwordless root access, change to NOPASSWD: ALL. The example below gives the user plantfloor passwordless sudo access: # User privilege specification root ALL=(ALL:ALL) ALL plantfloor ALL=(ALL) NOPASSWD: ALL Save and exit to apply the changes. Be careful, as it’s possible to remove your own sudo rights by accident. Also, make sure this line is the LAST line in the file. Assign Static IP sudo nano /etc/dhcpcd.conf. interface eth0 static ip_address=192.168.1.XX/24 Optional: (Only do if internet access is required.) static routers=192.168.1.1 static domain_name_servers=192.168.1.1 Make plantfloor the Default Auto Login sudo nano /etc/lightdm/lightdm.conf Uncomment these two lines: autologin-user=plantfloor autologin-user-timeout=0 WARNING – These lines may occur in a different section. Look for the [Seats:*] section. (The last section. You’ll be replacing the pi autologin user.) Reboot and then: Drop the background to just grey, no image. Remove all the icons but the terminal from the top panel. Install Thunar for Network File Access Since this is the first package we are installing, be sure to at least run: sudo apt-get update to refresh the repository locations. sudo apt-get install thunar For Python PLC Comms Copy the pylogix_master folder from the 10_Installables on the NAS. To access the network folders you will have to use Thunar. Enter smb://<ip address of pc with shares> into the address bar. Reference: https://github.com/dmroeder/pylogix Add RDP Support sudo apt-get install xrdp Make a Python Program Run on Startup Putting it in the users autostart file should have worked. Don’t use “sudo” that file belongs to the user. Code: nano ~/.config/lxsession/LXDE-pi/autostart Add the program to the bottom like this: @sudo /usr/bin/python /home/plantfloor/python_apps/<program name.py> The autostart file won’t run until after login to the desktop, even if the login is automatic, since it has to know who the user is to apply the correct desktop settings. By that time the rest of the system is ready. Piface Digital 2 Installation Install the packages if not installed already. sudo apt-get install python-pifacedigitalio or sudo apt-get install python3-pifacedigitalio Apply the patch to the python2.7 folder to fix … Continue Reading →