472,783 Members | 1,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,783 software developers and data experts.

making a opc client in Python and use opc server Events

Hi all
I have a sample code to implement opc client in Python. i use a
file .py making by makepy with pythonwin for Com Interface.
i can get all server in machine, connect to server opc, disconnect,
add group, add item, read, write item in server opc.

import win32com.client # librairie pour utiliser l'interface COM/DCOM
from win32com.client import gencache
gencache.EnsureModule('{DFB83232-A952-11D2-A46B-00C04F796375}', 0, 1,
0)

for svr in opcserver.GetOPCServers():
print svr

#connect to server OPC Demo Simulation from Matrikon
opcserver.Connect('Matrikon.OPC.Simulation.1')

# Instance object Groups
groups=opcserver.OPCGroups
#add group
group=groups.Add('Group1')

#instance onject Items
items=group.OPCItems
# add item in server opc
tem=items.AddItem('File1.item1',1)

#read item value
item.Read(win32com.client.constants.OPCDevice)

# write a new value
item.Write(100)

#read item value
item.Read(win32com.client.constants.OPCDevice)
#if no pb you have 100 :)

#Disconnect
#opcserver.Disconnect()

BUT, and BUT, i want to use a event from opc server for uodating item
value with this below class. And i don't konw how make it!!!!!!!!
help me plz

opcserver=win32com.client.Dispatch('OPC.Automation .1')
and now i want to use events from opc server. in a class:
class DIOPCGroupEvent:
class DIOPCGroupsEvent:
class DIOPCServerEvent:

Jun 4 '07 #1
1 3847
On 4 juin, 11:32, getelectro...@gmail.com wrote:
Hi all
I have a sample code to implement opc client in Python. i use a
file .py making by makepy with pythonwin for Com Interface.
i can get all server in machine, connect to server opc, disconnect,
add group, add item, read, write item in server opc.

import win32com.client # librairie pour utiliser l'interface COM/DCOM
from win32com.client import gencache
gencache.EnsureModule('{DFB83232-A952-11D2-A46B-00C04F796375}', 0, 1,
0)

for svr in opcserver.GetOPCServers():
print svr

#connect to server OPC Demo Simulation from Matrikon
opcserver.Connect('Matrikon.OPC.Simulation.1')

# Instance object Groups
groups=opcserver.OPCGroups
#add group
group=groups.Add('Group1')

#instance onject Items
items=group.OPCItems
# add item in server opc
tem=items.AddItem('File1.item1',1)

#read item value
item.Read(win32com.client.constants.OPCDevice)

# write a new value
item.Write(100)

#read item value
item.Read(win32com.client.constants.OPCDevice)
#if no pb you have 100 :)

#Disconnect
#opcserver.Disconnect()

BUT, and BUT, i want to use a event from opc server for uodating item
value with this below class. And i don't konw how make it!!!!!!!!
help me plz

opcserver=win32com.client.Dispatch('OPC.Automation .1')
and now i want to use events from opc server. in a class:
class DIOPCGroupEvent:
class DIOPCGroupsEvent:
class DIOPCServerEvent:
Try this:

# Event Handlers
class ServerEvent:
def __init__(self):
print 'Init ServerEvent'

def OnServerShutDown(self, Reason):
print 'OnServerShutDown', Reason

class GroupEvent:
def __init__(self):
print 'Init GroupEvent'

def OnAsyncCancelComplete(self, CancelID):
print 'OnAsyncCancelComplete', CancelID

def OnDataChange(self, TransactionID, NumItems, ClientHandles,
ItemValues, Qualities, TimeStamps):
print 'OnDataChange', zip(ClientHandles, ItemValues, Qualities)

def OnAsyncReadComplete(self, TransactionID, NumItems, ClientHandles,
ItemValues, Qualities,
TimeStamps, Errors):
print 'OnAsyncReadComplete', zip(ClientHandles, ItemValues,
Qualities)

def OnAsyncWriteComplete(self, TransactionID, NumItems,
ClientHandles, Errors):
print 'OnAsyncWriteComplete', zip(ClientHandles, Errors)

class GroupsEvent:
def __init__(self):
print 'Init GroupsEvent'

def OnGlobalDataChange(self, TransactionID, GroupHandle, NumItems,
ClientHandles, ItemValues,
Qualities, TimeStamps):
print 'OnGlobalDataChange', zip(ClientHandles, ItemValues,
Qualities)

opc = DispatchWithEvents('Matrikon.OPC.Automation.1', ServerEvent)

groups = DispatchWithEvents(opc.OPCGroups, GroupsEvent)
groups.DefaultGroupIsActive = True
groups.DefaultGroupUpdateRate = 2000

group1 = DispatchWithEvents(groups.Add('G1'), GroupEvent)
group2 = DispatchWithEvents(groups.Add('G2'), GroupEvent)
#etc ...

It works for the GroupsEvents but I don't get the GroupEvent for each
group, I may still do someting wrong..

Jun 28 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Fuzzyman | last post by:
In a nutshell - the question I'm asking is, how do I make a socket conenction go via a proxy server ? All our internet traffic has to go through a proxy-server at location 'dav-serv:8080' and I...
1
by: Erwin S. Andreasen | last post by:
I have a Python application server that manages several different data sets, permits various reports to be run on them and the data to be downloaded as tab-delimetered files, all via a web...
15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
5
by: Mong | last post by:
Hi, I have a webform with various asp controls on it such as textboxes and dropdownlists. I'm fairly new to asp.net coming from VB6 and am wondering when it's best to use client side events and...
6
by: Gary Kshepitzki | last post by:
Hello I am trying to send an event from a Python COM server to a VB (or VB.NET) COM client. I am a newbie both in VB and in python. Can anyone give me a simple (but complete) code example both of...
10
by: Ben | last post by:
Hi, I made an application in classic asp (reservation of books and video stuffs for students) and want to migrate to asp.net. The user has to chose a date, then pushung on a submit button. The...
3
by: Dan | last post by:
Does the COM server created with python have to be compiled? I have the need to integrate database access but, I can not have any proprietary software. Meaning no compiled programs built by me. So,...
2
by: Kenneth McDonald | last post by:
I'm doing some work with a Python program that works hand-in-hand with the DOM on a local client (processing DOM events, issuing DOM modification commands, etc.) I'm currently using cherrypy as the...
1
by: hocker | last post by:
I have created a client-server application using .NET remoting in C#. The client initiates a call to the server then subscribes to events from the server, using an abstract class which contains the...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.