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 →


Install ODBC Support for Linux

These instructions come from many other websites and I have consolidated them for what has worked for me.  If this also works for you, then that’s a good thing.  I have used these instructions to setup ODBC connectivity from Ubuntu 16.04 to a MSSQL server running 2008r2.  Then I have written applications using this ODBC connection in Gambas. Install Required Packages sudo apt-get install unixodbc unixodbc-dev freetds-bin Download and Compile FreeTDS cd /usr/local sudo wget http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz tar xvfz freetds-stable.tgz cd freetds-0.82 ./configure –enable-msdblib –with-tdsver=8.0 –with-unixodbc=/usr make make install make clean Test Connections telnet <ip address of SQL Server> 1433 Should result in: Connected to <ip address of SQL Server> tsql -S <ip address of SQL Server> -U <username> Should result in: 1> Create Configuration File In the home directory create .odbc.ini – [mssqlserver] Description = MS SQL Server Driver = /usr/local/lib/libtdsodbc.so Server = <ip address of SQL Server> UID = <username> PWD = <password> ReadOnly = No Port = 1433 TDS_Version = 8.0 Test ODBC Connection isql -v mssqlserver <username> ‘<password>’  


A Test Run of Ubuntu Gnome

When Ubuntu made the decision to go off on their own and develop their own desktop environment it didn’t bother me too much.  To be honest, once Windows 7 let you simply press the super key and start to type the name of the application you want to launch I pretty much stopped using the start menu all together.  (I still thinks it’s funny watching people struggle to find the application they want to start by navigating the huge monstrosity that is the start menu.)  I fell into using Unity and was very happy with the 14.04 and then the very usable and stable 16.04 LTS versions.  I instantly fell in love with the HUD, since I can never remember where the page landscape menu option is in LibreDraw or the emboss transform in Gimp.  To me, it was like the Unity developers had mind melded with my keyboard centric work flow. Well, now I have to begin switching to Gnome and so I spun up an 18.04 VM and began fiddling with it.  I went into the settings dialogue and checked out the keyboard shortcuts.  I tried simply changing the workspace navigation keyboard shortcut and the settings window locked up.  I clicked on the close button for the window and it wouldn’t close.  I waited several seconds for the window to popup allowing me to force quit the application, but it never appeared.  Finally I decided to reboot and install the latest updates.  After doing that I began again customizing some simple things.  I decided to change my wallpaper.  I opened the settings to change the wallpaper and saw a nice interface that even previewed the wallpaper and let me change the lock screen wallpaper as well.  Then I discovered that it won’t let you pick a picture from any folder, you’ve got to put the picture into the Pictures folder.  Fine, I tried to do this from files (Nautilus) and then once again, the files app locked up and nothing worked on the desktop.  Just my mouse.  This time I had to reboot the system to even get out of the locked desktop.  Even though I have had the infrequent app fail in Ubuntu, it NEVER took out the whole system. I don’t know.  I looked online to see if anyone else is having stability issues with the transition and everyone seems fine or comments on how much better Gnome is.  I must be doing something wrong because this Gnome desktop does not seem as polished or stable as Unity was.  Maybe I won’t move from 16.04 just yet. 🙁


Love My Chromebook (Provided it’s Served with Croutons)

I bought an Acer CB3-111 for $150 after reading several reviews on Amazon.  This is an 11″ Chromebook with a full fledged Intel Celeron processor.  Immediately after getting it I downloaded the latest Crouton.  For those that don’t know, Crouton is a great little tool for installing and running Ubuntu on your Chromebook.  The process takes about 5 steps and the most annoying thing about the whole process was having to boot the Chromebook into Developer mode and wait the 20 seconds while it says “Hey your booting into Developer mode and should press a key to completely not do this.”  HAHAHA….NOPE!!  Unfortunately, every time you boot the Chromebook it will display this warning and you will need to wait without touching it.  Since I don’t ever turn it off, this is generally not an issue.  I don’t include the steps for installing Crouton, just Google it, there are plenty of sites that give detailed instructions. Once Crouton is installed and you have loaded and launched your favorite flavor of Ubuntu, mine was Xubuntu, now you have a full laptop.  Since this thing is all solid state, I got a hard plastic shell for it for an extra $20 and lug this thing around with me everywhere.


Raspberry Pi 2 4G Raspbian Image Gotcha

I ran into an issue setting up a new 8G micro SD card for use with my Raspberry Pi 2 and wanted to capture the description of the problem, here, because I wasted at least 2 hours fighting this and not finding anything on the internet that described the exact problem I had.  The final solution was a real “DUH!” moment. Steps: I simply downloaded the Raspbian generic image and used dd to load the image onto my 8G SD card.  Then booted the Pi 2 with new image successfully and then ran sudo apt-get update and finally sudo apt-get upgrade.  The upgrade seemed to take a long time, but I wasn’t too concerned since this is a Pi, not an AMD 8350. Symptoms: – The upgrade took a long time. – After the reboot the Pi would not show the normal system loading screen, only a black screen with a sporadically flashing cursor in the upper left corner.  The green LED would flash and almost make it seem like it was going to do something, but nothing ever happened. Problem: The actual problem is a matter of storage space.  Palm to forehead!!!  The files of the Raspbian image took up the majority of the 4G partition it created on the 8G SD card.  Then when I ran the upgrade the packages that were downloaded completely filled the remaining space and didn’t successfully install.  Because the upgrade took so long I walked away and didn’t babysit the install and figured everything was okay. Rebooted and WHAMMO!  NO JOY!!!  I kept thinking something was wrong with the SD card. Solution: The key is to resize the disk to expand the partition back to the full 8G size.  There is a simple way to do this right from the default GUI.  THEN, do the apt-get update and upgrade.


