Exemplo n.º 1
0
    def dln_spislave_set_mode(self, mode):
        """
        Set the SPI mode of the SPI Slave
        :param mode: possible values are
         Mode 0 => DLN_SPI_SLAVE_CPOL_0 | DLN_SPI_SLAVE_CPHA_0
         Mode 1 => DLN_SPI_SLAVE_CPOL_0 | DLN_SPI_SLAVE_CPHA_1
         Mode 2 => DLN_SPI_SLAVE_CPOL_1 | DLN_SPI_SLAVE_CPHA_0
         Mode 3 => DLN_SPI_SLAVE_CPOL_1 | DLN_SPI_SLAVE_CPHA_1
        :return:
        """
        cpol = 0
        cpha = 0
        if mode == 1:
            cpol = 0
            cpha = 1
        if mode == 2:
            cpol = 1
            cpha = 0
        if mode == 3:
            cpol = 1
            cpha = 1
        self._import_module_in_wrapper(DLN_MODULE_SPI_SLAVE)
        enable = self._dlnSpiSlave.dln_spislave_is_enabled(self.__handle, 0)
        if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
            self._dlnSpiSlave.dln_spislave_disable(self.__handle, 0, 0)

        if DLN_SUCCEEDED(self._dlnSpiSlave.dln_spislave_set_cpol(self.__handle, 0, cpol)) and DLN_SUCCEEDED(
                self._dlnSpiSlave.dln_spislave_set_cpha(self.__handle, 0, cpha)):
            res = DLN_RES_SUCCESS
        else:
            res = DLN_RES_FAIL

        if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
            enable = self._dlnSpiSlave.dln_spislave_enable(self.__handle, 0)
        return DLN_SUCCEEDED(enable[0]) and DLN_SUCCEEDED(res)
Exemplo n.º 2
0
 def enable_spislave(self):
     """
     Enable the SPI Slave
     :return: True if success, else False
     """
     self._import_module_in_wrapper(DLN_MODULE_SPI_SLAVE)
     enable = self._dlnSpiSlave.dln_spislave_is_enabled(self.__handle, 0)
     if DLN_SUCCEEDED(enable[0]) and enable[1] == 0:
         enable = self._dlnSpiSlave.dln_spislave_enable(self.__handle, 0)
     return DLN_SUCCEEDED(enable[0])
Exemplo n.º 3
0
    def dln_spislave_get_supported_framesizes(self):
        self._import_module_in_wrapper(DLN_MODULE_SPI_SLAVE)
        enable = self._dlnSpiSlave.dln_spislave_is_enabled(self.__handle, 0)
        if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
            self._dlnSpiSlave.dln_spislave_disable(self.__handle, 0, 0)

        res = self._dlnSpiSlave.dln_spislave_get_supported_framesizes(self.__handle, 0)

        if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
            enable = self._dlnSpiSlave.dln_spislave_enable(self.__handle, 0)
        return DLN_SUCCEEDED(enable[0]) and DLN_SUCCEEDED(res[0]), res[1]
Exemplo n.º 4
0
 def disable_i2cslave(self):
     """
     Disable the I2C Slave
     :return: True if success, else False
     """
     self._import_module_in_wrapper(DLN_MODULE_I2C_SLAVE)
     enable = self._dlnI2cSlave.dln_i2cslave_is_enabled(self.__handle, 0)
     if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
         res = self._dlnI2cSlave.dln_i2cslave_disable(self.__handle, 0, 5)
         return DLN_SUCCEEDED(res)
     else:
         return DLN_SUCCEEDED(enable[0])
Exemplo n.º 5
0
    def dln_spislave_set_framesize(self, framesize):
        """
        Set the frame size of the SPI slave
        """
        self._import_module_in_wrapper(DLN_MODULE_SPI_SLAVE)
        enable = self._dlnSpiSlave.dln_spislave_is_enabled(self.__handle, 0)
        if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
            self._dlnSpiSlave.dln_spislave_disable(self.__handle, 0, 0)

        res = self._dlnSpiSlave.dln_spislave_set_framesize(self.__handle, 0, framesize)

        if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
            enable = self._dlnSpiSlave.dln_spislave_enable(self.__handle, 0)
        return DLN_SUCCEEDED(enable[0]) and DLN_SUCCEEDED(res)
