Index: dialin/hd/valves.py =================================================================== diff -u -r287af45040e35882e001fb3ea835f304007870c4 -r4903294ad7ee4218a2bfc535e3ab85e93d3f1f8f --- dialin/hd/valves.py (.../valves.py) (revision 287af45040e35882e001fb3ea835f304007870c4) +++ dialin/hd/valves.py (.../valves.py) (revision 4903294ad7ee4218a2bfc535e3ab85e93d3f1f8f) @@ -19,26 +19,29 @@ from ..utils.conversions import integer_to_bytearray from .constants import NO_RESET from ..protocols.CAN import (DenaliMessage, DenaliChannels) -from ..utils.base import _AbstractSubSystem, _publish +from ..utils.base import _AbstractSubSystem, _publish, DialinEnum from ..common import MsgIds from logging import Logger -from ..utils.base import DialinEnum +from enum import unique +@unique class ValvesEnum(DialinEnum): VDI = 0 VDO = 1 VBA = 2 VBV = 3 +@unique class ValvesPositions(DialinEnum): VALVE_POSITION_NOT_IN_POSITION = 0 VALVE_POSITION_A_INSERT_EJECT = 1 VALVE_POSITION_B_OPEN = 2 VALVE_POSITION_C_CLOSE = 3 +@unique class ValvesStates(DialinEnum): VALVE_STATE_WAIT_FOR_POST = 0 VALVE_STATE_HOMING_NOT_STARTED = 1 @@ -49,6 +52,7 @@ VALVE_STATE_IN_BYPASS_MODE = 6 +@unique class AirTrapState(DialinEnum): STATE_CLOSED = 0 STATE_OPEN = 1 @@ -61,6 +65,7 @@ \brief Hemodialysis Device (HD) Dialin API sub-class for valves related commands. """ # Valves states publish message field positions + # Note the MsgFieldPosition was not used since some of the published data are S16 START_POS_VALVES_ID = DenaliMessage.PAYLOAD_START_INDEX END_POS_VALVES_ID = START_POS_VALVES_ID + 4 @@ -98,7 +103,7 @@ """ DGDrainPump constructor - \param outer_instance: reference to the DG (outer) class. + @param outer_instance: reference to the DG (outer) class. """ super().__init__() self.can_interface = can_interface @@ -148,16 +153,16 @@ """ Constructs and sends the HD valves set position for a valve - \param valve: integer - Valve number: + @param valve: integer - Valve number: VDI = 0 VDO = 1 VBA = 2 VBV = 3 - \param position: integer - Position number: + @param position: integer - Position number: VALVE_POSITION_A_INSERT_EJECT = 1 VALVE_POSITION_B_OPEN = 2 VALVE_POSITION_C_CLOSE = 3 - \returns 1 if successful, zero otherwise + @returns 1 if successful, zero otherwise """ reset_value = integer_to_bytearray(reset) vlv = integer_to_bytearray(valve) @@ -182,15 +187,15 @@ """ Constructs and sends the HD valves PWM command - \param valve: integer - Valve number: + @param valve: integer - Valve number: VDI = 0 VDO = 1 VBA = 2 VBV = 3 - \param direction: integer - Direction number: + @param direction: integer - Direction number: 0 = Clockwise 1 = Counter clockwise - \returns 1 if successful, zero otherwise + @returns 1 if successful, zero otherwise """ reset_value = integer_to_bytearray(reset) vlv = integer_to_bytearray(valve) @@ -216,12 +221,12 @@ """ Constructs and sends the HD valves home command - \param vavle: integer - Valve number: + @param valve: integer - Valve number: VDI = 0 VDO = 1 VBA = 2 VBV = 3 - \returns 1 if successful, zero otherwise + @returns 1 if successful, zero otherwise """ payload = integer_to_bytearray(valve) @@ -243,7 +248,7 @@ """ Constructs and sends an open/close command to the HD air trap valve - \returns 1 if successful, zero otherwise + @returns 1 if successful, zero otherwise """ if valve_state == AirTrapState.STATE_OPEN: @@ -272,8 +277,8 @@ Handles published HD valves data messages. HD valves data are captured for reference. - \param message: published HD valves data message - \returns none + @param message: published HD valves data message + @returns none """ vlv_ID = struct.unpack('i', bytearray( message['message'][self.START_POS_VALVES_ID:self.END_POS_VALVES_ID]))[0] Index: tests/hd_valves_test.py =================================================================== diff -u -r91dc90bd009bdbf5621dcaa1bc12ab3d691673f7 -r4903294ad7ee4218a2bfc535e3ab85e93d3f1f8f --- tests/hd_valves_test.py (.../hd_valves_test.py) (revision 91dc90bd009bdbf5621dcaa1bc12ab3d691673f7) +++ tests/hd_valves_test.py (.../hd_valves_test.py) (revision 4903294ad7ee4218a2bfc535e3ab85e93d3f1f8f) @@ -14,6 +14,7 @@ # ############################################################################ import sys +import json sys.path.append("..") from dialin.hd.constants import RESET, NO_RESET from dialin.hd.hemodialysis_device import HD @@ -35,25 +36,69 @@ #sleep(2) overall_counter = 0 - sleep_time = 0.01 + sleep_time = 0.05 overall_time_seconds = 4 + loops = 5 + counter = 0 + valve = ValvesEnum.VBV - valves.cmd_home_hd_valve(ValvesEnum.VBA.value) + valves.cmd_hd_valves_broadcast_interval_override(100) sleep(3) - valves.cmd_hd_valves_broadcast_interval_override(10) - sleep(3) + valves.cmd_home_hd_valve(valve.value) + sleep(5) - valves.cmd_set_hd_valve_position(ValvesEnum.VBA.value, ValvesPositions.VALVE_POSITION_C_CLOSE.value) + f = open("Valves_Test_200.txt", "w") - while overall_counter < (overall_time_seconds/sleep_time): + while counter < loops: - print(valves.valves_status[ValvesEnum.VBA.name]) + print('Loop: {}'.format(counter)) + overall_counter = 0 + valves.cmd_set_hd_valve_position(valve.value, ValvesPositions.VALVE_POSITION_B_OPEN.value) - overall_counter = overall_counter + 1 + while overall_counter < (overall_time_seconds/sleep_time): + sleep(sleep_time) + status = ('ID, {}, Pos, {}, PosCnt, {}, Cmd, {}, State, {}, Current, {}, PosA, {}, PosB, {}, PosC, {} \r' + .format(valves.valves_status[valve.name]['Valve'], + valves.valves_status[valve.name]['PosID'], + valves.valves_status[valve.name]['PosCnt'], + valves.valves_status[valve.name]['Cmd'], + valves.valves_status[valve.name]['State'], + valves.valves_status[valve.name]['Current'], + valves.valves_status[valve.name]['PosA'], + valves.valves_status[valve.name]['PosB'], + valves.valves_status[valve.name]['PosC'])) + print(status) + f.write(status) + overall_counter = overall_counter + 1 - sleep(sleep_time) + overall_counter = 0 + valves.cmd_set_hd_valve_position(valve.value, ValvesPositions.VALVE_POSITION_C_CLOSE.value) + while overall_counter < (overall_time_seconds / sleep_time): + sleep(sleep_time) + status = ('ID, {}, Pos, {}, PosCnt, {}, Cmd, {}, State, {}, Current, {}, PosA, {}, PosB, {}, PosC, {} \r' + .format(valves.valves_status[valve.name]['Valve'], + valves.valves_status[valve.name]['PosID'], + valves.valves_status[valve.name]['PosCnt'], + valves.valves_status[valve.name]['Cmd'], + valves.valves_status[valve.name]['State'], + valves.valves_status[valve.name]['Current'], + valves.valves_status[valve.name]['PosA'], + valves.valves_status[valve.name]['PosB'], + valves.valves_status[valve.name]['PosC'])) + print(status) + f.write(status) + overall_counter = overall_counter + 1 + + counter += 1 + + f.close() + + + + + """ print("Reset") #valves.cmd_set_hd_valve_pwm(2, 50, 0) Index: tests/test_hd_valves.py =================================================================== diff -u -r287af45040e35882e001fb3ea835f304007870c4 -r4903294ad7ee4218a2bfc535e3ab85e93d3f1f8f --- tests/test_hd_valves.py (.../test_hd_valves.py) (revision 287af45040e35882e001fb3ea835f304007870c4) +++ tests/test_hd_valves.py (.../test_hd_valves.py) (revision 4903294ad7ee4218a2bfc535e3ab85e93d3f1f8f) @@ -25,7 +25,10 @@ hd = HD() hd.cmd_log_in_to_hd() hd.valves.cmd_hd_valves_broadcast_interval_override(50) + sleep(1) + hd.valves.cmd_home_hd_valve(ValvesEnum.VDI.name) + """ # print params every second for a while while True: sleep(0.100) @@ -55,3 +58,4 @@ hd.valves.valves_status[ValvesEnum.VBV.name]['Current']) exit(1) + """