News:

  • August 06, 2026, 05:49:57 PM

Login with username, password and session length

Author Topic: Python interpreter  (Read 20517 times)

scottsutton

  • Full Member
  • ***
  • Posts: 46
Python interpreter
« on: December 21, 2020, 07:40:34 AM »
I use Python for analytics and process control in various system. I have found that the Python language is very power in the industrial control environment. Typically, I access data from a PLC with PyModbusTCP running on a network PC. From that point I can process the data with Python and create reports that help optimize systems. Everything from the number crunching to generating the report and emailing it out is done with Python automatically.

I may be alone or vary rare in my methods but I think it would be great to have the Do-More engine have a Python Interpreter running onboard. Then allow a space for scripting kind of like for motion control.

Any thoughts?

Scott Sutton   

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6170
  • Yes Pinky, Do-more will control the world!
Re: Python interpreter
« Reply #1 on: December 21, 2020, 08:57:29 AM »
We've talked about it. There are challenges and questions but we like the concept. Not sure on Python specifically, but we definitely envision one or more textual languages in Do-more.
« Last Edit: December 21, 2020, 11:20:12 AM by BobO »
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

scottsutton

  • Full Member
  • ***
  • Posts: 46
Re: Python interpreter
« Reply #2 on: December 21, 2020, 10:44:33 AM »
In my humble opinion Python would be a great choice BC of the low learning curve and also it has modules that are ready made to do some serious data analytics. Also, from what I understand Python is one of the fastest growing languages around and its acceptance is growing in a variety of industries.

Scott

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6170
  • Yes Pinky, Do-more will control the world!
Re: Python interpreter
« Reply #3 on: December 21, 2020, 11:19:57 AM »
In my humble opinion Python would be a great choice BC of the low learning curve and also it has modules that are ready made to do some serious data analytics. Also, from what I understand Python is one of the fastest growing languages around and its acceptance is growing in a variety of industries.

Scott

We like the idea. Major concerns about resource requirements and performance. If it takes 3 days to run a script that needs to take 5 seconds, I haven't helped you.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

scottsutton

  • Full Member
  • ***
  • Posts: 46
Re: Python interpreter
« Reply #4 on: December 21, 2020, 11:34:03 AM »
Not to suggest that I understand your Do-More system architecture but would a co-processor in the form of an expansion module relieve some overhead off of the main CPU. The module could be capable to run several of the most popular languages or you buy a module for your preferred language?   

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6170
  • Yes Pinky, Do-more will control the world!
Re: Python interpreter
« Reply #5 on: December 21, 2020, 12:37:01 PM »
Not to suggest that I understand your Do-More system architecture but would a co-processor in the form of an expansion module relieve some overhead off of the main CPU. The module could be capable to run several of the most popular languages or you buy a module for your preferred language?

That is certainly an option. With all of these ideas, we're trying to balance ROI. Integrating MicroPython into a POM might be a good/easy way to do it, but embedded directly in the processor would improve the integration. Always tradeoffs.

We built the Windows CE based PLC long before anyone thought it was a good idea...and based on customer response, it really wasn't a good idea. Now that IoT is a bigger and bigger thing, we see a market for things like Python on a PLC. We're just not sure the best way to approach it. Host is a small company. We have to choose our shots.

Again, I like the idea. I had dug into it a couple of years ago and decided it wasn't the right thing to do...yet. Now may be the time, we just need to see where it fits in our development priorities, and whether existing hardware can run it well enough to be useful.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6170
  • Yes Pinky, Do-more will control the world!
Re: Python interpreter
« Reply #6 on: December 21, 2020, 02:35:04 PM »
Spent some time reviewing options. It doesn't look like much has changed since I looked into it before. MicroPython looks like the friendliest implementation, since it is small-ish but full featured, and  bare metal. The next question is whether the packages needed for data processing would run on MicroPython. Probably will need Python guys to talk about what is needed. It would be really easy to integrate Python in a form that serves no useful purpose, i.e., capable of running simple scripts, but incapable of doing the things people really need. Cool, but not useful.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

jrayb

  • Full Member
  • ***
  • Posts: 46
Re: Python interpreter
« Reply #7 on: December 22, 2020, 06:36:54 PM »
Spent some time reviewing options. It doesn't look like much has changed since I looked into it before. MicroPython looks like the friendliest implementation, since it is small-ish but full featured, and  bare metal. The next question is whether the packages needed for data processing would run on MicroPython. Probably will need Python guys to talk about what is needed. It would be really easy to integrate Python in a form that serves no useful purpose, i.e., capable of running simple scripts, but incapable of doing the things people really need. Cool, but not useful.

Bob, I think he is talking about using it for data collection, Display & emailing automatically in a nice pretty format so that others could read & understand the data that they're looking at. I would find this very useful too. I convert .csv files into line graph spread sheets for a pumping system that we run. I do this every single morning when I get to work. I use it as a guage of efficiency or "big brother" watching the guys when management isn't there. We're a 24/7 operation & any time lost is forever gone. If there were a method of doing all of the converting .csv files into a nice bar graph & emailing it automatically then I would be over the moon!!

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6170
  • Yes Pinky, Do-more will control the world!
