0% found this document useful (0 votes)
11 views

Modbus Py Code

The document contains code that reads input registers, decodes hexadecimal values to strings, unpacks data, and displays output in a loop waiting 2 seconds between iterations.

Uploaded by

Shamim Ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Modbus Py Code

The document contains code that reads input registers, decodes hexadecimal values to strings, unpacks data, and displays output in a loop waiting 2 seconds between iterations.

Uploaded by

Shamim Ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import struct

from time import sleep


from binascii import hexlify
from codecs import decode

while(app.running_script):
resp = app.fc04_read_input_registers(21, 0, 2)
a= decode(hexlify(app.msg_in), 'utf_8', 'ignore')
b= a[6:14]
e=struct.unpack('!f', bytes.fromhex(b))[0]

# Display received data.


app.set_output('Received Data: {}\nMessage Out: {}\nMessage In: {}'.format(
e,
decode(hexlify(app.msg_out), 'utf_8', 'ignore'),
decode(hexlify(app.msg_in), 'utf_8', 'ignore')
))
# Wait 2 seconds.
sleep(2)

You might also like