Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def ReadByHandle(self, symbolHandle, adsDatatype):
length = AdsDatatype.GetSize(adsDatatype)
data = self.Read(0xF005, symbolHandle, length).Data
return AdsDatatype.Unpack(data, adsDatatype)
def Unpack(value, adsDatatype):
packFmt = AdsDatatype.GetPackFormat(adsDatatype)
if(packFmt != None):
return struct.unpack(packFmt, value)[0]
else:
return value
def WriteByHandle(self, symbolHandle, adsDatatype, value):
valueRaw = AdsDatatype.Pack(value, adsDatatype)
self.Write(0xF005, symbolHandle, valueRaw)
def ReadByHandle(self, symbolHandle, adsDatatype):
length = AdsDatatype.GetSize(adsDatatype)
data = self.Read(0xF005, symbolHandle, length).Data
return AdsDatatype.Unpack(data, adsDatatype)
def ReadFrom(self, byteBuffer):
if (self.AdsDatatype == AdsDatatype.Bool):
result = AdsDatatype.UnpackFrom(AdsDatatype.UInt8, byteBuffer, self.IndexOffset)
result = ((result & (1 << self.BitOffset)) == True)
else:
result = AdsDatatype.UnpackFrom(self.AdsDatatype, byteBuffer, self.IndexOffset)
self.Value = result
return result
def WriteTo(self, byteBuffer):
# byte shift needed, if bool!
if (self.AdsDatatype == AdsDatatype.Bool):
currentByte = AdsDatatype.UnpackFrom(AdsDatatype.UInt8, byteBuffer, self.IndexOffset)
if (self.Value):
newByte = currentByte | (1 << self.BitOffset)
else:
newByte = currentByte & ~(1 << self.BitOffset) & 0xF
AdsDatatype.PackInto(AdsDatatype.UInt8, byteBuffer, self.IndexOffset, newByte)
else:
AdsDatatype.PackInto(self.AdsDatatype, byteBuffer, self.IndexOffset, self.Value)