.... I forgot to attach the code. here it is. Thanks.
   
  Jeff

Graham Bloice <[EMAIL PROTECTED]> wrote:
  Jeff Peery wrote:
> thanks for the beta!
> 
> I think my main problem is that I don't really understand this code; I
> didn't write it. Could you recommend a book/website that describes
> what these functions like 'group.OPCItems.AddItem' do? For example,
> how do I know what a 'group' is or what the addItem() parameters are,
> or how to interpret that error code that you interpreted, and I'm not
> really sure if this code will work for other OPC servers other than
> the automation direct server.
> 
> Also, where might I go learn about how to setup the event handler for
> a data change event?
> 
> Thanks again, I appreciate your help!
> Jeff
> 
The canonical definition of the OPC Automation interface API is the OPC
DA Auto 2.02 Specification. DA stands for Data Acquisition. The
originators of this document are the OPC Foundation, at
http://www.opcfoundation.org, and the specification is *so* open you
have to become a member to download it (at a cost of USD 1500). Grrr.

However, if your Google fu is up to it you might find a copy lying
around elsewhere, as I have run across it on several OPC Vendors sites. 
I think I've also found it with several OPC Servers. I would recommend
that you get the Matrikon OPC Simulation server for testing, this
installs the Matrikon OPC Explorer which is a useful client app to work
out what's happening when your client doesn't work. This might give you
the docs. The document goes under various names such as opcda20_auto.doc.

Note that the docs are VB (VB6) based, but not too difficult to convert
to python.

You will also want to read up on creating event handlers in PyWin

-- 
Regards,

Graham Bloice



       
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  Try it now.
import win32com.client
import win32api
import pythoncom
import sys
import time
import msvcrt

def OnResult(self, event):
    print event.msg
    
class GroupEvents:
    def __init__(self):
        print 'init Group Events'
         
    def 
OnDataChange(self,TransactionID,NumItems,ClientHandles,ItemValues,Qualities,TimeStamps):
        print TransactionID, 'transaction id'
        print NumItems, 'num items'
        print ClientHandles, 'client handles'
        print ItemValues, 'item values'
        print Qualities, 'Qualities'
        print TimeStamps, 'Time Stamps'
        print 'Data Change at', time.ctime()


opcServer = win32com.client.Dispatch('OPC.Automation.1')
opcServer.Connect('AutomationDirect.KEPDirectServer')
groups = opcServer.OPCGroups
group = groups.Add()
item = group.OPCItems.AddItem('Test Avance.Test Avance.IsReady', 1)
# need to keep groupEvents around so the GroupEvents instance exists
groupEvents = win32com.client.DispatchWithEvents(group, GroupEvents)
group.IsActive = 1   
group.IsSubscribed = 1
print item.Read(0x1)
item.Write(False)
print item.Read(0x1)
item.Write(True)
print item.Read(0x1)

end = time.clock() + 2 
while time.clock() < end and not msvcrt.kbhit(): 
    pythoncom.PumpWaitingMessages() 

opcServer.OPCGroups.RemoveAll()
opcServer.Disconnect()
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to