Exemplo n.º 6
0
 def set_i2cslave_address(self, address):
     """
     Set the I2C slave address
     :param address: hexa string containing the address to set
     :return: True if the command was successfully send else False
     """
     self._import_module_in_wrapper(DLN_MODULE_I2C_SLAVE)
     enable = self._dlnI2cSlave.dln_i2cslave_is_enabled(self.__handle, 0)
     if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
         self._dlnI2cSlave.dln_i2cslave_disable(self.__handle, 0, 0)
     res = self._dlnI2cSlave.dln_i2cslave_set_address(self.__handle, 0, 1, int(address, 16))
     if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
         enable = self._dlnI2cSlave.dln_i2cslave_Enable(self.__handle, 0)
     return DLN_SUCCEEDED(enable[0]) and DLN_SUCCEEDED(res)
Exemplo n.º 7
0
 def set_spislave_payload(self, payload):
     """
     Set the payload value of the device witch is read on i2cget
     :param payload: String containing the hex value to load
     :return: True if the payload was successfully set else false
     """
     self._import_module_in_wrapper(DLN_MODULE_SPI_SLAVE)
     enable = self._dlnSpiSlave.dln_spislave_is_enabled(self.__handle, 0)
     if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
         self._dlnSpiSlave.dln_spislave_disable(self.__handle, 0, 0)
     bin_payload = binascii.unhexlify(payload)
     res = self._dlnSpiSlave.dln_spislave_load_reply(self.__handle, 0, len(bin_payload), bin_payload)
     if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
         enable = self._dlnSpiSlave.dln_spislave_enable(self.__handle, 0)
     return DLN_SUCCEEDED(enable[0]) and DLN_SUCCEEDED(res)
Exemplo n.º 8
0
    def enable_i2cslave_notifications(self):
        """
        Enable the I2C Slave notifications
        :return:
        """
        if self._dlnI2cSlave is not None:
            enable = self._dlnI2cSlave.dln_i2cslave_is_enabled(self.__handle, 0)
            if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
                self._dlnI2cSlave.dln_i2cslave_disable(self.__handle, 0, 0)
            from acs_test_scripts.Equipment.IOAdapters.Diolan.Wrapper.DiolanI2CWrapper import DLN_I2C_SLAVE_EVENT_WRITE

            res = self._dlnI2cSlave.dln_i2cslave_set_event(self.__handle, 0, 1, DLN_I2C_SLAVE_EVENT_WRITE)
            if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
                enable = self._dlnI2cSlave.dln_i2cslave_Enable(self.__handle, 0)
            return DLN_SUCCEEDED(enable[0]) and DLN_SUCCEEDED(res)
        else:
            return False
Exemplo n.º 9
0
    def dln_spislave_get_mode(self):
        """
        Set the SPI mode of the SPI Slave
        :return mode: possible values are
         Mode 0 => DLN_SPI_SLAVE_CPOL_0 | DLN_SPI_SLAVE_CPHA_0
         Mode 1 => DLN_SPI_SLAVE_CPOL_0 | DLN_SPI_SLAVE_CPHA_1
         Mode 2 => DLN_SPI_SLAVE_CPOL_1 | DLN_SPI_SLAVE_CPHA_0
         Mode 3 => DLN_SPI_SLAVE_CPOL_1 | DLN_SPI_SLAVE_CPHA_1
        """
        self._import_module_in_wrapper(DLN_MODULE_SPI_SLAVE)
        enable = self._dlnSpiSlave.dln_spislave_is_enabled(self.__handle, 0)
        if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
            self._dlnSpiSlave.dln_spislave_disable(self.__handle, 0, 0)

        res = self._dlnSpiSlave.dln_spislave_get_mode(self.__handle, 0)

        if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
            enable = self._dlnSpiSlave.dln_spislave_enable(self.__handle, 0)
        return DLN_SUCCEEDED(enable[0]) and DLN_SUCCEEDED(res[0]), res[1]
Exemplo n.º 10
0
    def get_i2cslave_address(self):
        """
        Retreive the I2C address of the module
        :return: string containing address in hexa
        """

        self._import_module_in_wrapper(DLN_MODULE_I2C_SLAVE)
        res = self._dlnI2cSlave.dln_i2cslave_get_address(self.__handle, 0, 1)
        if DLN_SUCCEEDED(res[0]):
            return res[1]
Exemplo n.º 11
0
 def get_serial_number(self):
     """
     Return the device serial number
     :return int: serial number
     """
     self._import_module_in_wrapper(DLN_MODULE_GENERIC)
     res = self._dlnGen.DlnGetDeviceSn(self.__handle)
     if DLN_SUCCEEDED(res[0]):
         self._serial_number = res[1]
     return self._serial_number
