Index: DialysateGenerator.py =================================================================== diff -u -r45dc69508ab8752571ff888887a59c6d7d12ff05 -rabd93c1d800178a5ee618b9bba83532b853e3c96 --- DialysateGenerator.py (.../DialysateGenerator.py) (revision 45dc69508ab8752571ff888887a59c6d7d12ff05) +++ DialysateGenerator.py (.../DialysateGenerator.py) (revision abd93c1d800178a5ee618b9bba83532b853e3c96) @@ -1,21 +1,31 @@ -""" - \file DialysateGeneraator.py - \brief Comprises API interface for the DG board. +########################################################################### +# +# 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 START_BYTE +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: @@ -43,19 +53,34 @@ # Create listener self.__serialPort = DialitySerialMessenger(serial_port=port) self.__serialPort.start() - self.__messageID = 0 def fill(self): + """ + \brief request the DG board to fill - # Send fill message - message = bytearray([int.from_bytes(START_BYTE, byteorder="big"), 0, 0, 0, 0]) - self.__messageID = 0 + \returns True if ran the command, False otherwise + """ - print("fill sent") + requestID = 3 + cargo = bytearray() + message = DialityPacket.buildPacket(request_id=requestID, cargo=cargo) + + print("fill") + # Send message - self.__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 @@ -64,22 +89,6 @@ t1 = method t2 = message_id - def __send(self, a_message): - # First calculate CRC - a_message[-1] = self.__calculate_crc(a_message) - - # Send command via serial port - self.__serialPort.write(a_message) - - # Check message ID - - self.__messageID = int.from_bytes(a_message[1:2], byteorder='big', signed=False) - - def __calculate_crc(self, a_message): - # a_command includes the last byte for crc - return sum(a_message[0:-1]) % 256 - - if __name__ == "__main__": thedg = DG() # \var thedg