Re: Python interpreter
« Reply #8 on: December 23, 2020, 09:35:36 AM »
There are always pros and cons to what you do where and why. Is Python scripting part of the control? Is it part of the data post processing? Should it be done on the PLC itself, or on a cloud based server? Etc. Etc. The real answers are unlikely to be 'yes' or 'no', and most likely to be 'all of the above', but performance and resources will always force compromises.

We are already moving toward adding one or more forms of textual languages to future Do-more PLCs. We're certain that we'd like to have a C-like textual language for control, preferably something that could completely replace ladder. We're also certain that we'd like to have some form of scripting language for doing other things. Maybe Python is a good choice for that. We'll look into it.

As an initial offering, I could see the scripting language wanting access to PLC image register data, PLC file systems, and PLC comms (email? TCP? UDP? We'll see.). It won't be particularly fast. but for scripting that's probably fine. Anything else you absolutely need?
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

jrayb

  • Full Member
  • ***
  • Posts: 46
Re: Python interpreter
« Reply #9 on: December 23, 2020, 02:46:56 PM »
I completely understand where you're coming from. I'm not saying that it has to be python or any specific brand. Also, it's not the end of the world for me if this never comes to fruition. I love Do-More & all of my projects except 2 (they're Click PLC) are Do-More PLC's. I have a total of 7 Do-More PLC's running in my plant & plan on expanding that to over 15 Do-More PLC's. The beauty of the Do-More is the data logging & email feature. Once the "brass" found out that I could send daily reports of a machines efficiency, that is without question correct (people tend to be less than truthful when reporting) they wanted me to push for more machine data collection. If this holds true, then I will be in my office converting .csv files to Excel spread sheet line graphs until lunch lol. I even setup a MQTT server with live data collection & display but they wanted something that would be in their email box daily. I am not a 100% programmer (i'm a maintenance manager at a small plastics plant). If you know of anything that I could use for automating the conversion of my data collection into a line graph & emailing it automatically, then I would definately look into it!!! Thanks so much for all of the hard work that you guys put into your product & the awesome support that you offer on your forums!!!

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: Python interpreter
« Reply #10 on: December 23, 2020, 05:44:42 PM »
...If this holds true, then I will be in my office converting .csv files to Excel spread sheet line graphs until lunch lol. I even setup a MQTT server with live data collection & display but they wanted something that would be in their email box daily. ...... If you know of anything that I could use for automating the conversion of my data collection into a line graph & emailing it automatically, then I would definately look into it!!!....
If you are posting MQTT data (to the the cloud), why not run a cloud based python script to take that daily data and create reports to email to management?  If you have the data in a database, you can easily create compilers to make the reports?

scottsutton

  • Full Member
  • ***
  • Posts: 46
Re: Python interpreter
« Reply #11 on: December 24, 2020, 06:27:18 AM »
jrayb wrote:

Quote
If there were a method of doing all of the converting .csv files into a nice bar graph & emailing it automatically then I would be over the moon!!

This is doable with something along the lines of raspberry pi or any computer that can run Python (Windows based, Mac, Linux). A PC running Python/ pymodbusTCP module can connect to just about any PLC and poll data at any reasonable rate. I have set up systems that poll critical data every X seconds/minutes/hours, and then once per day the data is processed at a predetermined time (all with a python script) and an excel report is generated with charts/graphs. The excel report is automatically emailed out to needed recipient(s). Management loves data that has been processed into visual format. This method does not utilize any of Do-More's excellent data logging features.

As I currently do this with a network based PC my desire would be to be able to do this type of data processing with the Do-More directly. Reducing hardware in any system is desirable but my current methods work extremely well.

-Scott


jrayb

  • Full Member
  • ***
  • Posts: 46
Re: Python interpreter
« Reply #12 on: December 25, 2020, 12:16:11 AM »
I have only been programming for about 10 months now. I have a vast knowledge of relay logic, which led me to PLC programming. Can one of you guys point me in the direction of the Python software?

scottsutton

  • Full Member
  • ***
  • Posts: 46
Re: Python interpreter
« Reply #13 on: December 25, 2020, 04:55:25 AM »
In my opinion the best way to get your feet wet with Python is to buy a raspberry pi single board computer. The pi foundation has created a platform that was designed from the ground up to get people into programming. The knowledge base is vast and the forums are active. If you do go that route (There are many ways to learn Python) then you will need some Linux knowledge or you will acquire it along the way.

YouTube is full of Python tutorials, also Python's syntax is very readable so the learning curve is  low compared to some other languages. When you blend PLC programming with another PC based language the possibilities are endless. Process measurement and reporting, Failure prediction, maintenance scheduling based on historical data, inventory reporting, etc.

-Scott