Reputation: 315
I have written a code in PYTHON. I want to transfer the respective outputs to OPC DA server so that clients can access it from the explorer. Can I create an empty configured aliases where I can fill it with my values and then display it or any similar logical easy solution ? the only way I figured out was to transfer the output data to a simulated item but that is not really a solution since I only want to show my data..
Upvotes: 1
Views: 4835
Reputation: 1608
Code for manipulation values through OPC DA, similar to the answer from @john-hedengren , but with the use of QuickOPC library:
import opclabs_quickopc
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.OperationModel import *
client = EasyDAClient()
try:
IEasyDAClientExtension.WriteItemValue(client, '', 'Kepware.KEPServerEX.V5', 'Channel2.Device1.T_12_Load_AVG', Load1_avg)
IEasyDAClientExtension.WriteItemValue(client, '', 'Kepware.KEPServerEX.V5', 'Channel2.Device1.T_21_Load_AVG', Load2_avg)
except OpcException as opcException:
print('*** Failure: ' + opcException.GetBaseException().Message, sep='')
exit()
OPC UA (Unified Architecture) would require some changes, but the code would be similar in principle.
Upvotes: 0
Reputation: 14386
You can transfer values with MODBUS or OPC. You can do this with OpenOPC or PyOPC but you may want to use the newer OPC-UA standard. There is a well-developed Python package for OPC-UA. Here is example code with OpenOPC if you do need to use the older DA standard.
# #######################################
# OPC write
# #######################################
try:
# OPC connection
import OpenOPC
opc=OpenOPC.client()
b=opc.connect('Kepware.KEPServerEX.V5')
#opc.connect('Kepware.KEPServerEX.V5','localhost')
Load1_avg = opcm[0][0]
Load2_avg = opcm[0][1]
opc.write( ('Channel2.Device1.T_12_Load_AVG',Load1_avg) )
opc.write( ('Channel2.Device1.T_21_Load_AVG',Load2_avg) )
opc.close()
except:
print 'OPC communication failed'
pass
I've used this successfully with a Kepware server on several applications.
Upvotes: 0