def main(): # input parsing stuff try: from Queue import Queue, Empty except ImportError: from queue import Queue, Empty # python 3.x ON_POSIX = "posix" in sys.builtin_module_names def enqueue_output(out, queue): for line in iter(out.readline, b""): queue.put(line) out.close() config = ConfigParser.RawConfigParser() config.read("boxconfig.txt") waitSecs = config.getint("general", "seconds_box_is_unlocked") lock = solenoid(config.getint("lock", "pin"), waitSecs) containerIDInputHostPath = config.get("container_id_input_host", "ENTRY_POINT") containerIDInputHostArgs = config.get("container_id_input_host", "ARGS") containerIDInputHostTarget = [] containerIDInputHostTarget.append(containerIDInputHostPath) containerIDInputHostTarget.extend(containerIDInputHostArgs.split(str=";")) containerIDInputHost = Popen(containerIDInputHostTarget, stdout=PIPE, stderr=PIPE, bufsize=50, close_fds=ON_POSIX) inputQueue = Queue() inputQueueWatcher = Thread(target=enqueue_output, args=(containerIDInputHost.stdout, inputQueue)) inputQueueWatcher.daemon = True # thread dies with the program inputQueueWatcher.start() RESTClient = ComponentRESTClient() while True: idInput = "" while idInput == "": try: idInput = inputQueue.get_nowait() except Empty: pass if RESTClinet.CheckInBox(idInput): print("RFID accepted") lock.unlockThenLock() else: print("RFID rejected")
def main(): testLock = solenoid(4, 5) testLock.unlockThenLock()