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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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: Final Touches
  • 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: 25 Aug 2015 7:39 PM Date Created
  • Views 466 views
  • Likes 1 like
  • Comments 0 comments
  • escape_the_past
Related
Recommended

Escape The Past: Final Touches

frellwan
frellwan
25 Aug 2015

This past week I have been completing the code to finalize the project The MTrim RS-422 serial interface needed to be available from within the DF1  RS-232RS-232 interface object since the bits in the PLC that are being read by the DF1 object actually trigger the sending of information across the RS-422 serial interface to the MTrim

 

The final code for the serial communications can be found at: https://github.com/frellwan/SciFy-Pi.git  in the serial/DF1 folder.

 

Code to make the MTrim Accessible from within the DF1 class:

class DF1ClientProtocol(SerialClientProtocol):

  def __init__(self, logger, ftpEndpoint, mtrimSerial):
  ''' Initializes our custom protocol

  :param logger: The local file to store results
  :param ftpEndpoint: The endpoint to send results to and read recipes from
  '''
  SerialClientProtocol.__init__(self)
  self.logger = logger
  self.ftpEndpoint = ftpEndpoint
  self.mtrimSerial = mtrimSerial
  self.logFile = logger.getFileName()
  self.ENQCount = 0
  self.lcOEE = LoopingCall(self.startOEEData)
  self.lcAlarms = LoopingCall(self.startAlarmsData)
  self.lcFTP = LoopingCall(self.startFTPTransfer)
  self._reconnecting = False
  self.config = utilities.optionReader()
  fLogFile = logfile.LogFile('df1comms.log', '/home/pi/projects/newSLC/logs', maxRotatedFiles=2)
  fLogObserver = log.FileLogObserver(fLogFile)
  log.startLogging(logfile.LogFile('df1comms.log', '/home/pi/projects/newSLC/logs', maxRotatedFiles=2))
  #log.startLogging(sys.stdout)
  self.notified = False
  self.transferred = False
  self.loaded = False

 

 

Then to change parameters when the recipe is changed:

def sendRecipe(recipe):
    PLCRecipe = self.config.getPLCRecipe()

    result = self.mtrimSerial.writeParameter(1, 1, float(recipe[-3]))
    result.addErrback(self.errorHandler, "sendRecipe")

    result = self.mtrimSerial.writeParameter(1, 20, float(recipe[-2]))
    result.addErrback(self.errorHandler, "sendRecipe")

    result = self.mtrimSerial.writeParameter(1, 21, float(recipe[-1]))
    result.addErrback(self.errorHandler, "sendRecipe")

    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')

 

 

I also need the PiFace code and the serial code to run when the RPi is booted up.

 

I tried following the istructions found here, but I could not get it to work. I was able to use the basic concept outlined, but had to make changes to the rc.local file in the /etc/init.d directory. When I did that it worked fine.

So to enable the PiFace code and the serial code I created a file - launcher.sh - that looks like this:

#!/bin/sh
# launcher.sh
cd /home/pi/projects
cd /home/pi/projects/PiFace
python3 lcdSM.py &
cd /home/pi/projects/newSLC
python df1.py &

 

The I used the command:

sudo nano /etc/rc.local

 

to make the file look like this:

#!/bin/sh

### BEGIN INIT INFO
# Provides: rc.local
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Start df1comms daemon
### END INIT INFO

# Install Script Info
(sleep 10; sudo /home/pi/projects/launcher.sh)&

 

 

Everything is working very well. I will put some videos together to show here shortly.

  • Sign in to reply
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