How to use the pyads.pyads.ADSError 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 / pyads / pyads.py View on Github external
ctypes.POINTER(ctypes.c_ulong),
    ]
    adsSyncAddDeviceNotificationReqFct.restype = c_ulong
    c_callback = NOTEFUNC(callback)
    err_code = adsSyncAddDeviceNotificationReqFct(
        pAmsAddr,
        nIndexGroup,
        nIndexOffset,
        pointer(attrib),
        c_callback,
        nHUser,
        pointer(pNotification),
    )

    if err_code:
        raise ADSError(err_code)
    callback_store[pNotification.value] = c_callback
    return (pNotification.value, hnl)
github stlehmann / pyads / pyads / pyads.py View on Github external
pAmsAddr = pointer(adr.amsAddrStruct())
    nIndexGroup = c_ulong(indexGroup)
    nIndexOffset = c_ulong(indexOffset)

    if plcDataType == PLCTYPE_STRING:
        data = (STRING_BUFFER * PLCTYPE_STRING)()
    else:
        data = plcDataType()

    pData = pointer(data)
    nLength = c_ulong(sizeof(data))
    errCode = adsSyncReadReqFct(pAmsAddr, nIndexGroup, nIndexOffset, nLength, pData)

    if errCode:
        raise ADSError(errCode)

    if plcDataType == PLCTYPE_STRING:
        return data.value.decode("utf-8")

    if type(plcDataType).__name__ == "PyCArrayType":
        return [i for i in data]

    if hasattr(data, "value"):
        return data.value

    return data
github stlehmann / pyads / pyads / pyads.py View on Github external
nData = plcWriteDataType(value)
        data = pointer(nData)
        data_length = sizeof(nData)

    err_code = adsSyncReadWriteReqFct(
        pAmsAddr,
        nIndexGroup,
        nIndexOffset,
        nReadLength,
        pointer(readData),
        data_length,
        data,
    )

    if err_code:
        raise ADSError(err_code)

    if plcReadDataType == PLCTYPE_STRING:
        return readData.value.decode("utf-8")

    if type(plcReadDataType).__name__ == "PyCArrayType":
        return [i for i in readData]

    if hasattr(readData, "value"):
        return readData.value

    return readData
github stlehmann / pyads / pyads / pyads.py View on Github external
def adsGetLocalAddress():
    """
    :summary: Return the local AMS-address and the port number.
    :rtype: pyads.structs.AmsAddr
    :return: AMS-address

    """
    adsGetLocalAddressFct = _adsDLL.AdsGetLocalAddress
    stAmsAddr = SAmsAddr()
    errCode = adsGetLocalAddressFct(pointer(stAmsAddr))

    if errCode:
        raise ADSError(errCode)

    adsLocalAddr = AmsAddr()
    adsLocalAddr._ams_addr = stAmsAddr
    return adsLocalAddr
github stlehmann / pyads / pyads / pyads.py View on Github external
nAdsState = c_ulong(adsState)
    nDeviceState = c_ulong(deviceState)

    if plcDataType == PLCTYPE_STRING:
        nData = c_char_p(data.encode())
        pData = nData
        nLength = len(pData.value) + 1
    else:
        nData = plcDataType(data)
        pData = pointer(nData)
        nLength = sizeof(nData)

    errCode = adsSyncWriteControlReqFct(pAddr, nAdsState, nDeviceState,
                                        nLength, pData)
    if errCode:
        raise ADSError(errCode)
github stlehmann / pyads / pyads / pyads.py View on Github external
pAddr = pointer(adr.amsAddrStruct())
    nAdsState = c_ulong(adsState)
    nDeviceState = c_ulong(deviceState)

    if plcDataType == PLCTYPE_STRING:
        nData = c_char_p(data.encode())
        pData = nData  # type: Union[c_char_p, pointer[Any]]
        nLength = len(pData.value) + 1  # type: ignore
    else:
        nData = plcDataType(data)
        pData = pointer(nData)
        nLength = sizeof(nData)

    errCode = adsSyncWriteControlReqFct(pAddr, nAdsState, nDeviceState, nLength, pData)
    if errCode:
        raise ADSError(errCode)
github stlehmann / pyads / pyads / pyads.py View on Github external
pAmsAddr = pointer(adr.amsAddrStruct())
    nIndexGroup = c_ulong(indexGroup)
    nIndexOffset = c_ulong(indexOffset)

    if plcDataType == PLCTYPE_STRING:
        data = (STRING_BUFFER * PLCTYPE_STRING)()
    else:
        data = plcDataType()

    pData = pointer(data)
    nLength = c_ulong(sizeof(data))
    errCode = adsSyncReadReqFct(
        pAmsAddr, nIndexGroup, nIndexOffset, nLength, pData)

    if errCode:
        raise ADSError(errCode)

    if plcDataType == PLCTYPE_STRING:
        return data.value.decode('utf-8')

    if type(plcDataType).__name__ == 'PyCArrayType':
        return [i for i in data]

    if hasattr(data, 'value'):
        return data.value

    return data
github stlehmann / pyads / pyads / pyads.py View on Github external
:param pyads.structs.AmsAddr adr: local or remote AmsAddr
    :rtype: string, AdsVersion
    :return: device name, version

    """
    adsSyncReadDeviceInfoReqFct = _adsDLL.AdsSyncReadDeviceInfoReq

    pAmsAddr = pointer(adr.amsAddrStruct())
    devNameStringBuffer = create_string_buffer(20)
    pDevName = pointer(devNameStringBuffer)
    stVersion = SAdsVersion()
    pVersion = pointer(stVersion)

    errCode = adsSyncReadDeviceInfoReqFct(pAmsAddr, pDevName, pVersion)
    if errCode:
        raise ADSError(errCode)
    return (devNameStringBuffer.value.decode(), AdsVersion(stVersion))

github stlehmann / pyads / pyads / pyads.py View on Github external
if plcDataType == PLCTYPE_STRING:
        nData = c_char_p(value.encode())
        pData = nData
        nLength = len(pData.value) + 1
    else:
        if type(plcDataType).__name__ == 'PyCArrayType':
            nData = plcDataType(*value)
        else:
            nData = plcDataType(value)
        pData = pointer(nData)
        nLength = sizeof(nData)

    errCode = adsSyncWriteReqFct(pAmsAddr, nIndexGroup, nIndexOffset,
                                 nLength, pData)
    if errCode:
        raise ADSError(errCode)