i already worked with snap7 a bit and managed to read bool values from a DB with follwing function:
def ReadBool(db_number, start_offset, bit_offset):
reading = plc.db_read(db_number, start_offset, 1)
a = snap7.util.get_bool(reading, 0, bit_offset)
return a
Now i want to read values in other formats like UInt, String and Real. I tried the following function i found online:
def ReadMemory(start_address, length):
reading = plc.read_area(snap7.types.Areas.MK, 0, start_address, length)
value = struct.unpack('>f', reading)
return value
This function needs at least 4 bits to read, i guess because of the .read_area. With plc.db_read() instead of plc.read_area() it always said "no CPU connection", although i can read out bool values with function ReadBool in same script. I saved my error wrong but i will update error tomorrow.
Is this (ReadMemory) a good function to read out data? Or can i do it more easily? I just need to read one info at a time and i just need to use the info in cv.putText() then.