Exemplo n.º 12
0
 def get_version(self):
     """
     get the versions of the Diolan io adapter
     Hardware_Type_ID | Hardware_model | Hardware_version | Firmware_version | Server_version | Library_Version
     :return: dictionary containing versions information
     """
     self._import_module_in_wrapper(DLN_MODULE_GENERIC)
     res = self._dlnGen.DlnGetVersion(self.__handle)
     if DLN_SUCCEEDED(res[0]):
         self._format_version(res[1])
Exemplo n.º 13
0
    def enable_notification_callback(self):
        """
        Enable the Events from Diolan
        :return:
        """
        self._import_module_in_wrapper(DLN_MODULE_GENERIC)
        from acs_test_scripts.Equipment.IOAdapters.Diolan.Wrapper.DiolanGenWrapper import PDLN_CALLBACK, DLN_NOTIFICATION_TYPE_CALLBACK

        self._dlnCallback = PDLN_CALLBACK(self.py_dlnCallback)
        res = self._dlnGen.dln_register_notification(HDLN_ALL_DEVICES, notification_type=DLN_NOTIFICATION_TYPE_CALLBACK,
                                                   notification_callback=self._dlnCallback)
        self._logger.info("DLN register notification ret = " + str(DLN_SUCCEEDED(res)))
Exemplo n.º 14
0
    def trt_event_notification(self, header, buffer):
        """
        This function handle the I2C Slave events.
        We handle only the write event to modify the reply registry.
        :param header: header structure
        :param buffer: full buffer structure
        :return:
        """
        if header.msgId == DLN_MSG_ID_I2C_SLAVE_WRITE_EV:
            event_struct = DLN_I2C_SLAVE_WRITE_EV.from_buffer_copy(buffer)
            buf = bytearray(event_struct.buffer)
            buf = buf[:event_struct.size]
            write = buf[1:].decode('utf-8')
            # address_index = struct.unpack_from("B", buf[:1])[0] - 1

            if event_struct.size == 1:
                pass
                #master want writing at address
            else:
                # ajust the payload size
                if len(write) > len(self.__fullPayload):
                    to_add = len(write) - len(self.__fullPayload)
                    self.__fullPayload += '\x00' * to_add

                # modify the reply registry
                for count, byte in enumerate(write):
                    payload = list(self.__fullPayload)
                    payload[count] = byte.decode('utf-8')
                    self.__fullPayload = ''.join(payload)
                # load the new reply registry
                enable = self.dln_i2cslave_is_enabled(event_struct.header.handle, 0)
                if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
                    self.dln_i2cslave_disable(event_struct.header.handle, 0, 0)
                self.dln_i2cslave_load_reply(event_struct.header.handle, event_struct.port, len(self.__fullPayload),
                                             self.__fullPayload)
                if DLN_SUCCEEDED(enable[0]) and enable[1] == 1:
                    self.dln_i2cslave_Enable(event_struct.header.handle, 0)
        else:
            # unknown event
            pass
Exemplo n.º 15
0
    def open_device(self, deviceId):
        """
        Open the Diolan io adapter interface
        :return: handle to the device
        """
        self._import_module_in_wrapper(DLN_MODULE_GENERIC)
        if deviceId is not None:
            res = self._dlnGen.dln_open_device_by_id(deviceId)
            if DLN_SUCCEEDED(res[0]):
                self.__handle = res[1]

        else:
            TestEquipmentException(TestEquipmentException.INVALID_PARAMETER, "Diolan Connection fail")

        return self.__handle
Exemplo n.º 16
0
 def py_dlnCallback(self, handle, context_p):
     """
     Callback for the Diolan Events
     :param handle:
     :param context_p:
     :return:
     """
     res = self.__dln_get_message(HDLN_ALL_DEVICES)
     if DLN_SUCCEEDED(res[0]):
         return_buf = res[1]
         header = DLN_MSG_HEADER.from_buffer_copy(return_buf)
         # DLN_DEVICE_ADDED_EV event doesn't contain device handle - device is not opened yet.
         # To show device ID and SN in the events list, we open the device and change the handle
         # in the DLN_DEVICE_ADDED_EV with the new one.
         # This way the DLN_DEVICE_ADDED_EV can be processed as any other event.
         if self._dlnI2cSlave is not None:
             self._dlnI2cSlave.trt_event_notification(header, return_buf)
         if self._dlnSpiSlave is not None:
             self._dlnSpiSlave.trt_event_notification(header, return_buf)