gijzelaerr / python-snap7

A Python wrapper for the snap7 PLC communication library
http://python-snap7.readthedocs.org/
MIT License
643 stars 246 forks source link

set_lreal from utili #426

Closed gborre closed 1 year ago

gborre commented 1 year ago

Hello! I was wondering if I was misusing the set_lreal function or there's something not working. This is the current implementation. ` def setlreal(bytearray: bytearray, byte_index: int, lreal: float) -> bytearray:

lreal = float(lreal)
_bytes = struct.unpack('8B', struct.pack('>d', lreal))
bytearray_[byte_index] = _bytes[0]
return

Using the function as it is I got wrong results writing on PLC. I did a small change to make it work: def setlreal(bytearray: bytearray, byte_index: int, lreal: float) -> bytearray:

lreal = float(lreal)
_bytes = struct.unpack('8B', struct.pack('>d', lreal))
**bytearray_[byte_index: byte_index + 8] = _bytes[:]**
return

` Is this correct? Am I doing something wrong?

Thanks!