gijzelaerr / python-snap7

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

DB_write Issue in Snap7 #290

Closed INDRANI125 closed 3 years ago

INDRANI125 commented 3 years ago

While writing String from my Python application to TIA Portal, I am not getting the exact string in my TIA portal as well as in Python program as attached. Where as it is working fine in case of read operation. Can anyone help me out?It is getting random values. tia_snap

Python Code- import snap7 IP='192.168.0.1' RACK=0 SLOT=1 DB_NUMBER=100 START_ADDRESS=1 SIZE=259

plc=snap7.client.Client() plc.connect(IP,RACK,SLOT) plc_info=plc.get_cpu_info() print(f'Module Type: {plc_info.ModuleTypeName}') print(f'State: {plc.get_cpu_state()}') db=plc.db_read(DB_NUMBER,START_ADDRESS,SIZE) plc.db_write(DB_NUMBER, START_ADDRESS, b'Python to TIA') product_name=db[0:255].decode('UTF-8').strip('\x00') print(f'Product Name: {product_name}') product_value=int.from_bytes(db[255:257], byteorder='big') print(f'Product Value: {product_value}') product_status=bool(db[257]) print(f'Product Status: {product_status}') Python Output- Module Type: b'CPU 1510SP-1 PN' State: S7CpuStatusRun Product Name: TIA Portal to Python // problem in writing this output Product Value: 14 Product Status: True