AdvancedClimateSystems / uModbus

Python implementation of the Modbus protocol.
Mozilla Public License 2.0
211 stars 81 forks source link

TCP client example : read_coils #87

Closed danielblengino closed 4 years ago

danielblengino commented 4 years ago

Hello,

I am trying to implement tcp.read_coils function just after the client example.

import socket import struct from umodbus import conf from umodbus.client import tcp

conf.SIGNED_VALUES = True

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(('localhost', 1502))

message = tcp.write_multiple_coils(slave_id=1, starting_address=1, values=[1, 0, 1, 1, 0]) response = tcp.send_message(message, sock)

resp_pdu = tcp.read_coils(slave_id=1, starting_address=1, quantity=5)

function_code = resp_pdu[:1] byte_count = resp_pdu[1:2] coil_status = resp_pdu[2:]

but I don't get in resp_pdu what I have written. I use the example server with threading.

Possible problems :

Can you help ?

danielblengino commented 4 years ago

Understood the logic, solution is : message2 = tcp.read_coils(...) response2 = tcp.send_message(..)