Index: HemodialysisDevice.py =================================================================== diff -u -r194ee2ccf460b9e05ff7969a9ca258ec757bc239 -r680670f948d164932a6a68effa940bd8455e820e --- HemodialysisDevice.py (.../HemodialysisDevice.py) (revision 194ee2ccf460b9e05ff7969a9ca258ec757bc239) +++ HemodialysisDevice.py (.../HemodialysisDevice.py) (revision 680670f948d164932a6a68effa940bd8455e820e) @@ -14,8 +14,8 @@ # ############################################################################ -from DialityCoreSerialProtocol import DialitySerialMessenger -from DialityCoreSerialProtocol import DialityPacket +from DialityCoreCanProtocol import DialityCanMessenger +from DialityCoreCanProtocol import DialityPacket from time import sleep from binascii import unhexlify @@ -28,23 +28,22 @@ """ - def __init__(self, port="/dev/ttyUSB0"): + def __init__(self, can__interface="can0"): """ - HD constructor using serial port name + HD constructor using can bus - \param port: serial port name, e.g. "/dev/ttyUSB0" + \param bus: can bus, e.g. "can0" \returns HD object that allows communication with board via port \details For example: - hd_object = HD(port='/dev/ttyUSB69') or - hd_object = HD('/dev/ttyUSB69') + hd_object = HD(can__interface='can0') or + hd_object = HD('can0') """ # Create listener - self.__serialPort = DialitySerialMessenger(serial_port=port) - self.__serialPort.start() - self.__messageID = 0 + self.__can_interface = DialityCanMessenger(can_interface=can__interface) + self.__can_interface.start() def login(self): """ @@ -54,6 +53,7 @@ """ + channel_id = 0x400 request_id = 0x8000 cargo = b'123' @@ -62,16 +62,12 @@ print("login") # Send message - received_message = self.__serialPort.send(message) + received_message = self.__can_interface.send(channel_id, message) - if len(received_message) != 0: - + if received_message is not None: print(received_message) - - print("Logged:" + str(received_message[4])) - + print("Logged In: " + str(received_message[4])) return received_message[4] - else: print("Timeout!!!!") return False @@ -86,6 +82,7 @@ \returns 1 if successful, zero otherwise """ + channel_id = 0x400 request_id = 0x8001 cargo = msg @@ -94,18 +91,14 @@ print("insert HD message") # Send message - received_message = self.__serialPort.send(message) + received_message = self.__can_interface.send(channel_id, message) # If there is content... - if len(received_message) != 0: - + if received_message is not None: print(received_message) - print("Inserted message: " + str(received_message[4])) - # 5th element is OK or not OK return received_message[4] - else: print("Timeout!!!!") return False @@ -122,6 +115,7 @@ \returns 1 if successful, zero otherwise """ + channel_id = 0x400 request_id = 0x8002 rst = self.__integer2ByteArray(reset) @@ -133,18 +127,14 @@ print("override off button") # Send message - received_message = self.__serialPort.send(message) + received_message = self.__can_interface.send(channel_id, message) # If there is content... - if len(received_message) != 0: - + if received_message is not None: print(received_message) - print("Off button overridden to " + ("pressed" if state != 0 else "released") + ":" + str(received_message[4])) - # 5th element is OK or not OK return received_message[4] - else: print("Timeout!!!!") return False @@ -160,6 +150,7 @@ \returns 1 if successful, zero otherwise """ + channel_id = 0x400 request_id = 0x8003 rst = self.__integer2ByteArray(reset) @@ -171,18 +162,14 @@ print("override stop button") # Send message - received_message = self.__serialPort.send(message) + received_message = self.__can_interface.send(channel_id, message) # If there is content... - if len(received_message) != 0: - + if received_message is not None: print(received_message) - print("Stop button overridden to " + ("pressed" if state != 0 else "released") + ":" + str(received_message[4])) - # 5th element is OK or not OK return received_message[4] - else: print("Timeout!!!!") return False @@ -207,6 +194,7 @@ 6 = manual """ + channel_id = 0x400 request_id = 0x8004 rst = self.__integer2ByteArray(reset) @@ -218,13 +206,11 @@ print("override alarm lamp pattern") # Send message - received_message = self.__serialPort.send(message) + received_message = self.__can_interface.send(channel_id, message) # If there is content... - if len(received_message) != 0: - + if received_message is not None: print(received_message) - if pattern == 0: str_pat = "off" elif pattern == 1: @@ -239,12 +225,9 @@ str_pat = "low" else: str_pat = "manual" - print("Alarm lamp pattern overridden to " + str_pat + ":" + str(received_message[4])) - # 5th element is OK or not OK return received_message[4] - else: print("Timeout!!!!") return False @@ -261,6 +244,7 @@ \returns 1 if successful, zero otherwise """ + channel_id = 0x400 request_id = 0x8005 rst = self.__integer2ByteArray(reset) @@ -273,18 +257,14 @@ print("override watchdog task check-in state") # Send message - received_message = self.__serialPort.send(message) + received_message = self.__can_interface.send(channel_id, message) # If there is content... - if len(received_message) != 0: - + if received_message is not None: print(received_message) - print("Watchdog task check-in overridden to " + ("checked in" if state != 0 else "not checked in") + ":" + str(received_message[4])) - # 5th element is OK or not OK return received_message[4] - else: print("Timeout!!!!") return False @@ -301,6 +281,7 @@ \returns 1 if successful, zero otherwise """ + channel_id = 0x400 request_id = 0x8006 rst = self.__integer2ByteArray(reset) @@ -313,18 +294,14 @@ print("override alarm state") # Send message - received_message = self.__serialPort.send(message) + received_message = self.__can_interface.send(channel_id, message) # If there is content... - if len(received_message) != 0: - + if received_message is not None: print(received_message) - print("Alarm state overridden to " + ("active" if state != 0 else "inactive") + ":" + str(received_message[4])) - # 5th element is OK or not OK return received_message[4] - else: print("Timeout!!!!") return False @@ -341,6 +318,7 @@ \returns 1 if successful, zero otherwise """ + channel_id = 0x400 request_id = 0x8007 rst = self.__integer2ByteArray(reset) @@ -353,18 +331,14 @@ print("override alarm time since activated") # Send message - received_message = self.__serialPort.send(message) + received_message = self.__can_interface.send(channel_id, message) # If there is content... - if len(received_message) != 0: - + if received_message is not None: print(received_message) - print("Alarm time since activated overridden to " + str(time_ms) + " ms: " + str(received_message[4])) - # 5th element is OK or not OK return received_message[4] - else: print("Timeout!!!!") return False @@ -380,6 +354,7 @@ \returns 1 if successful, zero otherwise """ + channel_id = 0x400 request_id = 0x8008 rst = self.__integer2ByteArray(reset) @@ -391,18 +366,14 @@ print("override blood flow set point") # Send message - received_message = self.__serialPort.send(message) + received_message = self.__can_interface.send(channel_id, message) # If there is content... - if len(received_message) != 0: - + if received_message is not None: print(received_message) - print("Blood flow set point overridden to " + str(flow) + " mL/min: " + str(received_message[4])) - # 5th element is OK or not OK return received_message[4] - else: print("Timeout!!!!") return False @@ -418,6 +389,7 @@ \returns 1 if successful, zero otherwise """ + channel_id = 0x400 request_id = 0x8009 rst = self.__integer2ByteArray(reset) @@ -429,18 +401,14 @@ print("override measured blood flow") # Send message - received_message = self.__serialPort.send(message) + received_message = self.__can_interface.send(channel_id, message) # If there is content... - if len(received_message) != 0: - + if received_message is not None: print(received_message) - print("Blood flow (measured)) overridden to " + str(flow) + " mL/min: " + str(received_message[4])) - # 5th element is OK or not OK return received_message[4] - else: print("Timeout!!!!") return False @@ -456,6 +424,7 @@ \returns 1 if successful, zero otherwise """ + channel_id = 0x400 request_id = 0x800A rst = self.__integer2ByteArray(reset) @@ -467,18 +436,14 @@ print("override measured blood pump speed") # Send message - received_message = self.__serialPort.send(message) + received_message = self.__can_interface.send(channel_id, message) # If there is content... - if len(received_message) != 0: - + if received_message is not None: print(received_message) - print("Blood pump speed (measured) overridden to " + str(speed) + " RPM: " + str(received_message[4])) - # 5th element is OK or not OK return received_message[4] - else: print("Timeout!!!!") return False @@ -494,6 +459,7 @@ \returns 1 if successful, zero otherwise """ + channel_id = 0x400 request_id = 0x800B rst = self.__integer2ByteArray(reset) @@ -505,18 +471,14 @@ print("override measured blood pump motor current") # Send message - received_message = self.__serialPort.send(message) + received_message = self.__can_interface.send(channel_id, message) # If there is content... - if len(received_message) != 0: - + if received_message is not None: print(received_message) - print("Blood pump current (measured) overridden to " + str(curr) + " mA: " + str(received_message[4])) - # 5th element is OK or not OK return received_message[4] - else: print("Timeout!!!!") return False @@ -547,4 +509,4 @@ thehd.login() sleep(2) - thehd.OffButton() + thehd.OffButtonOverride(0,1)