element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Sci Fi Your Pi
  • Challenges & Projects
  • Design Challenges
  • Sci Fi Your Pi
  • More
  • Cancel
Sci Fi Your Pi
Blog Escape The Past: Recipe Transfer to PLC and PLC data logging
  • Blog
  • Forum
  • Documents
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: frellwan
  • Date Created: 14 Aug 2015 10:47 PM Date Created
  • Views 1023 views
  • Likes 2 likes
  • Comments 3 comments
  • escape_the_past
Related
Recommended

Escape The Past: Recipe Transfer to PLC and PLC data logging

frellwan
frellwan
14 Aug 2015

This week I was able to make progress on being able to read the recipe files and load the data to the PLC. I also made some modifications to the OEE data collection to add a header line to the log  file.

 

PLC Recipe Files:

In order to load recipes, the operator will interact through the PanelView display. The operator chooses to load a new recipe by first selecting a recipe 'Family', then selecting the actual product. As can be seen below N10:23 and N10:24 hold the current screen that the operator is on and the next screen to load. When the operator has selected a product to load, bit B3:6/0 is set to signal that a product has been selected. The RPi is reading this bit, along with a couple of others, every 0.2 seconds. When it detects that this bit is True, it reads the product that was selected from the PLC, then reads the recipe file from the SD card on the RPi and selects the appropriate recipe data from the file. The RPi then sends this data to the PLC and when the data transfer is complete will clear B3:6/0.

 

The operator will select the recipe 'Family' as shown in the below picture. Due to corporate policy I had to distort the choices, but I think you get the point.

image

 

Once the 'Family' is selected, the actual recipe will be selected as shown in the below picture.

image

Once the recipe is selected, bit B3:6/0 is set in the PLC.

image

 

Once the RPi recognizes the change in state of B3:6/0, the RPi will retrieve the recipe information and transmit it to the PLC.

 

image

 

 

if (bits[1]):
    # self.loaded added so multiple uploads won't be initiated
    if (not self.loaded):
        serialLog.debug("Loading Values to PLC")
        print "Load values to PLC"
        self.loaded = True

        def clearRecipeBit(response):
            request = protectedWriteRequest(1, self.ALARMS[1], [0])
            d = self.sendRequest(request)
            d.addErrback(self.errorHandler, 'clearRecipeBit')


        def sendRecipe(recipe):
            PLCRecipe = self.config.getPLCRecipe()
            index = 1                               # Index 0 is recipe name
            var = []
            for address in PLCRecipe:
                request = protectedWriteRequest(1, address, [float(recipe[index])])
                result = self.sendRequest(request)
                result.addErrback(self.errorHandler, "sendRecipe")
                var.append(result)
            d = defer.gatherResults(var)
            d.addCallback(clearRecipeBit)
            d.addErrback(self.errorHandler, 'saving data in StartOEEData failed')
                
                
            def getRecipeValues(recipeName):
                localDir, remoteDir = self.config.getRecipeDirectories()
                filename = localDir + '/' + 'families.csv'
                fObj = open(filename, 'r')
                for recipe in fObj:
                    if recipe.strip() in recipeName[0]:
                        recipeFile = localDir + '/' + recipe.strip() + '.csv'
                        fRecipe = open(recipeFile, 'r')
                        for line in fRecipe:
                            if recipeName[0] in line.strip():
                                sendRecipe(line.strip().split(','))
                            
        request = protectedReadRequest(1, 'ST15:20')
        d = self.sendRequest(request)
        d.addCallback(getRecipeValues)
        d.addErrback(self.errorHandler, 'saving recipe data')
            
    else:
        self.loaded = False

 

 

PLC Data Logging

The RPi scans the PLC every 60 seconds to retreive OEE information that will be stored to a local file and eventually FTP'd to a OEE server. The data is stored to a logfile that rotates on a daily basis. The loggerfile is saved in csv format. I added some code to the loggerfile program to add header information to the first line of the file.

 

def _openFile(self):
    self.closed = False

    if os.path.exists(self.path):
        self._file = file(self.path, "r+", 1)
        self._file.seek(0, 2)
    else:
        config = utilities.optionReader()
        if self.defaultMode is not None:
            # Set the lowest permissions
            oldUmask = os.umask(0o777)
            try:
                self._file = file(self.path, "w+", 1)
                #write header information
                self._file.write(','.join(map(str,config.getLoggerHeader())))
            finally:
                os.umask(oldUmask)
        else:
            self._file = file(self.path, "w+", 1)
            #write header information
            self._file.write(','.join(map(str,config.getLoggerHeader())))

    if self.defaultMode is not None:
        try:
            os.chmod(self.path, self.defaultMode)
        except OSError:
            # Probably /dev/null or something?
            pass

    self.lastDate = self.toDate(os.stat(self.path)[8])

 

 

Last thing to do is integrate the MTrim serial program into the DF1 serial program to write recipe values to it.

  • Sign in to reply
Parents
  • balearicdynamics
    balearicdynamics over 10 years ago

    Nice work Eric! Is there a special reason that the text menus on the screen photos is not shown (it seems a blurred artifact) ?

     

    After the RPI data collection cycles from the AB PLC on its rotating file do you have considered to make a minimal parsing of it (i.e. managing unexpected conditions, alarms etc.) or the RPI acts just as a data collector / manager / archive ?

     

    The idea to FTP the log file to remote sounds good.

     

    Enrico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • frellwan
    frellwan over 10 years ago in reply to balearicdynamics

    Enrico - Thanks for the questions.

     

    This is a project that I am doing at the company I work for. In obtaining permission to post the photos, I was asked to blur the recipe names. The recipe names aren't really important to the project. The important part is more to see that you select the recipe and the RPI can read it, find the recipe file, read the recipe file, and upload to the PLC.

     

    The rotating file is just for data storage to send to an external server that will post the data to an internal web server, so there is no parsing of that data, However, in addition to collecting the OEE data, the code is also scanning for an alarm word. This 16 bit word contains 6 alarm/warning bits, that if set will trigger an email to be sent. The config.ini file can be set up to send emails to one or more people. I have even had it send a text to my phone.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • frellwan
    frellwan over 10 years ago in reply to balearicdynamics

    Enrico - Thanks for the questions.

     

    This is a project that I am doing at the company I work for. In obtaining permission to post the photos, I was asked to blur the recipe names. The recipe names aren't really important to the project. The important part is more to see that you select the recipe and the RPI can read it, find the recipe file, read the recipe file, and upload to the PLC.

     

    The rotating file is just for data storage to send to an external server that will post the data to an internal web server, so there is no parsing of that data, However, in addition to collecting the OEE data, the code is also scanning for an alarm word. This 16 bit word contains 6 alarm/warning bits, that if set will trigger an email to be sent. The config.ini file can be set up to send emails to one or more people. I have even had it send a text to my phone.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • balearicdynamics
    balearicdynamics over 10 years ago in reply to frellwan

    Hello Eric, thank you for the explanation. I though that it was something wrong in the display image that's the reason of my question.

     

    Instead about the parsing and feedback messaging yes the mechanism is really very interesting. I have done something like this in past and was a really good experience. Unfortunately I had only a java support on the linux micro controller machine to manage the PLC and sensors so I had to develop a lot of java classed to control hardware while in a lower level language it will be easier.

     

    Enrico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube