Thank you for reading. I've set up my RPi3 to communicate with an Allen Bradley L32 PLC. The goal is simply to take a picture using the RPiCamera after receiving a trigger from the PLC. It will save the file with a name assigned from the PLC, upload it to a remote computer using an FTP server, then delete the picture. I've got this part working, however after around 3 hours the two scripts that I've written will just disappear from the 'Services' window.
Here's the first script that's handling all of what I described above:
Code: Select all
import ftplib from picamera import PiCamera import time from Example_Program import * import os # Camera Settings camera = PiCamera() # Camera Factory Resolution Is 3280 x 2464 camera.resolution = (3280, 2464) # camera.brightness = 45 # camera.contrast = 50 counter = 0 FileNameTag = 'Pi_Filename_With_JPG' def doWork(): # Handshake To PLC To Confirm Connection ex_write('Pi_Handshake', '1') if ex_read('Trigger_Shutter') is True: try: # Starting Camera And Taking Picture camera.start_preview() time.sleep(2) camera.capture(ex_read(FileNameTag)) camera.stop_preview() # Logging Into FTP Server print("Trying To Login To FTP...") ftp = ftplib.FTP() ftp.connect('192.168.1.4', '800') ftp.login('scott', '') ex_write('FTP_Logon_Successful', '1') ftp.set_pasv(False) # Sending File To FTP Server fullname = ex_read(FileNameTag) name = os.path.split(fullname) f = open(fullname, "rb") ftp.storbinary('STOR ' + name, f) f.close() # Remove File From Pi os.remove(fullname) except Exception: pass while True: try: doWork() except Exception: doWork()
Code: Select all
import time from Example_Program import * import os def restart(): if ex_read('HMI_Reset_Pb') == 1: try: os.system('sudo shutdown -r now') except Exception: pass while True: try: restart() except Exception: restart()
I'm very new to Python, RPi's and the like, so if there's anything glaringly obvious in this code structure, please feel free to let me know!