How to use the pyads.constants.PLCTYPE_UDINT 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_write_uint(self):
        value = 100

        with self.plc:
            self.plc.write(
                index_group=constants.INDEXGROUP_DATA,
                index_offset=1,
                value=value,
                plc_datatype=constants.PLCTYPE_UDINT,
            )

        # Retrieve list of received requests from server
        requests = self.test_server.request_history

        # Assert that the server received a request
        self.assertEqual(len(requests), 1)

        # Assert that the server received the correct command
        self.assert_command_id(requests[0], constants.ADSCOMMAND_WRITE)

        # Check the value received by the server
        received_value = struct.unpack("
github stlehmann / pyads / tests / test_integration.py View on Github external
def test_read_write_array(self):
        write_value = tuple(range(5))

        ads.read_write(
            self.endpoint,
            index_group=constants.INDEXGROUP_DATA,
            index_offset=1,
            plc_read_datatype=constants.PLCTYPE_UDINT,
            value=write_value,
            plc_write_datatype=constants.PLCTYPE_UDINT * 5,
        )

        # Retrieve list of received requests from server
        requests = self.test_server.request_history

        # Check the value received by the server
        received_value = struct.unpack("
github stlehmann / pyads / tests / test_connection_class.py View on Github external
def test_read_write(self):
        write_value = 100

        with self.plc:
            read_value = self.plc.read_write(
                index_group=constants.INDEXGROUP_DATA,
                index_offset=1,
                plc_read_datatype=constants.PLCTYPE_UDINT,
                value=write_value,
                plc_write_datatype=constants.PLCTYPE_UDINT,
            )

        # Retrieve list of received requests from server
        requests = self.test_server.request_history

        # Assert that the server received a request
        self.assertEqual(len(requests), 1)

        # Assert that the server received the correct command
        self.assert_command_id(requests[0], constants.ADSCOMMAND_READWRITE)

        # Check the value received by the server
        received_value = struct.unpack("
github stlehmann / pyads / pyads / pyads_ex.py View on Github external
:param pyads.structs.AmsAddr adr: local or remote AmsAddr
    :param int notification_handle: Notification Handle
    :param int user_handle: User Handle

    """
    adsSyncDelDeviceNotificationReqFct = _adsDLL.AdsSyncDelDeviceNotificationReqEx

    pAmsAddr = ctypes.pointer(adr.amsAddrStruct())
    nHNotification = ctypes.c_ulong(notification_handle)
    err_code = adsSyncDelDeviceNotificationReqFct(port, pAmsAddr, nHNotification)
    del callback_store[(adr, notification_handle)]
    if err_code:
        raise ADSError(err_code)

    if user_handle is not None:
        adsSyncWriteReqEx(port, adr, ADSIGRP_SYM_RELEASEHND, 0, user_handle, PLCTYPE_UDINT)
github stlehmann / pyads / pyads / pyads.py View on Github external
:param int plcDataType: type of the data given to the PLC, according to
        PLCTYPE constants
    :rtype: PLCTYPE
    :return: value: **value**

    """
    # Get the handle of the PLC-variable
    hnl = adsSyncReadWriteReq(
        adr, ADSIGRP_SYM_HNDBYNAME, 0x0, PLCTYPE_UDINT, dataName, PLCTYPE_STRING
    )

    # Read the value of a PLC-variable, via handle
    value = adsSyncReadReq(adr, ADSIGRP_SYM_VALBYHND, hnl, plcDataType)

    # Release the handle of the PLC-variable
    adsSyncWriteReq(adr, ADSIGRP_SYM_RELEASEHND, 0, hnl, PLCTYPE_UDINT)

    return value

github stlehmann / pyads / pyads / pyads.py View on Github external
:param AmsAddr adr: local or remote AmsAddr
    :param int notification_handle: notification handle
    :param int user_handle: user handle

    """
    adsSyncDelDeviceNotificationReqFct = _adsDLL.AdsSyncDelDeviceNotificationReq

    pAmsAddr = pointer(adr.amsAddrStruct())
    nHNotification = c_ulong(notification_handle)
    err_code = adsSyncDelDeviceNotificationReqFct(pAmsAddr, nHNotification)
    callback_store[notification_handle] = None
    if err_code:
        raise ADSError(err_code)

    adsSyncWriteReq(adr, ADSIGRP_SYM_RELEASEHND, 0, user_handle, PLCTYPE_UDINT)

github stlehmann / pyads / pyads / pyads_ex.py View on Github external
"""
    global callback_store

    if NOTEFUNC is None:
        raise TypeError("Callback function type can't be None")

    adsSyncAddDeviceNotificationReqFct = _adsDLL.AdsSyncAddDeviceNotificationReqEx

    pAmsAddr = ctypes.pointer(adr.amsAddrStruct())
    if isinstance(data, str):
        hnl = adsSyncReadWriteReqEx2(
            port,
            adr,
            ADSIGRP_SYM_HNDBYNAME,
            0x0,
            PLCTYPE_UDINT,
            data,
            PLCTYPE_STRING,
        )

        nIndexGroup = ctypes.c_ulong(ADSIGRP_SYM_VALBYHND)
        nIndexOffset = ctypes.c_ulong(hnl)
    elif isinstance(data, tuple):
        nIndexGroup = data[0]
        nIndexOffset = data[1]
        hnl = None
    else:
        raise TypeError("Parameter data has the wrong type %s. Allowed types are: str, Tuple[int, int]." % (type(data)))

    attrib = pNoteAttrib.notificationAttribStruct()
    pNotification = ctypes.c_ulong()
github stlehmann / pyads / pyads / pyads.py View on Github external
def adsSyncWriteByName(adr, dataName, value, plcDataType):
    # type: (AmsAddr, str, Any, Type) -> None
    """Send data synchronous to an ADS-device from data name.

    :param pyads.structs.AmsAddr adr: local or remote AmsAddr
    :param string dataName: PLC storage address
    :param value: value to write to the storage address of the PLC
    :param int plcDataType: type of the data given to the PLC,
        according to PLCTYPE constants

    """
    # Get the handle of the PLC-variable
    hnl = adsSyncReadWriteReq(
        adr, ADSIGRP_SYM_HNDBYNAME, 0x0, PLCTYPE_UDINT, dataName, PLCTYPE_STRING
    )

    # Write the value of a PLC-variable, via handle
    adsSyncWriteReq(adr, ADSIGRP_SYM_VALBYHND, hnl, value, plcDataType)

    # Release the handle of the PLC-variable
    adsSyncWriteReq(adr, ADSIGRP_SYM_RELEASEHND, 0, hnl, PLCTYPE_UDINT)
github stlehmann / pyads / pyads / pyads_ex.py View on Github external
def adsGetHandle(port, address, data_name):
    # type: (int, AmsAddr, str) -> int
    """Get the handle of the PLC-variable.

    :param int port: local AMS port as returned by adsPortOpenEx()
    :param pyads.structs.AmsAddr address: local or remote AmsAddr
    :param string data_name: data name
    :rtype: int
    :return: handle: PLC-variable handle
    """
    handle = adsSyncReadWriteReqEx2(
        port,
        address,
        ADSIGRP_SYM_HNDBYNAME,
        0x0,
        PLCTYPE_UDINT,
        data_name,
        PLCTYPE_STRING,
    )

    return handle