@@ -0,0 +1,2667 @@
+import threading%0Aimport time%0Afrom functools import partial%0Afrom queue import Empty%0A%0Aimport msgpack%0Aimport zmq%0A%0Aimport infupy.backends.fresenius as fresenius%0A%0Azmqhost = '127.0.0.1'%0Azmqport = 4201%0Afreseniusport = 'COM5'%0A%0Adef stateWorker(stopevent):%0A    context = zmq.Context()%0A    zmqsocket = context.socket(zmq.PUB)%0A    comm = fresenius.FreseniusComm(freseniusport)%0A    base = fresenius.FreseniusBase(comm)%0A%0A    paramVolumeWorker = partial(volumeWorker, comm.eventq, zmqsocket, stopevent)%0A    volumeThread = threading.Thread(target=paramVolumeWorker)%0A    volumeThread.start()%0A%0A    while not stopevent.wait(5):%0A        # Check Base%0A        try:%0A            dtype = base.readDeviceType()%0A        except fresenius.CommandError as e:%0A            print(f'Base error: %7Be%7D')%0A            try:%0A                base = fresenius.FreseniusBase(comm)%0A            except fresenius.CommandError as e:%0A                print(f'Failed to connect to base: %7Be%7D')%0A        # Check Syringes%0A        try:%0A            modids = base.listModules()%0A            for modid in modids:%0A                if not modid in base.syringes:%0A                    s = base.connectSyringe(modid)%0A                s.registerEvent(fresenius.VarId.volume)%0A        except fresenius.CommandError as e:%0A            print(f'Attach syringe error: %7Be%7D')%0A    print('Stopping')%0A    volumeThread.join()%0A    print('volumeThread joined')%0A    for s in base.syringes.values():%0A        print(f'Disconnecting syringe %7Bs.index%7D')%0A        s.disconnect()%0A    print(f'Disconnecting Base')%0A    base.disconnect()%0A%0Adef volumeWorker(queue, zmqsocket, stopevent):%0A    while not stopevent.is_set():%0A        try:%0A            dt, origin, inmsg = queue.get(timeout=1)%0A        except Empty:%0A            continue%0A        print(f'Received: %7Borigin%7D %7Binmsg%7D %7Bdt%7D')%0A        try:%0A            volume = fresenius.extractVolume(inmsg)%0A        except ValueError:%0A            print(%22Failed to decode volume from: %7Binmsg%7D%22)%0A            continue%0A        print(f'Volume: %7Bvolume%7D')%0A        timestamp = int(dt.timestamp() * 1e9)%0A        value = %7Bf'syringe%7Borigin%7D_volume' : volume%7D%0A        sample = %7B'basetime' : timestamp, 'data' : value, 'tags' : %7B%7D, 'meta' : %7B%7D%7D%0A        packed = msgpack.packb(sample)%0A        outmsg = b'infupy ' + packed%0A        print(f'Sending: %7Boutmsg%7D')%0A        zmqsocket.send(outmsg)%0A%0A%0Aif __name__ == '__main__':%0A    stopevent = threading.Event()%0A    stateThread = threading.Thread(target=stateWorker, args=%5Bstopevent%5D)%0A    stateThread.start()%0A    while not stopevent.is_set():%0A        try:%0A            time.sleep(1)%0A        except KeyboardInterrupt:%0A            stopevent.set()%0A    stateThread.join()%0A    print('stateThread joined')%0A

Add python script that uses the infupy library and streams to zmq