예제 #1
0
def run_sync_client():
    client_cert = 'client.crt'
    client_key = 'privk.key'
    did_wallet_path = "walletDid.json"
    client = ModbusTlsClient(host=os.getenv('IP_SERVER'),
                             port=8020,
                             sslctx=None,
                             certfile=client_cert,
                             keyfile=client_key,
                             did_wallet_path=did_wallet_path)
    socket, B = client.connect()
    print("B")
    print(B)
    client.close()
예제 #2
0
    def testBasicSyncTlsClient(self):
        ''' Test the basic methods for the tls sync client'''

        # receive/send
        client = ModbusTlsClient()
        client.socket = mockSocket()
        self.assertEqual(0, client._send(None))
        self.assertEqual(1, client._send(b'\x00'))
        self.assertEqual(b'\x00', client._recv(1))

        # connect/disconnect
        self.assertTrue(client.connect())
        client.close()

        # already closed socket
        client.socket = False
        client.close()

        self.assertEqual("ModbusTlsClient(localhost:802)", str(client))
예제 #3
0
This is a simple example of writing a modbus TCP over TLS client that uses
Python builtin module ssl - TLS/SSL wrapper for socket objects for the TLS
feature.
"""
# -------------------------------------------------------------------------- #
# import necessary libraries
# -------------------------------------------------------------------------- #
import ssl
from pymodbus.client.sync import ModbusTlsClient

# -------------------------------------------------------------------------- #
# the TLS detail security can be set in SSLContext which is the context here
# -------------------------------------------------------------------------- #
context = ssl.create_default_context()
context.options |= ssl.OP_NO_SSLv2
context.options |= ssl.OP_NO_SSLv3
context.options |= ssl.OP_NO_TLSv1
context.options |= ssl.OP_NO_TLSv1_1

# -------------------------------------------------------------------------- #
# pass SSLContext which is the context here to ModbusTcpClient()
# -------------------------------------------------------------------------- #
client = ModbusTlsClient('test.host.com', 8020, sslctx=context)
client.connect()

result = client.read_coils(1, 8)
print(result.bits)

client.close()