473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 3936
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.