Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modbus Error: [Input/Output] The operation did not complete (read) (_ssl.c:2578) #2463

Closed
alainzhiyanov opened this issue Nov 22, 2024 · 6 comments · Fixed by #2466
Closed

Comments

@alainzhiyanov
Copy link

Versions

  • Python: 3:10.12
  • OS: Ubuntu 22.04
  • Pymodbus: 3.7.4

Pymodbus Specific

  • Server: async tls
  • Client: sync tls

Description

Tried to set up a server and client usint two ec2 instances and have the client write a value to register 0. I get error Modbus Error: [Input/Output] The operation did not complete (read) (_ssl.c:2578). Seems to be a similar issue to this but I am not getting this requested slave does not exist: 0.

Code and Logs

# SERVER
import logging
import asyncio

from pymodbus.server import StartAsyncTlsServer
from pymodbus.device import ModbusDeviceIdentification
from pymodbus.datastore import ModbusSequentialDataBlock, ModbusSlaveContext, ModbusServerContext
import pymodbus

pymodbus.pymodbus_apply_logging_config("DEBUG")


async def run_server():
    store = ModbusSlaveContext(
        di=ModbusSequentialDataBlock(0, [0] * 10),  # Discrete Inputs
        co=ModbusSequentialDataBlock(0, [0] * 10),  # Coils
        ir=ModbusSequentialDataBlock(0, [0] * 10),  # Input Registers
        hr=ModbusSequentialDataBlock(0, [0] * 10),  # Holding Registers
    )
    context = ModbusServerContext(slaves=store, )

    identity = ModbusDeviceIdentification()
    identity.VendorName = "Pymodbus"
    identity.ProductCode = "PM"
    identity.VendorUrl = "http://github.com/bashwork/pymodbus/"
    identity.ProductName = "Pymodbus Server"
    identity.ModelName = "Pymodbus Server"
    identity.MajorMinorRevision = "1.0"


    server = await StartAsyncTlsServer(
        context,
        identity=identity,
        certfile="/certfile.pem",
        keyfile="/key",
        address=("0.0.0.0", 502)
    )


if __name__ == "__main__":
    asyncio.run(run_server(), debug=True)
##client
#!/usr/bin/env python3
import time
import pymodbus
import pymodbus.client as modbusClient
import logging

import ssl


pymodbus.pymodbus_apply_logging_config("DEBUG")
# Hardcoded server IP and port
SERVER_IP = SERVER_IP
SERVER_PORT = 502
sslctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
sslctx.load_cert_chain(certfile="/certfile.pem", keyfile="/key")
sslctx.load_verify_locations(cafile="/certfile.pem")
sslctx.verify_mode = ssl.CERT_OPTIONAL
sslctx.check_hostname = False
# Initialize and connect the client
client = modbusClient.ModbusTlsClient(SERVER_IP, port=SERVER_PORT, timeout=3, sslctx=sslctx, retries = 5)
connection = client.connect()

# Write value 12345 to register 0
register_address = 0
value_to_write = 12345
result = client.write_register(register_address, value_to_write)

time.sleep(1)
read_result = client.read_holding_registers(register_address, count=1)
print(read_result)

# Close the client connection
client.close()

Logs:
Screenshot 2024-11-21 at 8 38 02 PM

@janiversen
Copy link
Collaborator

It seems the lower layers closest to the the connection, are you sure your certificates are ok ?

Our test cases includes a case very similar to yours, running a tls server against client_async_calls (all from examples), and that works,

I will try running the 2 examples against each other manually and see if I can reproduce your problem.

@janiversen
Copy link
Collaborator

We have made some changes around tls, please try with dev.

@janiversen
Copy link
Collaborator

Confirmed this is solved on dev.

@alainzhiyanov
Copy link
Author

Thank you for your help. I'm still having an issue. I tried with dev and still getting the same error.

Here's some info about my version (same for both client and server machine):
Screenshot 2024-11-23 at 7 11 48 PM

Here's my log when I run some the example for async tls server and sync tls client:
Screenshot 2024-11-23 at 7 37 17 PM

@janiversen
Copy link
Collaborator

I will try to simulate your situation, the sync client have undergone a lot of changes on dev.

@janiversen janiversen reopened this Nov 24, 2024
@janiversen
Copy link
Collaborator

Reproduced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants