import sys sys.path.append("..") from dialin.dg.dialysate_generator import DG from dialin.dg.drain_pump import DrainPumpStates from time import sleep def get_flush_mode_info(): info = ('State, {}, Overall_elapsed_time, {}, State_elapsed_time, {}, Drain_vol, {:5.3f}, ' .format(dg.flush.flush_state, dg.flush.overall_elapsed_time, dg.flush.state_elapsed_time, dg.flush.flush_drain_line_volume)) return info def get_dg_valves_states(): info = ('VPi, {}, VSP, {}, VPd, {}, VBf, {}, VPo, {}, VDr, {}, VRc, {}, VRo, {}, VRd, {}, VRi, {}, VRf, {}, ' .format(dg.valves.valve_states_enum[dg.valves.VALVE_PRESSURE_INLET], dg.valves.valve_states_enum[dg.valves.VALVE_SAMPLING_PORT], dg.valves.valve_states_enum[dg.valves.VALVE_PRODUCTION_DRAIN], dg.valves.valve_states_enum[dg.valves.VALVE_BYPASS_FILTER], dg.valves.valve_states_enum[dg.valves.VALVE_PRESSURE_OUTLET], dg.valves.valve_states_enum[dg.valves.VALVE_DRAIN], dg.valves.valve_states_enum[dg.valves.VALVE_RECIRCULATE], dg.valves.valve_states_enum[dg.valves.VALVE_RESERVOIR_OUTLET], dg.valves.valve_states_enum[dg.valves.VALVE_RESERVOIR_DRAIN], dg.valves.valve_states_enum[dg.valves.VALVE_RESERVOIR_INLET], dg.valves.valve_states_enum[dg.valves.VALVE_RESERVOIR_FILL])) return info def get_drain_states_info(): info = ('Drain, {}, DAC, {}, RPM, {}, PRd, {:5.3f}, PDr, {:5.3f}, '. format(DrainPumpStates(dg.drain_pump.drain_pump_state).name, dg.drain_pump.dac_value, dg.drain_pump.current_drain_pump_rpm, dg.pressures.drain_pump_inlet_pressure, dg.pressures.drain_pump_outlet_pressure)) return info def get_load_cells_info(): info = ('A1, {:5.3f}, A2, {:5.3f}, B1, {:5.3f}, B2, {:5.3f}, '. format(dg.load_cells.load_cell_A1, dg.load_cells.load_cell_A2, dg.load_cells.load_cell_B1, dg.load_cells.load_cell_B2)) return info def get_ro_info(): info = ('RO, {}, PPi, {:5.3f}, PPo, {:5.3f}, PWM, {:5.3f}, Flow, {:5.3f}, ' .format(dg.ro_pump.ro_pump_state, dg.pressures.ro_pump_inlet_pressure, dg.pressures.ro_pump_outlet_pressure, dg.ro_pump.pwm_duty_cycle_pct, dg.ro_pump.measured_flow_rate_lpm)) return info def run_flush_mode(): complete_counter = 1 f = open("/home/fw/projects/dialin/tests/Flush_mode.log", "w") dg.hd_proxy.cmd_start_stop_dg_flush() try: while True: flush = get_flush_mode_info() load_cell = get_load_cells_info() drain = get_drain_states_info() ro = get_ro_info() valves = get_dg_valves_states() var = flush + load_cell + drain + ro + valves + '\r' print(var) f.write(var) sleep(1) # If the mode came back to standby or standby solo if dg.dg_operation_mode == 3 or dg.dg_operation_mode == 4: # If it is the first call, stop heat disinfect if complete_counter == 1: dg.hd_proxy.cmd_start_stop_dg_flush(start=False) # Write a few more complete states to make sure the complete state items are recorded elif complete_counter == 3: f.close() break complete_counter += 1 except KeyboardInterrupt: dg.hd_proxy.cmd_start_stop_dg_flush(start=False) f.close() if __name__ == "__main__": dg = DG(log_level='DEBUG') dg.cmd_log_in_to_dg() sleep(1) run_flush_mode()