Are you Really Worried About What Others Get?

I read a recent article where a progressive entrepreneur raised the minimum wage of all of his employees so even the lowest paid employee at the company would be making $70,000.  Sounds like a great idea, right.  I mean, who would be upset about this?  It turns out that a lot of people who made more than the new 70K minimum at the company were so upset that others were getting this bump, they quit.  This is something with which I have never been able to identify.  Maybe it comes from a certain level of narcissism, but I always figured it was a great thing when somebody else got a raise in pay or a reward of some kind and what difference does it make what I get in comparison.  Honestly, if I am unhappy with what I am getting in compensation or reward I would either tell those who can change it (the boss) or I would leave for a better offer.  (And make no mistake, I have done this.)  It also helps that I love what I do for a living.   Maybe there is some psychological trigger in humans that says we have to have more than others and if we can’t have more then they need to have less.  Next time you do a comparison of this kind, stop and ask yourself, are you genuinely happy with your compensation?  If you are, why would you begrudge someone else’s good fortune.  Even if you know that the guy getting the raise does nothing all day compared to you.  Don’t let your sense of self worth be driven by comparisons with others.


Laptops – The Abandoned Platform

Is it just me or have all the complaints regarding the lack of HiRes laptop resolutions that have been thrown at the laptop manufacturers simply fallen on deaf ears?  Since 2012 there have been news items where Linus Torvalds and even Flav-a-Flav complained about the 1366 x 768 resolution joke.  I am sick of finding laptops with seemingly great price points only to be disappointed by the lackluster resolution.  MY $250 MOTO X PHONE has a higher resolution.  WTH!!! I found this offering from Dell…..  A 14″ laptop with a Core i5.  This is (or should be) a nice laptop….. At $889 there is NO excuse for the low resolution. Please, Please, Please, laptop manufacturers…..  Don’t forget that platform that lets you produce as well as consume.  I love my laptop, I need my laptop and I want my laptop.  Don’t get me wrong, tablets are great for reading or watching some video or playing a quick game, but just try to sit and write a blog or do your budget on one.  Not gonna happen.  (At least not for me.)  And I am cool with the whole convergence thing….  I know the Windows Surface is supposed to bridge the gap between laptop and tablet, but in my opinion, continuing to produce these laptops that are a complete joke, is simply distracting.  Just stop it already. That is all.


Proxmox VE (Virtually Serving the Home User)

I have been a long time user of VMWare and have used the product extensively to run Windows on Linux or vice-versa.  In addition, I have used it to virtualize many of the services I use at home.  For instance, my Samba and FTP server is a virtual machine running Ubuntu 10.04 on an Ubuntu 12.04 host.  This has saved my ass in the past when I’ve had hardware issues and had to migrate from one computer to another.  Since the Samba and FTP server was a virtual machine I merely had to move it from the computer it was on and host it on a temporary computer while I repaired the hardware on the main computer.  Once the hardware was repaired I simply moved the virtual machine back.  I recently added Owncloud to my virtual server collection.  This has been very effective and I have been very happy with the decision to virtualize the server since moving it will now be very easy and making backups is as simple as stopping the guest, making a copy of the file and then restarting it.   The virtualized servers have been running on my fileserver which is mostly responsible for storing the 2 TB of data in a raid 1 configuration and making it available to the household users.  This has all been working quite well, but in the words of Tim Allen, I wanted to give it “More power!!!!”.  It was a simple enough decision to split the virtual server part off of the fileserver, let the fileserver continue to host its 2 TB of data and let a new computer do all the virtualization….  Enter Proxmox VE.  Proxmox VE is similar to VMWare ESXi in that it is installed on bare metal and runs virtual machines that you have to remotely access.  Proxmox supports fully virtualized KVM and OpenVZ or containers.  This was ideal for me since most of my home based virtual machines run Linux and containers are known to be much more efficient than KVM, but can not run Windows. With the platform selected the next step was to purchase the hardware.  I selected the AMD FX-8350 processor with its 8 cores feeling that this would be perfect for CPU hungry virtual machines.  I snapped this into an MSI 990FXA-GD65 which would unleash its power giving it 6GB SATA III ports.  I then added a Seagate Barracuda 1TB HD, but this failed after a week and I replaced it with a Western Digital Red 2TB for nearly twice the price.  Last I put in two 4GB sticks to take advantage of the dual channel memory, but planned to upgrade later.  As for video and case, these things are merely fluff on a headless PC, so any old one was fine.  In the end it came to about $630, a little more than I wanted to spend, but a lot less than if I had purchased something prefab.   Installing Proxmox was a breeze as everything is open … Continue Reading →