How to use the pyads.Connection function in pyads

To help you get started, we’ve selected a few pyads examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stlehmann / pyads / tests / test_connection_class.py View on Github external
def test_methods_with_closed_port(self):
        # type: () -> None
        """Test pyads.Connection methods with no open port."""
        with self.plc:
            adr = self.plc.get_local_address()
            self.assertIsNotNone(adr)

        plc = pyads.Connection("127.0.0.1.1.1", 851)
        self.assertIsNone(plc.get_local_address())
        self.assertIsNone(plc.read_state())
        self.assertIsNone(plc.read_device_info())
        self.assertIsNone(plc.read_write(1, 2, pyads.PLCTYPE_INT, 1, pyads.PLCTYPE_INT))
        self.assertIsNone(plc.read(1, 2, pyads.PLCTYPE_INT))
        self.assertIsNone(plc.read_by_name("hello", pyads.PLCTYPE_INT))
        self.assertIsNone(plc.get_handle("hello"))
        self.assertIsNone(
            plc.read_structure_by_name(
                "hello", (("", pyads.PLCTYPE_BOOL, 1), ("", pyads.PLCTYPE_BOOL, 1))
            )
        )
        self.assertIsNone(
            plc.add_device_notification(
                "test", pyads.NotificationAttrib(4), lambda x: x
            )
github stlehmann / pyads / tests / test_connection_class.py View on Github external
def test_initialization(self):
        # type: () -> None
        """Test init process."""
        with self.assertRaises(TypeError):
            pyads.Connection()

        with self.assertRaises(AttributeError):
            pyads.Connection(None, None)
github stlehmann / pyads / tests / test_integration.py View on Github external
def test_decorated_device_notification(self):

        plc = pyads.Connection(TEST_SERVER_AMS_NET_ID, TEST_SERVER_AMS_PORT)

        @plc.notification(pyads.PLCTYPE_INT)
        def callback(handle, name, timestamp, value):
            print (handle, name, timestamp, value)

        with plc:
            plc.add_device_notification("a", pyads.NotificationAttrib(20), callback)
            plc.write_by_name("a", 1, pyads.PLCTYPE_INT)
github stlehmann / pyads / tests / test_connection_class.py View on Github external
def setUp(self):
        # type: () -> None
        """Establish connection to the testserver."""
        self.test_server.request_history = []
        self.plc = pyads.Connection(
            TEST_SERVER_AMS_NET_ID, TEST_SERVER_AMS_PORT, TEST_SERVER_IP_ADDRESS
        )
github stlehmann / pyads / tests / test_connection_class.py View on Github external
def test_no_ip_address(self):
        # type: () -> None
        """Autogenerate IP-address from AMS net id.

        Autogenerate IP-address from AMS net id if no ip address is given
        on initialization.

        """
        plc = pyads.Connection(TEST_SERVER_AMS_NET_ID, TEST_SERVER_AMS_PORT)
        self.assertEqual(TEST_SERVER_IP_ADDRESS, plc.ip_address)
github stlehmann / pyads / tests / test_connection_class.py View on Github external
def test_initialization(self):
        # type: () -> None
        """Test init process."""
        with self.assertRaises(TypeError):
            pyads.Connection()

        with self.assertRaises(AttributeError):
            pyads.Connection(None, None)
github home-assistant / home-assistant / homeassistant / components / ads / __init__.py View on Github external
def setup(hass, config):
    """Set up the ADS component."""
    import pyads

    conf = config[DOMAIN]

    net_id = conf.get(CONF_DEVICE)
    ip_address = conf.get(CONF_IP_ADDRESS)
    port = conf.get(CONF_PORT)

    client = pyads.Connection(net_id, port, ip_address)

    AdsHub.ADS_TYPEMAP = {
        ADSTYPE_BOOL: pyads.PLCTYPE_BOOL,
        ADSTYPE_BYTE: pyads.PLCTYPE_BYTE,
        ADSTYPE_DINT: pyads.PLCTYPE_DINT,
        ADSTYPE_INT: pyads.PLCTYPE_INT,
        ADSTYPE_UDINT: pyads.PLCTYPE_UDINT,
        ADSTYPE_UINT: pyads.PLCTYPE_UINT,
    }

    AdsHub.ADSError = pyads.ADSError
    AdsHub.PLCTYPE_BOOL = pyads.PLCTYPE_BOOL
    AdsHub.PLCTYPE_BYTE = pyads.PLCTYPE_BYTE
    AdsHub.PLCTYPE_DINT = pyads.PLCTYPE_DINT
    AdsHub.PLCTYPE_INT = pyads.PLCTYPE_INT
    AdsHub.PLCTYPE_UDINT = pyads.PLCTYPE_UDINT