########################################################################### # # 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 DialysateGenerator.py # # @date 16-Oct-2019 # @author L. Baloa # # @brief This class allows sending to and receiving from the DG device. # ############################################################################ from DialityCoreSerialProtocol import DialitySerialMessenger from DialityCoreSerialProtocol import DialityPacket from time import sleep """ \mainpage Dialin API Dialin API is comprised primarily by 3 classes: - \ref DG - \ref HD - \ref UI """ class DG: """ \class DG \brief Dialysate Generator (DG) Dialin object API. It provides the basic interface to communicate with the DG board """ def __init__(self, port="/dev/ttyUSB0"): """ DG constructor using serial port name \param port: serial port name, e.g. "/dev/ttyUSB0" \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') """ # Create listener self.__serialPort = DialitySerialMessenger(serial_port=port) self.__serialPort.start() def fill(self): """ \brief request the DG board to fill \returns True if ran the command, False otherwise """ requestID = 3 cargo = bytearray() message = DialityPacket.buildPacket(request_id=requestID, cargo=cargo) print("fill") # Send message received_message = self.__serialPort.send(message) if len(received_message) != 0: print("Return:" + str(received_message[4])) 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__": thedg = DG() # \var thedg sleep(2) thedg.fill() sleep(2) thedg.fill() sleep(1) thedg.fill() sleep(2) thedg.fill()