Пример #1
0
    def test_init_invalid_type(self):
        """Test symbol lookup when type cannot be found

        There was a read/write check that verifies the plc_typ was not None,
        but this was removed.
        """

        var = PLCVariable(name="UnknownType",
                          ads_type=0,
                          symbol_type="non_existent_type")
        var.index_group = 123
        var.index_offset = 100
        var.plc_type = constants.PLCTYPE_BYTE  # Set to something real

        self.handler.add_variable(var)

        with self.plc:

            # Create symbol while providing everything:
            symbol = AdsSymbol(self.plc, name=var.name)

            self.assertEqual(var.symbol_type, symbol.symbol_type)
            self.assertIsNone(symbol.plc_type)

            # with self.assertRaises(ValueError) as cm:
            #     # Without type specified, it cannot read
            #     symbol.read()
            # self.assertIn('Cannot read or write', str(cm.exception))

            with self.assertRaises(TypeError) as cm:
                # Error is thrown inside pyads_ex
                symbol.read()
            self.assertIn("NoneType", str(cm.exception))

        self.assertAdsRequestsCount(1)  # Only a WRITE followed by a READ
Пример #2
0
    def test_init_by_name_matrix_style(self):
        """Test symbol creation when it's an array denoted as matrix

        This is how an array originating from Simulink could look like.
        """

        var = PLCVariable(
            "ArrayVar",
            ads_type=0,
            symbol_type="matrix_21_int8_T",  # Simulink array looks like this
        )
        var.plc_type = constants.PLCTYPE_ARR_SINT(21)  # Have to do this
        # manually
        var.index_group = 123
        var.index_offset = 100
        self.handler.add_variable(var)

        self.plc.open()

        symbol = AdsSymbol(
            self.plc,
            name=var.name,
            index_group=var.index_group,
            index_offset=var.index_offset,
            symbol_type=var.symbol_type,
        )  # No lookup

        # Verify looked up info
        self.assertEqual(var.plc_type, symbol.plc_type)
        self.assertEqual(var.symbol_type, symbol.symbol_type)

        self.assertAdsRequestsCount(0)  # No requests