Seth Sims wrote:
> Hello everyone,
>
>     I am having a problem receiving events from some com objects I am working 
> with. win32com has performed beautifully so far 
> and the code can call methods and manipulate properties with no problems. 
> However I cannot seem to figure out why I am not 
> receiving events. It is probably just a lack of knowledge on my part about 
> com but thats why I am asking.
>     The com object that this code accesses follows a specification for 
> talking to point of sale devices called OPOS. In 
> particular it is a control for a magnetic stripe reader device. I need to 
> receive the DataEvent event from the control. I am 
> using the method prototypes from the makepy utility for the event class but I 
> never see their print statements executed on my 
> output.
>    The DataEvent is being fired though the various card properties are not 
> filled in until the event is generated and those 
> show up every time. Also I have used the ActiveX test shell from vc++ 6 and 
> it receives the events. In the output I have 
> scrubbed the card number and name (its actually a fake test card but it seems 
> safer this way) but the data is there and 
> correct. Thank you for your help in advance.
>
>                          -Seth Sims
>
>
> -----------event.py-------------
>
> import win32com.client as client
> import pythoncom
>
> class OPOSEventSink:
>
>    def OnDirectIOEvent(self, EventNumber, pData, pString):
>        """method DirectIOEvent"""
>        print "direct io"
>
>    def OnDataEvent(self, Status):
>        """method DataEvent"""
>        print "data"
>
>    def OnStatusUpdateEvent(self, Data):
>        """method StatusUpdateEvent"""
>        print "status update"
>
>    def OnErrorEvent(self, ResultCode, ResultCodeExtended, ErrorLocus, 
> pErrorResponse):
>        """method ErrorEvent"""
>        print "error"
>
>
> if __name__ == '__main__':
>    msr = client.DispatchWithEvents("OPOS.MSR", OPOSEventSink)
>
>    #Ready the device
>    msr.Open("Ing6XXX")
>    msr.ClaimDevice(-1)
>
>    #setup the magnetic stripe reader
>    #tell the device to turn its self off when a swipe is read
>    msr.AutoDisable = True
>    msr.DataEventEnabled = True
>
>    #read all 4 tracks
>    msr.TracksToRead = 0xf
>
>    #hold events till I tell you to send them
>    msr.FreezeEvents = True
>
>    #turn the device on
>    msr.DeviceEnabled = True
>
>    print "please swipe a card"
>
>    #when this loop finishes there has
>    #been a successful swipe of a card
>    #and a data event is waiting to be
>    #released in the com object
>    while msr.DataCount < 1:
>        pass
>
>    #by the OPOS specification these
>    #attributes are set as blank strings
>    #until a data event is fired
>    print 'before unfreezing events should be blank'
>    print 'Account number:', msr.AccountNumber, \
>           '\nName:', msr.Surname, '\n'
>
>    #release the events
>    msr.FreezeEvents = False
>
>    print 'events thawed should still be blank'
>    print 'Account number:', msr.AccountNumber, \
>          '\nName:', msr.Surname, '\n'
>
>    pythoncom.PumpWaitingMessages()
>
>    print 'after pump waiting messages now the values should be there'
>    print 'Account number:', msr.AccountNumber, \
>          '\nName:', msr.Surname, '\n'
>
>    msr.ReleaseDevice()
>    msr.Close()
>
> ---------- Output -------------
> please swipe a card
> before unfreezing events should be blank
> Account number:
> Name:
>
> events thawed should still be blank
> Account number:
> Name:
>
> after pump waiting messages now the values should be there
> Account number: <scrubed by me>
> Name: <ditto>

It may be that a single PumpWaitingMessages doesn't allow enough
time for the events to be delivered.  Try running it in a loop with a
small sleep until the event is fired.

          Roger




_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to