########################################################################### # # 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 DialityCoreCanProtocol import DialityCanMessenger from DialityCoreCanProtocol import DialityPacket from time import sleep """ \mainpage Dialin API Dialin API is comprised primarily by 3 classes: - \ref DialysateGenerator.DG - \ref HemodialysisDevice.HD """ 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, can__interface="can0"): """ DG constructor using can bus \param bus: can bus, e.g. "can0" \returns DG object that allows communication with board via port \details For example: dg_object = DG(can__interface='can0') or dg_object = DG('can0') """ # Create listener self.__can_interface = DialityCanMessenger(can_interface=can__interface) self.__can_interface.start() def fill(self, startOrStop='start'): """ \brief request the DG board to fill \returns True if ran the command, False otherwise """ channel_id = 0x100 msgID = 1000 if startOrStop == 'start': cargo=[1] else: cargo=[0] packet = DialityPacket.buildPacket(request_id=msgID, cargo=cargo) # Send message received_packet = self.__can_interface.send(channel_id, packet) if received_packet is not None: return received_packet[4] else: return False def registerSyncReceiver(self, channel_id, request_id, method): self.__can_interface.registerSyncFunction(channel_id, request_id, method) def test_sync_function(packet): print("s", end="", flush=True) def test_fill_print(packet): if packet is not False: print("f") else: print("t") if __name__ == "__main__": test_dg = DG() sleep(2) test_packet = test_dg.fill('start') test_fill_print(test_packet) sleep(20) test_packet = test_dg.fill('stop') test_fill_print(test_packet) # 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)