########################################################################### # # Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. # # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN # WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # # @file HemodialysisDevice.py # # @date 16-Oct-2019 # @author L. Baloa # # @brief This class allows sending to and receiving from the HD device. # ############################################################################ from DialityCoreSerialProtocol import DialitySerialMessenger from DialityCoreSerialProtocol import DialityPacket from time import sleep class HD: """ \class HD \brief Hemodialysis Device (HD) Dialin object API. It provides the basic interface to communicate with the HD board """ def __init__(self, port="/dev/ttyUSB0"): """ HD constructor using serial port name \param port: serial port name, e.g. "/dev/ttyUSB0" \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') """ # Create listener self.__serialPort = DialitySerialMessenger(serial_port=port) self.__serialPort.start() self.__messageID = 0 def login(self): request_id = 8000 cargo = b'123' message = DialityPacket.buildPacket(request_id=request_id, cargo=cargo) print("login") # Send message received_message = self.__serialPort.send(message) if len(received_message) != 0: print(received_message) print("Logged:" + str(received_message[4])) return received_message[4] else: print("Timeout!!!!") return False def OffButton(self): request_id = 8001 cargo = b'\x00\x01\x00\x00\x00' message = DialityPacket.buildPacket(request_id=request_id, cargo=cargo) print("override off button") # Send message received_message = self.__serialPort.send(message) # If there is content... if len(received_message) != 0: print(received_message) print("Logged:" + str(received_message[4])) # 5th element is OK or not OK return received_message[4] else: print("Timeout!!!!") return False 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__": thehd = HD() # \var thedg sleep(2) thehd.login() sleep(2) thehd.OffButton()