Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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
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
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
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)
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)
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
: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))
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)