from opcua import Client, ua import time import tkinter import socket # Enter IP address for the OPC UA connection print('Enter IP address:') ipAddress = input() url = "opc.tcp://" + str(ipAddress) + ":4840" # url = "opc.tcp://192.168.136.13:4840" # Establish a connetion to the OPC UA server with IP address, user and password client = Client(url) client.set_user("Maintenance") client.set_password("main") client.connect() print("client conneted") # Array for the Binary coded Port. Every bit is one Port 00000000 arrPort = [1, 2, 4, 8, 16, 32, 64, 128] try: while True: # Enter The number of the Port (between 1 and 8) print('Enter Port (1 to 8):') inpPort = int(input()) - 1 # Enter the number of the Pin (Pin2 or Pin4) print('Enter Pin (2 or 4):') intPin = int(input()) choosenPort = arrPort[inpPort] # Call function OPC UA to get the force ID method_forceID = client.get_node("ns=7; i=200") parent_forceID = client.get_node("ns=7;i=8") output_forceID = parent_forceID.call_method(method_forceID) force_ID = output_forceID[0] time.sleep(1) # Call function OPC UA to write the forceID, the forceMask and the forceData if intPin == 2: method_output = client.get_node("ns=7; i=203") if intPin == 4: method_output = client.get_node("ns=7; i=206") parent_output = client.get_node("ns=7;i=8") inp1 = ua.Variant(force_ID, ua.VariantType.UInt32) inp2 = ua.Variant(255, ua.VariantType.Byte) inp3 = ua.Variant(choosenPort, ua.VariantType.Byte) out = parent_output.call_method(method_output, inp1, inp2, inp3) client.disconnect() time.sleep(15)