class MQTTClientProcess(): def __init__(self, clientid, broker="localhost", port=1884): self.queue = Queue() self.clientid = clientid self.broker = broker self.port = port self.started = False self.process = Process(target=self.startProcess, args=(self.queue, self.clientid, broker, port,)) def send(self, channel, value): self.queue.put((channel, value)) def start(self): self.process.start() self.started = True def stop(self): self.process.stop() self.started = False def startProcess(self, queue, clientid, host, port): setproctitle("MQTT Client") print("Connecting to broker") print("Host: %s" % host) print("Port: %s" % port) mqttc = paho.Client(clientid) mqttc.connect(host, port=port, keepalive=60) print("Connected Successfully.\n") while True: data = queue.get(block=True) print("Sending Data.\n") print(data[0]) mqttc.publish("{}/{}".format(clientid, data[0]), data[1])
class Reloader(object): """Reload service when files change""" def __init__(self, sig='SIGHUP', files=[]): if not files: raise Exception('No file to watch for reload') self.log = Logs().log self.proc = None self._files = files sig_attr = getattr(signal, sig) try: assert int(sig_attr) except BaseException: raise Exception('Wrong signal provided for reload') self.observer = Observer() rel = Reload(sig=sig_attr, reloader=self) for dir in self.dirs: self.log.debug('Registering watcher for {dir}'.format(dir=dir)) self.observer.schedule(rel, dir, recursive=False) def _get_files(self): """Return iterator of tuples (path, file)""" for f in self._files: for m in glob.iglob(f): if os.path.isdir(m): yield (m, m) yield (os.path.dirname(m), m) if os.path.isdir(f): yield (f, f) yield (os.path.dirname(f), f) @property def files(self): """Return list of watched files""" return list(set([files[1] for files in self._get_files()])) @property def dirs(self): """Return list of watched directories""" return list(set([files[0] for files in self._get_files()])) def run(self, ret=False): while True: self.observer.start() if ret: return self.observer self.observer.join() def run_in_process(self): self.proc = Process(target=self.run) self.proc.start() def stop(self): if self.proc: self.proc.stop() else: self.observer.stop()
class Reloader(object): """Reload service when files change""" def __init__(self, sig='SIGHUP', files=[]): if not files: raise Exception('No file to watch for reload') self.log = Logs().log self.proc = None self._files = files sig_attr = getattr(signal, sig) try: assert int(sig_attr) except: raise Exception('Wrong signal provided for reload') self.observer = Observer() rel = Reload(sig=sig_attr, reloader=self) for dir in self.dirs: self.log.debug('Registering watcher for {dir}'.format(dir=dir)) self.observer.schedule(rel, dir, recursive=False) def _get_files(self): """Return iterator of tuples (path, file)""" for f in self._files: for m in glob.iglob(f): if os.path.isdir(m): yield (m, m) yield (os.path.dirname(m), m) if os.path.isdir(f): yield (f, f) yield (os.path.dirname(f), f) @property def files(self): """Return list of watched files""" return list(set([files[1] for files in self._get_files()])) @property def dirs(self): """Return list of watched directories""" return list(set([files[0] for files in self._get_files()])) def run(self, ret=False): while True: self.observer.start() if ret: return self.observer self.observer.join() def run_in_process(self): self.proc = Process(target=self.run) self.proc.start() def stop(self): if self.proc: self.proc.stop() else: self.observer.stop()
class PLProcess(object): ''' Create a Process. ''' def __init__(self, process, args): self.process = process self.args = args self.p = "" def create_process(self): self.p = Process(target=self.process, args=self.args) self.p.start() def stop_process(self, p): self.p.stop()
class SNMPService(service.Service): def __init__(self, cfg): super(SNMPService, self).__init__() cont = Controller([], cfg.CONF) self.snmp_server = Process(target=self.launch_SNMP_server, args=(cont.event_queue, cfg.CONF)) self.snmp_server.start() self.queue_thread = QueueMonitor(cont, self.snmp_server) LOG.info('Starting Queue Monitor Thread') self.queue_thread.start() self.queue_thread.join() def launch_SNMP_server(self, q, config): trap_server = SNMPTrapServer(controller=q, cfg=config) LOG.info('Starting SNMP Server Thread') trap_server.run() def end(self): self.queue_thread.stop() self.snmp_server.stop()
class PLProcess(object): ''' Create a Process. ''' def __init__(self, process, args): self.process = process self.args = args self.p = "" def create_process(self): if self.process == "": return elif self.args == "": self.p = Process(target=self.process) self.p.start() else: self.p = Process(target=self.process, args=(self.args)) self.p.start() def stop_process(self): self.p.stop()
def __init__(self): print("Making TubberCar ready, please wait..") try: mqtt = MqttService() p1 = Process(target=mqtt.connectandsubscribe, args=( self.subscribeTB, 'TubberCar', )) p1.deamon = True p1.start() time.sleep(5) ps3 = PlaystationService() if (ps3.ps3Connected): p2 = Process(target=ps3.joystickcontrole) p2.deamon = True p2.start() time.sleep(2) except KeyboardInterrupt: print("Exiting program.") p1.stop()
class Device(object): """docstring for Device""" def __init__(self, info): self.__urn = info.urn self.__xaddr = info.xaddr self.__proc = Process(target=self.__deviceProc, args=()) self.__rtsp = None self.__cam = None def run(self): print('Device %s running...', self.__urn) self.__proc.start() def stop(self): if self.__proc.is_alive(): self.__proc.stop() if self.__rtsp is not None: self.__rtsp.close() print('Device %s stopped...', self.__urn) def __deviceProc(self): res = url.urlparse(self.__xaddr) print(res) tmp = res[1].split(':') ip = tmp[0] if len(tmp) > 1: port = tmp[1] else: port = 80 num, matrix = read_anno_config('./Elec_Solution2/config/anno0.json') # get camera instance cam = ONVIFCamera(ip, port, '', '') # create media service media_service = cam.create_media_service() token = '000' # set video configuration configurations_list = media_service.GetVideoEncoderConfigurations() video_encoder_configuration = configurations_list[0] options = media_service.GetVideoEncoderConfigurationOptions({'ProfileToken':token}) video_encoder_configuration.Encoding = 'H264' video_encoder_configuration.Resolution = options.H264.ResolutionsAvailable[0] request = media_service.create_type('SetVideoEncoderConfiguration') request.Configuration = video_encoder_configuration request.ForcePersistence = True media_service.SetVideoEncoderConfiguration(request) # get video stream streamSetup = { 'StreamSetup': { 'Stream': 'RTP-Unicast', 'Transport': { 'Protocol': 'TCP' } }, 'ProfileToken': token } res = media_service.GetStreamUri(streamSetup) self.__rtsp = cv2.VideoCapture(res.Uri) reporter = context.getContext().reporter # capture and detect while self.__rtsp.isOpened(): print('%s capture start...' % ip) start = time.time() print('start: %d' % start) ret, frame = self.__rtsp.read() print('capture: %d' % time.time()) # img = cv2.cvtColor(numpy.asarray(frame),cv2.COLOR_RGB2BGR) print('convert: %d' % time.time()) tmp = self.__urn.split('-') name = tmp[-1] + '.jpg' cv2.imwrite(name, frame) detect_result = entry_detect(frame, num, matrix) print(detect_result) print('%s capture end %d. duration:%d' % (ip, time.time(), time.time() - start)) reporter.publish('hm_test', detect_result) time.sleep(10)
# draw the prediction on the frame label = "{}: {:.2f}%".format(CLASSES[idx], confidence * 100) cv2.rectangle(frame, (startX, startY), (endX, endY), COLORS[idx], 2) y = startY - 15 if startY - 15 > 15 else startY + 15 cv2.putText(frame, label, (startX, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, COLORS[idx], 2) # show the output frame frame = cv2.resize(frame, (500, 500)) cv2.imshow("Frame", frame) key = cv2.waitKey(1) & 0xFF # if the `q` key was pressed, break from the loop if key == ord("q"): break # update the FPS counter fps.update() # stop the timer and display FPS information fps.stop() print("[INFO] elapsed time: {:.2f}".format(fps.elapsed())) print("[INFO] approx. FPS: {:.2f}".format(fps.fps())) # do a bit of cleanup cv2.destroyAllWindows() vs.stop() p.stop()
import CaptureModule import FeatureExtractModule import MyTestModule from multiprocessing import Process if __name__ == "__main__": try: # processCapture = Process(target = CaptureModule.capture(), name=("processCapture")) # processFeature = Process(target = FeatureExtractModule.featureExtract(), name=("processFeature")) processTest = Process(target=MyTestModule.featureExtract()) # processCapture.start() # processFeature.start() processTest.start() except KeyboardInterrupt: # processCapture.stop() # processFeature.stop() processTest.stop() # processCapture.join() # processFeature.join() processTest.join()
def execute(module, topology_module = None, topology=default_topology, function=default_function, args=default_args, cli=default_cli, timeout=default_timeout, nodes=default_nodes, nox_path=default_nox_path, verbose=default_verbose, experiment_mode=default_experiment_mode): nodes = int(nodes) topology_module = module + "_topo" if topology_module is None else topology_module dirs = fetch_subdirs() setup_env(module, topology_module, function, args, topology, dirs, experiment_mode, nodes) import_directories(dirs) q = Queue() listener = Listener(signal_address) wait = Process(target=receive_signal, args=(listener,q)) wait.daemon = True wait.start() # if experiment_mode: # update_application = get_function_by_name(module, function) # initial_topology = get_function_by_name(topology_module, topology) # setup = get_function_by_name("update_lib", "setup") # inst = DummyComponent(args, update_application, setup, initial_topology) # os._exit(0) if experiment_mode: # yappi.start() nox = Process(target=run_nox) nox = NOX("c0", "UpdateApp") nox.start() lg.setLogLevel('output') output("*** Application started ***\n") wait.join(timeout) msg = "" status = "" if wait.is_alive(): status = "killed" wait.terminate() else: status = "finished" msg = q.get() # yappi.stop() # stats = string.join([str(stat) for stat in yappi.get_stats(yappi.SORTTYPE_TTOTAL)],"\n") output("*** Application %s ***\n%s" % (status, msg)) # output("*** Stats %s " % (stats)) if verbose: output("\n*** Controller output: ***\n" + getControllerOutput() + "\n") nox.stop() os._exit(0) # elif nox_only: # nox_command = os.path.expanduser(nox_path) # nox_dir = os.path.dirname(nox_command) # os.chdir(nox_dir) # if verbose: # nox_command += " -v" # command = "%s -i ptcp:6633 %s" % (nox_command,"UpdateApp") # os.system(command) # wait.join() # os._exit(0) else: global mininet topo = get_function_by_name(topology_module, topology)(nodes).mininet_topo() mininet = Mininet( topo=topo, switch=UserSwitch, controller=lambda name: NOX(name, "UpdateApp"), xterms=False, autoSetMacs=True, autoStaticArp=True ) mininet.start() lg.setLogLevel('output') output("*** Mininet Up ***\n") output("*** Application started ***\n") if cli: CLI(mininet) wait.join(timeout) msg = "" status = "" if wait.is_alive(): status = "killed" listener.close() wait.terminate() else: status = "finished" msg = q.get() output("*** Application %s ***\n%s" % (status, msg)) if verbose: output("*** Controller output: ***\n" + getControllerOutput() + "\n") mininet.stop() output("*** Mininet Down ***\n") os._exit(0)
stor = Storage(stg.uri, stg.user, stg.password) queue = Queue() lst = Listener(queue, stor) def reverse(ips): to_write = '' for l in range(256): ip_add = '{}.{}.{}.{}'.format(ips[0], ips[1], ips[2], l) try: host = socket.gethostbyaddr(ip_add)[0] queue.put([ip_add, host]) except: pass if __name__ == "__main__": ips = [] for i in range(256): if i not in [0, 10, 127] + [x for x in range(224, 240) ] + [y for y in range(240, 256)]: for j in range(256): for k in range(256): ips.append([i, j, k]) l = Process(target=lst.start) l.start() with Pool(stg.nb_work) as p: p.map(reverse, ips) l.stop() l.join()
class Choco(object): def __init__(self, config): self.config = config self.queue = Queue(10000) self.count = 0 self.pool = [Thread(target=self.start) for i in range(config.THREAD_COUNT)] self.working_count = Value(c_int) self.working_count_lock = Lock() if os.name is 'nt': self.watch_process = Thread(target=self.watch) self.ping_process = Thread(target=self.auto_ping) else: self.watch_process = Process(target=self.watch) self.ping_process = Process(target=self.auto_ping) self.exit = Value(c_bool) self.kakao = None redis_pool = redis.ConnectionPool(host=config.REDIS_HOST, port=config.REDIS_PORT, db=config.REDIS_DB, password=config.REDIS_PASSWORD) self.cache = ChocoCache.adapter = redis.Redis(connection_pool=redis_pool) self.module = Endpoint() self.module.set_prefix(config.COMMAND_PREFIX) self.cli = ChocoCLI(self) auth_mail = self.cache.hget('choco_auth', 'mail') auth_pass = self.cache.hget('choco_auth', 'password') auth_client = self.cache.hget('choco_auth', 'client') auth_x_vc = self.cache.hget('choco_auth', 'x_vc') if self.cache.hexists('choco_auth', 'uuid_base64'): auth_uuid = self.cache.hget('choco_auth', 'uuid_base64') else: auth_uuid = base64.b64encode(self.cache.hget('choco_auth', 'uuid')) if not auth_client: print >> sys.stderr, "Authenticate failed: client name not found\n" + \ "Please check config.py and set 'choco_auth' to redis server" sys.exit(1) elif not auth_uuid: print >> sys.stderr, "Authenticate failed: uuid not found\n" + \ "Please check config.py and set 'choco_auth' to redis server" sys.exit(1) self.load_module() if self.auth_kakao(auth_mail, auth_pass, auth_client, auth_uuid, auth_x_vc): print >> sys.stdout, 'Successfully connected to KakaoTalk server' def load_module(self): from modules import init_module, module_loader init_module(self, self.module) module_loader(home, self.config) def auth_kakao(self, mail, password, client, uuid, x_vc): user_session = self.cache.hget('choco_session', 'key') user_id = self.cache.hget('choco_session', 'id') if not user_session or not user_id: if not mail: print >> sys.stderr, "Authenticate failed: email address not found\n" + \ "Please check config.py and set 'choco_auth' to redis server" sys.exit(1) elif not password: print >> sys.stderr, "Authenticate failed: password not found\n" + \ "Please check config.py and set 'choco_auth' to redis server" sys.exit(1) elif not x_vc: print >> sys.stderr, "Authenticate failed: X-VC token not found\n" + \ "Please check config.py and set 'choco_auth' to redis server" sys.exit(1) self.kakao = kakaotalk(debug=self.config.DEBUG) auth_result = self.kakao.auth(mail, password, client, uuid, x_vc) if not auth_result: print >> sys.stderr, "KakaoTalk auth failed" sys.exit(1) else: login_result = self.kakao.login() if not login_result: print >> sys.stderr, "KakaoTalk login failed" sys.exit(1) else: self.cache.hset('choco_session', 'key', self.kakao.session_key) self.cache.hset('choco_session', 'id', self.kakao.user_id) else: self.kakao = kakaotalk(user_session, uuid, user_id, debug=self.config.DEBUG) login_result = self.kakao.login() if not login_result: print >> sys.stderr, "KakaoTalk login failed" sys.exit(1) return True def reload_kakao(self): print >> sys.stdout, 'Trying to reconnect..' self.ping_process.stop() for p in self.pool: p.stop() while not self.queue.empty(): self.queue.get() self.kakao.s.close() user_session = self.kakao.session_key uuid = self.kakao.device_uuid user_id = self.kakao.user_id del self.kakao self.kakao = kakaotalk(user_session, uuid, user_id, debug=self.config.DEBUG) login = self.kakao.login() if login: print >> sys.stdout, 'Reconnected' self.exit.value = False self.ping_process.start() for p in self.pool: p.start() self.watch() else: print >> sys.stderr, 'ERROR: failed to re-authorize to KakaoTalk' @staticmethod def run(config): bot = Choco(config) bot.ping_process.start() for p in bot.pool: p.start() bot.watch_process.start() bot.cli.open() def watch(self): while not self.exit.value: try: data = self.kakao.translate_response() if not data: print >> sys.stderr, \ 'WARNING: data is None. probably socket is disconnected?' self.reload_kakao() break elif data['command'] == 'MSG': body = data['body'] if 'chatId' in body: chatId = str(body['chatId']) exists = self.cache.hexists('choco:rooms', chatId) if not exists: data['command'] = 'NEW' self.queue.put(data) self.cache.incr('choco:count:recv') elif data['command'] == 'DECUNREAD' or data['command'] == 'WELCOME': body = data['body'] if 'chatId' in body: chatId = str(body['chatId']) exists = self.cache.hexists('choco:rooms', chatId) if not exists: data['command'] = 'NEW' self.queue.put(data) except socket.timeout, e: print >> sys.stderr, 'ERROR: socket timeout' except KeyboardInterrupt, e: self.send_exit() self.exit.value = True except Exception, e: print >> sys.stderr, e self.send_exit() self.exit.value = True
def execute(module, topology_module=None, topology=default_topology, function=default_function, args=default_args, cli=default_cli, timeout=default_timeout, nodes=default_nodes, nox_path=default_nox_path, verbose=default_verbose, experiment_mode=default_experiment_mode): nodes = int(nodes) topology_module = module + "_topo" if topology_module is None else topology_module dirs = fetch_subdirs() setup_env(module, topology_module, function, args, topology, dirs, experiment_mode, nodes) import_directories(dirs) q = Queue() listener = Listener(signal_address) wait = Process(target=receive_signal, args=(listener, q)) wait.daemon = True wait.start() # if experiment_mode: # update_application = get_function_by_name(module, function) # initial_topology = get_function_by_name(topology_module, topology) # setup = get_function_by_name("update_lib", "setup") # inst = DummyComponent(args, update_application, setup, initial_topology) # os._exit(0) if experiment_mode: # yappi.start() nox = Process(target=run_nox) nox = NOX("c0", "UpdateApp") nox.start() lg.setLogLevel('output') output("*** Application started ***\n") wait.join(timeout) msg = "" status = "" if wait.is_alive(): status = "killed" wait.terminate() else: status = "finished" msg = q.get() # yappi.stop() # stats = string.join([str(stat) for stat in yappi.get_stats(yappi.SORTTYPE_TTOTAL)],"\n") output("*** Application %s ***\n%s" % (status, msg)) # output("*** Stats %s " % (stats)) if verbose: output("\n*** Controller output: ***\n" + getControllerOutput() + "\n") nox.stop() os._exit(0) # elif nox_only: # nox_command = os.path.expanduser(nox_path) # nox_dir = os.path.dirname(nox_command) # os.chdir(nox_dir) # if verbose: # nox_command += " -v" # command = "%s -i ptcp:6633 %s" % (nox_command,"UpdateApp") # os.system(command) # wait.join() # os._exit(0) else: global mininet topo = get_function_by_name(topology_module, topology)(nodes).mininet_topo() mininet = Mininet(topo=topo, switch=UserSwitch, controller=lambda name: NOX(name, "UpdateApp"), xterms=False, autoSetMacs=True, autoStaticArp=True) mininet.start() lg.setLogLevel('output') output("*** Mininet Up ***\n") output("*** Application started ***\n") if cli: CLI(mininet) wait.join(timeout) msg = "" status = "" if wait.is_alive(): status = "killed" listener.close() wait.terminate() else: status = "finished" msg = q.get() output("*** Application %s ***\n%s" % (status, msg)) if verbose: output("*** Controller output: ***\n" + getControllerOutput() + "\n") mininet.stop() output("*** Mininet Down ***\n") os._exit(0)
observer = Thread(target=Handler().run, args=(ev(file), )) observer.start() obss.append(observer) observer = Observer() observer.schedule(Handler(), path=file, recursive=True) observer.start() obss.append(observer) observer = Observer() observer.schedule(Handler(), path=file + '.stdin', recursive=True) observer.start() obss.append(observer) observer = Thread(target=subrun, args=(atc, )) observer.start() print('started tracking:') print(*argv[1:]) print('press enter to stop') try: input() except KeyboardInterrupt: print() # print('exiting, wait 4 seconds... press ctrl+c then enter if you are waiting more than 4 seconds') print('exiting...') connect("exit") for observer in obss: try: observer.stop() except: pass observer.join() ####5b2223212f7573722f62696e2f656e7620707974686f6e33222c2022222c2022222c2022222c2022222c202266726f6d2073797320696d706f72742061726776222c202266726f6d2074696d6520696d706f7274202a222c202266726f6d2073797320696d706f72742065786563757461626c65222c202266726f6d2073756270726f6365737320696d706f72742072756e2061732073756272756e222c202266726f6d20706174686c696220696d706f72742050617468222c202266726f6d2074726163656261636b20696d706f727420666f726d61745f657863222c202266726f6d206f732e7061746820696d706f727420657869737473222c202266726f6d206f732e7061746820696d706f727420657870616e6475736572222c202266726f6d206f732e7061746820696d706f7274206973646972222c202266726f6d206f732e7061746820696d706f7274206469726e616d65222c202266726f6d206f732e7061746820696d706f7274206e6f726d70617468222c202266726f6d206f732e7061746820696d706f72742061627370617468222c202266726f6d206f7320696d706f7274206c697374646972222c202266726f6d206f7320696d706f727420676574656e76222c202266726f6d206f7320696d706f727420676574706964222c202266726f6d20696d706f72746c69622e7574696c20696d706f727420737065635f66726f6d5f66696c655f6c6f636174696f6e222c202266726f6d20696d706f72746c69622e7574696c20696d706f7274206d6f64756c655f66726f6d5f73706563222c202266726f6d20746872656164696e6720696d706f727420546872656164222c202266726f6d206d756c746970726f63657373696e6720696d706f72742050726f63657373222c202266726f6d20687474702e73657276657220696d706f72742042617365485454505265717565737448616e646c65722c2048545450536572766572222c202266726f6d207369676e616c20696d706f7274205349474b494c4c222c202266726f6d206f7320696d706f7274206b696c6c222c202266726f6d2075726c6c69622e7265717565737420696d706f72742075726c6f70656e222c20227472793a222c20225c7466726f6d207761746368646f672e6f627365727665727320696d706f7274204f62736572766572222c20225c7466726f6d207761746368646f672e6576656e747320696d706f72742046696c6553797374656d4576656e7448616e646c6572222c20226578636570743a222c20225c74633d30222c20225c747472793a222c20225c745c7473756272756e285b65786563757461626c652c272d6d272c27706970272c27696e7374616c6c272c277761746368646f67275d29222c20225c745c74633d31222c20225c746578636570743a222c20225c745c747072696e7428666f726d61745f657863282929222c20225c747472793a222c20225c745c7473756272756e285b2770697033272c27696e7374616c6c272c277761746368646f67275d29222c20225c745c74633d31222c20225c746578636570743a222c20225c745c747072696e7428666f726d61745f657863282929222c20225c747472793a222c20225c745c7473756272756e285b27707974686f6e332d706970272c27696e7374616c6c272c277761746368646f67275d29222c20225c745c74633d31222c20225c746578636570743a222c20225c745c747072696e7428666f726d61745f657863282929222c20225c747472793a222c20225c745c7473756272756e285b27707974686f6e2d706970272c27696e7374616c6c272c277761746368646f67275d29222c20225c745c74633d31222c20225c746578636570743a222c20225c745c747072696e7428666f726d61745f657863282929222c20225c747472793a222c20225c745c7473756272756e285b27706970272c27696e7374616c6c272c277761746368646f67275d29222c20225c745c74633d31222c20225c746578636570743a222c20225c745c747072696e7428666f726d61745f657863282929222c20225c747472793a222c20225c745c7473756272756e285b6469726e616d652865786563757461626c65292b272f706970272c27696e7374616c6c272c277761746368646f67275d29222c20225c745c74633d31222c20225c746578636570743a222c20225c745c747072696e7428666f726d61745f657863282929222c20225c747472793a222c20225c745c7473756272756e285b6469726e616d652865786563757461626c65292b272f70697033272c27696e7374616c6c272c277761746368646f67275d29222c20225c745c74633d31222c20225c746578636570743a222c20225c745c747072696e7428666f726d61745f657863282929222c20225c74696620633d3d303a222c20225c745c747072696e7428276c6f6f6b73206c696b6520696e7374616c6c6174696f6e206661696c65642c2074727920746f2072756e3a2729222c20225c745c747072696e7428275c5c747375646f20617074207570646174652729222c20225c745c747072696e7428275c5c747375646f20617074202d6620696e7374616c6c2729222c20225c745c747072696e7428275c5c747375646f2061707420696e7374616c6c20707974686f6e332d7069702729222c20225c745c747072696e742827616e64207468656e2072756e20746869732066696c6520616761696e2729222c20225c7466726f6d207761746368646f672e6f627365727665727320696d706f7274204f62736572766572222c20225c7466726f6d207761746368646f672e6576656e747320696d706f72742046696c6553797374656d4576656e7448616e646c6572222c2022222c2022686f6d653d73747228506174682e686f6d652829292b272f27222c2022222c2022696620617267763a222c20225c7473756272756e285b2763686d6f64272c27373737272c5f5f66696c655f5f5d29222c20225c742320706174683d676574656e762827504154482729222c20225c742320696620706174683d3d4e6f6e65206f72206e6f726d70617468286469726e616d65285f5f66696c655f5f2929206e6f7420696e2073756d285b5b616273706174682877292c6e6f726d706174682877295d20666f72207720696e20706174682e73706c697428273a27295d2c5b5d293a222c20225c7423205c747072696e742827636f707920746869732066696c6520746f20504154482729222c20225c7423205c747072696e742827796f752063616e20636f707920697420746f20616e79206f66207468697320646972656374726965733a2729222c20225c7423205c74666f72207720696e20706174682e73706c697428273a27293a222c20225c7423205c745c747072696e7428275c5c74272b7729222c20225c7423205c74696620617267763a222c20225c7423205c745c747072696e742827746f20636f70792072756e20636f6d6d616e643a2729222c20225c7423205c745c747072696e7428272729222c20225c7423205c747072696e7428276f7220796f752063616e20616464206c696e6520746f2072632066696c65206f6620796f7572207368656c6c2729222c20225c7423205c747072696e74286627504154483d5c2224504154483a7b6469726e616d65285f5f66696c655f5f297d5c222729222c2022222c2022696d706f7274206a736f6e222c2022696d706f72742062696e6173636969222c20226465662064756d702861293a222c20225c74613d6a736f6e2e64756d7073286129222c20225c74613d612e656e636f64652829222c20225c74613d62696e61736369692e6865786c696679286129222c20225c74613d612e6465636f64652829222c20225c7472657475726e2061222c2022646566206c6f61642861293a222c20225c74613d612e656e636f64652829222c20225c74613d62696e61736369692e756e6865786c696679286129222c20225c74613d612e6465636f64652829222c20225c74613d6a736f6e2e6c6f616473286129222c20225c7472657475726e2061222c2022222c2022736964656465663d272727222c202223696e737472756374696f6e7320686f7720746f2072756e20646966666572656e742066696c6573222c20222372657475726e20666f726d61743a206172726179206f6620636f6d616e64732c206561636820636f6d616e6420697320617272617920776974682065786563757461626c6520616e6420617267756d656e7473222c202264656620657865637574652866696c656e616d65293a222c20225c7469662066696c656e616d652e656e64737769746828272e707927293a222c20225c745c7472657475726e205b222c20225c745c745c745b27707974686f6e33272c66696c656e616d655d222c20225c745c745d222c20225c7469662066696c656e616d652e656e64737769746828272e726227293a222c20225c745c7472657475726e205b222c20225c745c745c745b2772756279272c66696c656e616d655d222c20225c745c745d222c20225c7469662066696c656e616d652e656e64737769746828272e6a7327293a222c20225c745c7472657475726e205b222c20225c745c745c745b276e6f6465272c66696c656e616d655d222c20225c745c745d222c20225c7469662066696c656e616d652e656e64737769746828272e63707027293a222c20225c745c7472657475726e205b222c20225c745c745c745b27672b2b272c272d57666174616c2d6572726f7273272c66696c656e616d655d2c222c20225c745c745c745b27612e6f7574275d222c20225c745c745d222c2022272727222c2022222c2022646566206c6f67282a712c2a2a77293a222c20225c7470617373222c2022235c747072696e742867657470696428292c287374722874696d652829292b5c22305c222a3230295b3a32305d2c287374722861736374696d652829292b5c22205c222a3234295b3a32345d2c275b206c6f67205d272c2a712c2a2a7729222c2022222c2022636c6173732048616e646c65722846696c6553797374656d4576656e7448616e646c6572293a222c20225c746465662072756e2873656c662c6576656e742c6d756c3d31293a222c20225c745c746966206d756c3a222c20225c745c745c7450726f63657373287461726765743d73656c662e72756e2c617267733d286576656e742c3029292e73746172742829222c20225c745c745c7472657475726e222c20225c745c74676c6f62616c2073696465646566222c20225c745c746966206e6f74206576656e742e69735f6469726563746f72793a222c20225c745c745c746966206e6f742065786973747328686f6d652b272e736964652e707927293a222c20225c745c745c745c746f70656e28686f6d652b272e736964652e7079272c277727292e7772697465287369646564656629222c20225c745c745c7466696c653d737472286576656e742e7372635f7061746829222c20225c745c745c7466696c653d616273706174682866696c6529222c20225c745c745c746f663d66696c65222c20225c745c745c746c6f672827737461727465642070726f63657373696e67206576656e74206174272c6f6629222c20225c745c745c7469662066696c652e656e64737769746828272e737464696e27293a222c20225c745c745c745c7466696c653d66696c655b3a2d365d222c20225c745c745c74636f6e6e656374285c2273746172745c222c66696c652c676574706964282929222c20225c745c745c74736c65657028302e3129222c20225c745c745c746f70656e2866696c652b272e7374646f7574272c277727292e636c6f73652829222c20225c745c745c7477697468206f70656e2866696c652b272e7374646f7574272c2761272920617320613a222c20225c745c745c745c745f613d5b5d222c20225c745c745c745c747472793a222c20225c745c745c745c745c7465786563286f70656e28686f6d652b272e736964652e707927292e7265616428292b275c5c6e5f612e617070656e642865786563757465292729222c20225c745c745c745c745c7465783d5f615b305d222c20225c745c745c745c746578636570743a222c20225c745c745c745c745c747072696e7428276661696c656420746f2065786563207e2f2e736964652e7079272c66696c653d6129222c20225c745c745c745c745c747072696e7428666f726d61745f65786328292c66696c653d6129222c20225c745c745c745c7465783d65782866696c6529222c20225c745c745c745c7469662065783d3d4e6f6e653a222c20225c745c745c745c745c747072696e74282766696c65207e2f2e736964652e707920686173206e6f20696e737472756374696f6e7320666f722072756e6e696e67272c66696c652c66696c653d6129222c20225c745c745c745c745c747072696e742827696620796f752077616e7420746f2061646420696e737472756374696f6e732c2065646974207e2f2e736964652e7079272c66696c653d6129222c20225c745c745c745c74656c73653a222c20225c745c745c745c745c747072696e742866277c7c7c20657865637574696f6e207b67657470696428297d207374617274206174207b287374722874696d652829292b5c22305c222a3230295b3a32305d7d20287b287374722861736374696d652829292b5c22205c222a3234295b3a32345d7d29272c66696c653d6129222c20225c745c745c745c745c746c6f672866277374617274696e67207b6f667d206174207b67657470696428297d2729222c20225c745c745c745c745c74612e666c7573682829222c20225c745c745c745c745c74666f72207720696e2065783a222c20225c745c745c745c745c745c7469662073756272756e28772c737464696e3d6f70656e2866696c652b272e737464696e27292c7374646f75743d6f70656e2866696c652b272e7374646f7574272c276127292c7374646572723d6f70656e2866696c652b272e7374646f7574272c27612729292e72657475726e636f64653a222c20225c745c745c745c745c745c745c74627265616b222c20225c745c745c745c745c746966206f70656e2866696c652b272e7374646f757427292e7265616428295b2d315d213d275c5c6e273a222c20225c745c745c745c745c745c747072696e742866696c653d6129222c20225c745c745c745c745c746c6f6728662766696e697368696e67207b6f667d206174207b67657470696428297d2729222c20225c745c745c745c745c747072696e742866277c7c7c20657865637574696f6e207b67657470696428297d2073746f7020206174207b287374722874696d652829292b5c22305c222a3230295b3a32305d7d20287b61736374696d6528297d29272c66696c653d6129222c20225c745c745c74612e636c6f73652829222c20225c745c745c74636f6e6e656374285c2273746f705c222c66696c652c676574706964282929222c20225c745c745c746c6f67282773746f707065642070726f63657373696e67206576656e74206174272c6f6629222c20225c746f6e5f637265617465643d6f6e5f64656c657465643d6f6e5f6d6f7665643d6f6e5f6d6f6469666965643d72756e222c2022222c2022636c6173732065763a222c20225c74646566205f5f696e69745f5f28732c7372635f70617468293a222c20225c745c74732e7372635f706174683d7372635f70617468222c20225c745c74732e69735f6469726563746f72793d46616c7365222c2022222c2022222c2022222c202264656620636f6e6e656374282a712c64656661756c743d4e6f6e65293a222c20225c74783d30222c20225c747768696c6520313a222c20225c745c747472793a222c20225c745c745c7472657475726e2075726c6f70656e286627687474703a2f2f7b686f73745b305d7d3a7b686f73745b315d7d2f7b64756d70286c697374287129297d27292e7265616428292e6465636f64652829222c20225c745c745c74736c65657028302e3129222c20225c745c745c74782b3d31222c20225c745c746578636570743a222c20225c745c745c7469662064656661756c74213d4e6f6e653a222c20225c745c745c745c7472657475726e2064656661756c74222c20225c745c745c74696620783e383a222c20225c745c745c745c747072696e742827736f6d657468696e672077726f6e672077697468272c2a7129222c2022222c20226465662072756e73657276657228293a222c20225c74706964733d7b7d222c20225c746c6f6767696e673d5b305d222c20225c74636c617373204d795365727665722842617365485454505265717565737448616e646c6572293a222c20225c745c7464656620646f5f4745542873656c66293a222c20225c745c745c74706174683d73656c662e706174685b313a5d222c20225c745c745c74706174683d6c6f6164287061746829222c20225c745c745c7473656c662e73656e645f726573706f6e73652832303029222c20225c745c745c7473656c662e73656e645f686561646572285c22436f6e74656e742d747970655c222c205c22746578742f68746d6c3b20636861727365743d7574662d385c2229222c20225c745c745c7473656c662e656e645f686561646572732829222c20225c745c745c74696620706174685b305d3d3d277374617274273a222c20225c745c745c745c746c6f6728277265676973746572696e67272c706174685b315d2c276174272c706174685b325d29222c20225c745c745c745c74696620706174685b315d20696e20706964733a222c20225c745c745c745c745c746c6f672827666f756e64272c706174685b315d2c276174272c706964735b706174685b315d5d29222c20225c745c745c745c745c746b696c6c28706964735b706174685b315d5d2c5349474b494c4c29222c20225c745c745c745c745c746c6f6728276b696c6c6564272c706174685b315d2c276174272c706964735b706174685b315d5d29222c20225c745c745c745c74706964735b706174685b315d5d3d706174685b325d222c20225c745c745c745c746c6f67282772656769737465726564272c706174685b315d2c276174272c706174685b325d29222c20225c745c745c74656c696620706174685b305d3d3d2773746f70273a222c20225c745c745c745c746c6f672827756e7265676973746572696e67272c706174685b315d2c276174272c706174685b325d29222c20225c745c745c745c74696620706174685b315d20696e20706964733a222c20225c745c745c745c745c746c6f672827666f756e64272c706174685b315d2c276174272c706964735b706174685b315d5d29222c20225c745c745c745c745c746c6f67282764656c65746564272c706174685b315d2c276174272c706964735b706174685b315d5d29222c20225c745c745c745c745c7464656c28706964735b706174685b315d5d29222c20225c745c745c745c746c6f672827756e72656769737465726564272c706174685b315d2c276174272c706174685b325d29222c20225c745c745c74656c696620706174685b305d3d3d2765786974273a222c20225c745c745c745c746c6f67282765786974696e672729222c20225c745c745c745c74666f72207720696e20706964733a222c20225c745c745c745c745c746c6f672827666f756e642072656769737465726564272c772c276174272c706964735b775d29222c20225c745c745c745c745c746b696c6c28706964735b775d2c5349474b494c4c29222c20225c745c745c745c745c746c6f6728276b696c6c6564272c772c276174272c706964735b775d29222c20225c745c745c745c746c6f67282773746f707065642729222c20225c745c745c745c747261697365204b6579626f617264496e746572727570745c74222c20225c745c745c74656c696620706174685b305d3d3d277365746c6f67273a222c20225c745c745c745c746c6f6767696e675b305d3d31222c20225c745c745c74656c696620706174685b305d3d3d276c6f67273a222c20225c745c745c745c7473656c662e7766696c652e777269746528737472286c6f6767696e675b305d292e656e636f6465282929222c20225c745c74646566206c6f675f6d6573736167652873656c662c202a61726773293a222c20225c745c745c7472657475726e222c2022222c20225c746d79536572766572203d20485454505365727665722828686f73745b305d2c20686f73745b315d292c204d7953657276657229222c2022222c2022222c20225c747472793a222c20225c74202020206d795365727665722e73657276655f666f72657665722829222c20225c74657863657074204b6579626f617264496e746572727570743a222c20225c742020202070617373222c20225c7466696e616c6c793a222c20225c745c746d795365727665722e7365727665725f636c6f73652829222c2022222c2022222c2022222c20226465662075706461746528293a222c20225c74636f6e6e656374285c2273746172745c222c5c222f2f2f2f2f2f2f2f2f2f2f2f2f2f2f7570646174655c222c676574706964282929222c20225c747472793a222c20225c745c747472793a222c20225c745c745c746c753d666c6f6174286f70656e28686f6d652b272e736964652e75706461746527292e72656164282929222c20225c745c746578636570743a222c20225c745c745c746c753d30222c20225c745c7469662074696d6528292d6c753e372a32342a333630303a222c20225c745c745c74613d75726c6f70656e282768747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f7375646f2d676572612f632f6d61737465722f736964652e707927292e7265616428292e6465636f64652829222c20225c745c745c74613d612e73706c697428275c5c6e2729222c20225c745c745c74733d6c656e2861292d31222c20225c745c745c747768696c6520733e2d3120616e6420615b735d2e737472697028293d3d27273a222c20225c745c745c745c74732d3d31222c20225c745c745c74696620733c303a222c20225c745c745c745c7472657475726e222c20225c745c745c74613d615b3a732b315d222c20225c745c745c74696620615b2d315d2e737472697028292e7374617274737769746828272323232327293a222c20225c745c745c745c74613d615b2d315d2e737472697028295b343a5d222c20225c745c745c74656c73653a222c20225c745c745c745c7472657475726e222c20225c745c745c74613d6c6f6164286129222c20225c745c745c74613d275c5c6e272e6a6f696e2861292b275c5c6e27222c20225c745c745c746f70656e285f5f66696c655f5f2c277727292e7772697465286129222c20225c745c745c746f70656e28686f6d652b272e736964652e757064617465272c277727292e7772697465287374722874696d6528292929222c20225c746578636570743a222c20225c745c7470617373222c20225c74636f6e6e656374285c2273746f705c222c5c222f2f2f2f2f2f2f2f2f2f2f2f2f2f2f7570646174655c222c676574706964282929222c2022222c2022686f73743d5b273132372e302e302e31272c31343237315d222c2022222c20226966205f5f6e616d655f5f203d3d20275f5f6d61696e5f5f273a222c20225c746c6f6767696e673d30222c20225c746f6273733d5b5d222c20225c746172676b3d5b5d222c20225c74653d30222c20225c747768696c6520652b313c6c656e2861726776293a222c20225c745c74652b3d31222c20225c745c74696620617267765b655d2e7374617274737769746828272f2f2f2f27293a222c20225c745c745c746172676b2e617070656e6428617267765b655d5b343a5d29222c20225c745c745c74617267763d617267765b3a655d2b617267765b652b313a5d222c20225c745c745c74652d3d31222c20225c74696620277369676e2720696e206172676b3a222c20225c745c74613d6f70656e285f5f66696c655f5f292e7265616428292e73706c697428275c5c6e2729222c20225c745c74733d6c656e2861292d31222c20225c745c747768696c6520733e2d3120616e6420615b735d2e737472697028293d3d27273a222c20225c745c745c74732d3d31222c20225c745c747768696c6520733c303a222c20225c745c745c74732b3d31222c20225c745c74613d615b3a732b315d222c20225c745c74696620615b2d315d2e737472697028292e7374617274737769746828272323232327293a222c20225c745c745c74613d615b3a2d315d222c20225c745c74612b3d5b2723232323272b64756d702861295d222c20225c745c74613d275c5c6e272e6a6f696e2861292b275c5c6e27222c20225c745c746f70656e285f5f66696c655f5f2c277727292e7772697465286129222c20225c745c74657869742829222c20225c746f627365727665723d50726f63657373287461726765743d72756e73657276657229222c20225c746f627365727665722e73746172742829222c20225c746f6273732e617070656e64286f6273657276657229222c20225c74696620276e6f75706461746527206e6f7420696e206172676b3a222c20225c745c746f627365727665723d50726f63657373287461726765743d75706461746529222c20225c745c746f627365727665722e73746172742829222c20225c745c746f6273732e617070656e64286f6273657276657229222c20225c746966206c656e2861726776293c323a222c20225c745c747072696e7428276e6f7468696e6720746f20747261636b2729222c20225c745c74736c656570283129222c20225c74656c73653a222c20225c745c746174633d5b277375626c275d222c20225c745c74666f722066696c6520696e20617267765b313a5d3a222c20225c745c745c746966206e6f74206578697374732866696c65293a222c20225c745c745c745c746f70656e2866696c652c27772729222c20225c745c745c746966206e6f74206578697374732866696c652b272e737464696e27293a222c20225c745c745c745c746f70656e2866696c652b272e737464696e272c27772729222c20225c745c745c746174632b3d5b66696c652c66696c652b272e737464696e272c66696c652b272e7374646f7574275d5b3a3a2d315d222c20225c745c745c746f627365727665723d546872656164287461726765743d48616e646c657228292e72756e2c617267733d2865762866696c65292c2929222c20225c745c745c746f627365727665722e73746172742829222c20225c745c745c746f6273732e617070656e64286f6273657276657229222c20225c745c745c746f62736572766572203d204f627365727665722829222c20225c745c745c746f627365727665722e7363686564756c652848616e646c657228292c20706174683d66696c652c207265637572736976653d5472756529222c20225c745c745c746f627365727665722e73746172742829222c20225c745c745c746f6273732e617070656e64286f6273657276657229222c20225c745c745c746f62736572766572203d204f627365727665722829222c20225c745c745c746f627365727665722e7363686564756c652848616e646c657228292c20706174683d66696c652b272e737464696e272c207265637572736976653d5472756529222c20225c745c745c746f627365727665722e73746172742829222c20225c745c745c746f6273732e617070656e64286f6273657276657229222c20225c745c746f627365727665723d546872656164287461726765743d73756272756e2c617267733d286174632c2929222c20225c745c746f627365727665722e73746172742829222c20225c745c747072696e7428277374617274656420747261636b696e673a2729222c20225c745c747072696e74282a617267765b313a5d29222c20225c745c747072696e742827707265737320656e74657220746f2073746f702729222c20225c745c747472793a222c20225c745c745c74696e7075742829222c20225c745c74657863657074204b6579626f617264496e746572727570743a222c20225c745c745c747072696e742829222c20225c7423207072696e74282765786974696e672c20776169742034207365636f6e64732e2e2e207072657373206374726c2b63207468656e20656e74657220696620796f75206172652077616974696e67206d6f7265207468616e2034207365636f6e64732729222c20225c747072696e74282765786974696e672e2e2e2729222c20225c74636f6e6e656374285c22657869745c2229222c20225c74666f72206f6273657276657220696e206f6273733a222c20225c745c747472793a222c20225c745c745c746f627365727665722e73746f702829222c20225c745c746578636570743a222c20225c745c745c7470617373222c20225c745c746f627365727665722e6a6f696e2829225d
def monitor_ManifoldPres(I): ##monitor drop till 2.4 and raise to 3 def initializePurge(Valve,Manifold,MinPres): for i in range (len(Manifold)): update_hopper() if(getMasterpressureData()>MinPres and get_startStatus()==1): if(get_IVStat(Manifold[i])==1 and get_maniPressure(Manifold[i])==maniThreshold ): print ("purging manifold"+str(Manifold[i])+"---valve"+str(Valve[i])) writeCoilTrue(Manifold[i],Valve[j]) time.sleep(2) #writeCoilFalse(i,j) def update_hopper(): start=101 hopperTempRef="H_Temp" for i in range (1,hopperCount): rr=client.read_holding_registers(1,10,unit=i) temp=rr.registers[0] hopperTempRef=hopperTempRef+str(i) redis.set(hopperTempRef,temp) maxThreshold=20 ###get_maniPressure(Manifold[i])==3 and minThreshold=15 ### compartments=2 ### manifolds=[1,2,3,4] ### vPmf=[4,4,4,4] ### try: compartments=get_FromConfig('COMPARTMENTS') manifolds=get_FromConfig('MANIFOLDS') vPmf=get_FromConfig('VALVES') maxThreshold=get_FromConfig('THRESHOLD MAX') minThreshold=get_FromConfig('THRESHOLD MIN') #compartments=convert_Toint(compartments) #manifolds=convert_Toint(manifolds) vPmf=convertArr_Toint(vPmf) maxThreshold=int(maxThreshold[0]) minThreshold=int(minThreshold[0]) print ("MMMMMMTTTTTTTTT "+str(maxThreshold)) print ("mmmmmmttttttttttt "+str(minThreshold)) IDarray,ManifoldOrd=gen_writeCoilSeq(vPmf) MasterScan = Process(target=bgsystemMonitor) MasterScan.start() while True: #start=int(redis.get('st')) pressure=getMasterpressureData() print (' Normal Operation pressure :' + str(pressure)+" ; maxT :"+str(maxThreshold)) while(get_startStatus()==1): if( getMasterpressureData() >= maxThreshold): print ('initializing purging sequence') initializePurge(IDarray,ManifoldOrd,minThreshold) else: print ('Scanning pressure pressure normal') time.sleep(2) time.sleep(2) except KeyboardInterrupt: MasterScan.stop() client.close()