Index: DialysateGenerator.py =================================================================== diff -u -r5f23b5ca87b6211702df8aa805fa767026862b77 -r147d938705b0e7c20ff1b7fe8fc92a43a4e00667 --- DialysateGenerator.py (.../DialysateGenerator.py) (revision 5f23b5ca87b6211702df8aa805fa767026862b77) +++ DialysateGenerator.py (.../DialysateGenerator.py) (revision 147d938705b0e7c20ff1b7fe8fc92a43a4e00667) @@ -14,11 +14,9 @@ # ############################################################################ -from DialityCoreSerialProtocol import DialitySerialMessenger -from DialityCoreSerialProtocol import DialityPacket +from DialityCoreCanProtocol import * from time import sleep - """ \mainpage Dialin API Dialin API is comprised primarily by 3 classes: @@ -27,77 +25,92 @@ - \ref HemodialysisDevice.HD """ + +def PublicationReceiverHandler(message): + print(".", end='', flush=True) + + class DG: """ \class DG - \brief Dialysate Generator (DG) Dialin object API. It provides the basic interface to communicate with + Dialysate Generator (DG) Dialin object API. It provides the basic interface to communicate with the DG board """ - def __init__(self, port="/dev/ttyUSB0"): + DG_MSG_ID_FILL_COMMAND = 0x2000 + DG_MSG_ID_BROADCAST = 0X2100 + + def __init__(self, can__interface="can0"): """ - DG constructor using serial port name + DG constructor using can bus - \param port: serial port name, e.g. "/dev/ttyUSB0" + \param can__interface: string with can bus name, e.g. "can0" \returns DG object that allows communication with board via port \details For example: - dg_object = DG(port='/dev/ttyUSB69') or - dg_object = DG('/dev/ttyUSB69') + dg_object = DG(can__interface='can0') or + dg_object = DG('can0') """ # Create listener - self.__serialPort = DialitySerialMessenger(serial_port=port) - self.__serialPort.start() + self.__can_interface = DenaliCanMessenger(can_interface=can__interface) + self.__can_interface.registerReceivingPublicationFunction(channel_id=DenaliChannels.dg_sync_broadcast_ch_id, + message_id=self.DG_MSG_ID_BROADCAST, + function=PublicationReceiverHandler) + self.__can_interface.start() - def fill(self): + def fill(self, start_or_stop='start'): """ - \brief request the DG board to fill + request the DG board to 'start' or to 'stop' fill - \returns True if ran the command, False otherwise + \param start_or_stop is a string indicating which action to take, e.g., 'start' or 'stop' + + \returns True if ran the command, False otherwise, returns None if timeout """ - requestID = 3 - cargo = bytearray() + payload = [1] if start_or_stop == 'start' else [0] - message = DialityPacket.buildPacket(request_id=requestID, cargo=cargo) + msg = DenaliMessage.buildMessage(channel_id=DenaliChannels.hd_to_dg_ch_id, + message_id=self.DG_MSG_ID_FILL_COMMAND, + payload=payload) - print("fill") - # Send message - received_message = self.__serialPort.send(message) + received_msg = self.__can_interface.send(msg) + returnValue = None - if len(received_message) != 0: + if received_msg is not None: + returnValue = True if DenaliMessage.getPayload(received_msg)[0] == 1 else False - print("Return:" + str(received_message[4])) + return returnValue - return received_message[4] - else: - print("Timeout!!!!") - return False +def test_fill_print(msg): + if msg is not None: + print("f", end='', flush=True) + else: + print("t", end='', flush=True) - def registerAsyncReceiver(self, message_id, method): - t1 = method - t2 = message_id - def registerSyncReceiver(self, message_id, method): - t1 = method - t2 = message_id - if __name__ == "__main__": + test_dg = DG() - thedg = DG() # \var thedg - sleep(2) - thedg.fill() - sleep(2) - thedg.fill() - sleep(1) - thedg.fill() + test_packet = test_dg.fill('start') + test_fill_print(test_packet) - sleep(2) - thedg.fill() + sleep(10) + test_packet = test_dg.fill('stop') + test_fill_print(test_packet) + +# del test_dg + +# sleep(1) +# test_packet = test_dg.fill('start') +# test_fill_print(test_packet) + +# sleep(2) +# test_packet = test_dg.fill('start') +# test_fill_print(test_packet)