Re: [python-win32] Client site not available
Ok. I have requested and now received a newer version of the OCX control (from the vendors) that DOES work with VBScript when executed from wscript/cscript. The PortOpen property now responds correctly without getting the aforementioned error - and this is a definite improvement. However, 2 things still elude me. 1) I wish to be able to use the events available in the object as well, and after much reading (and purchasing of your book, Mark - which helped ALOT in several other areas - thank you!) I was left feeling a bit lost in the 'events' arena. Here is the code I am attempting (short and simple) atm, which responds with AttributeError: 'win32com.client.COMEventClass instance at 0x12436112' object has no attribute '_typelib_guid_': ## Code snippet [start] from win32com.client import DispatchWithEvents class SwiperEvents(object): def OnCardDataChanged(self, Source=pythoncom.Missing, CursorType=pythoncom.Missing, LockType=pythoncom.Missing, Options=pythoncom.Missing, adStatus=pythoncom.Missing, pCommand=pythoncom.Missing, pRecordset=pythoncom.Missing, pConnection=pythoncom.Missing): print Handler called! swiper = DispatchWithEvents('ctlUSBHID.USBHID', SwiperEvents) ## Code snippet [end] I have a bad feeling this is an obvious error on my part - but am still too new at Python I guess. 2) (and this is probably related to the first thing) - when I monitor the CardData property for changes 'manually' (with a loop) it never changes - no matter how many card swipes I attempt. COULD this be a result of the PortOpen property not actually making the necessary connection in the OCX and just 'acting' like it was set?: __ Garth Johnson PS Oh - and I DID fully remove the old OCX AND the Makepy output before rebuilding it - and tested for the correct version of the control from wscript with vbscript test code they sent me (which looks essentially the same as the web page one). ___ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Client site not available
1) I wish to be able to use the events available in the object as well, and after much reading (and purchasing of your book, Mark - which helped ALOT in several other areas - thank you!) I was left feeling a bit lost in the 'events' arena. Here is the code I am attempting (short and simple) atm, which responds with AttributeError: 'win32com.client.COMEventClass instance at 0x12436112' object has no attribute '_typelib_guid_': ## Code snippet [start] from win32com.client import DispatchWithEvents class SwiperEvents(object): Try leaving the events class as an old style class (ie, don't derive from object) 2) (and this is probably related to the first thing) - when I monitor the CardData property for changes 'manually' (with a loop) it never changes - no matter how many card swipes I attempt. COULD this be a result of the PortOpen property not actually making the necessary connection in the OCX and just 'acting' like it was set?: I'm afraid I've no idea. Can you show the VBScript code that does work, and the version re-written in Python that doesn't? You should use python.exe to test in the first instance, and cscript.exe (not wscript.exe) to test the VBScript. Mark. ___ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Client site not available
Mark Hammond wrote: Try leaving the events class as an old style class (ie, don't derive from object) Hmm.. I did that, and got pretty much the same output - does this stack trace help at all? The code listed at the bottom is my complete code for my test. I don't need anything else to do this do I? Stack trace [start] AttributeError: 'win32com.client.COMEventClass instance at 0x12535288' object has no attribute '_typelib_guid_' Traceback (innermost last): File c:\Documents and Settings\Me\My Documents\Work\eXpressPayAdvantage\XPayAdv\directest2.py, line 1, in ? from win32com.client import DispatchWithEvents File c:\Documents and Settings\Me\My Documents\Work\eXpressPayAdvantage\XPayAdv\directest2.py, line 16, in ? swiper = DispatchWithEvents('ctlUSBHID.USBHID', SwiperEvents) File C:\Python24\Lib\site-packages\win32com\client\__init__.py, line 266, in DispatchWithEvents events_class.__init__(instance, instance) File C:\Python24\Lib\site-packages\win32com\gen_py\158336E7-3FF3-456E-912C-5985E9BBED24x0x1x1.py, line 104, in __init__ cookie=cp.Advise(win32com.server.util.wrap(self, usePolicy=EventHandlerPolicy)) File C:\Python24\Lib\site-packages\win32com\server\util.py, line 23, in wrap ob = usePolicy(ob) File C:\Python24\Lib\site-packages\win32com\server\policy.py, line 189, in __init__ self._wrap_(object) File C:\Python24\Lib\site-packages\win32com\server\policy.py, line 463, in _wrap_ tlb_guid = getattr(ob, '_typelib_guid_', None) File C:\Python24\Lib\site-packages\win32com\client\__init__.py, line 454, in __getattr__ raise AttributeError, '%s' object has no attribute '%s' % (repr(self), attr) Stack trace [end] Code (current) [start] from win32com.client import DispatchWithEvents import pythoncom class SwiperEvents: def OnCardDataChanged(self, Source=pythoncom.Missing, CursorType=pythoncom.Missing, LockType=pythoncom.Missing, Options=pythoncom.Missing, adStatus=pythoncom.Missing, pCommand=pythoncom.Missing, pRecordset=pythoncom.Missing, pConnection=pythoncom.Missing): print Handler called! swiper = DispatchWithEvents('ctlUSBHID.USBHID', SwiperEvents) print swiper.PortOpen swiper.PortOpen = True swiper.ClearBuffer() print swiper.PortOpen Code (current) [end] ___ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Client site not available
Mark Hammond wrote: Try leaving the events class as an old style class (ie, don't derive from object) Hmm.. I did that, and got pretty much the same output - does this stack trace help at all? The code listed at the bottom is my complete code for my test. I don't need anything else to do this do I? That all looks fine to me - but I'm a little confused: File C:\Python24\Lib\site-packages\win32com\server\policy.py, line 463, in _wrap_ tlb_guid = getattr(ob, '_typelib_guid_', None) File C:\Python24\Lib\site-packages\win32com\client\__init__.py, line 454, in __getattr__ raise AttributeError, '%s' object has no attribute '%s' % (repr(self), attr) It looks like this code: tlb_guid = getattr(ob, '_typelib_guid_', None) Is somehow managing to cause an AttributeError. The 3rd param (None) should prevent that from happening. If you examine that code, you can see that it fully expects the object to not have a _typelib_guid_ attribute - but it does that by relying on that fact an AttributeError will *not* be raised, but None returned instead. I'm not sure what could cause this - accidently assigning to AttributeError could possibly cause it, but I can't see any such thing in the code snippet. Is that code snippet your *entire* test program? Mark ___ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Client site not available
Mark Hammond wrote: I'm not sure what could cause this - accidently assigning to AttributeError could possibly cause it, but I can't see any such thing in the code snippet. Is that code snippet your *entire* test program? Yes, the snippet of code was the complete code listing... however I made a few changes to it since my last mail and found that when running it (as you suggested) with the command line (and NOT within the IDE that I am using - WingIDE) it ran with no errors printed. After some adjustments to the IDE - it now runs and ignores that error inside the IDE. Still no data from the swipes though. That is the #2 thing on my original list. I am going to get a full working example in vbscript to respond with - but in the mean time, here is my current code - see anything wrong in it? ..or that might prevent it from spewing forth some data ...assuming that the swiper is getting data and that my event convention is correct (which I believe it is now - thank you) # current code - complete [start] # Necessary modules from win32com.client import DispatchWithEvents # Event class for the USB HID Swiper instance below class SwiperEvents: def OnCardDataChanged(self): print CardData: %s % self.CardData # create a USB HID Swiper instance with event capabilities swiper = DispatchWithEvents('ctlUSBHID.USBHID', SwiperEvents) # Set and test the port to the device print swiper.PortOpen swiper.PortOpen = True print swiper.PortOpen swiper.ClearBuffer() # Wait for data or user intervention while 1: pass print Done. # current code - complete [end] ___ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Client site not available
The same process works fin in VBScript on the example page from MagTek.. Does it work from VBScript executed via cscript/wscript? If it only works from VBScript inside a webpage hosting the control, the problem will be that you need an OCX container to host the control. Pythonwin is capable (see the pywin\demos\ocx dir), as is wxPython (but I've never use that). Otherwise, can you post the VBScript code which does work (just up to the successful PortOpen property set)? Cheers, Mark ___ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Client site not available
Mark Hammond wrote: The same process works fin in _vbscript_ on the example page from MagTek.. Does it work from _vbscript_ executed via cscript/wscript? If it only works from _vbscript_ inside a webpage hosting the control, the problem will be that you need an OCX "container" to host the control. Pythonwin is capable (see the pywin\demos\ocx dir), as is wxPython (but I've never use that). Otherwise, can you post the _vbscript_ code which does work (just up to the successful PortOpen property set)? Cheers, Mark Thank you for the prompt answer Mark. You betcha, I can post the _vbscript_! ..and yes, it IS an OCX.. hmm, so I will need to treat this different then, than a regular COM? Here is the code (found at http://www.magtek.com/support/software/demo_programs/usb_swipe_insert/swipe_read_parse.asp): - code - start SCRIPT LANGUAGE="_vbscript_"!-- Sub window_onLoad() USBHID.PortOpen = True If Not(USBHID.PortOpen) then MsgBox "Unable to Open USB Reader" End if end sub Sub window_onUnload() USBHID.PortOpen = False end sub Sub USBHID_CardDataChanged() Document.MyForm.FIRST.Value = USBHID.GetFName() [-- snipped for brevity --] Document.MyForm.CARDDATA.Value = USBHID.CardData USBHID.ClearBuffer() end sub -- /SCRIPT OBJECT ID="USBHID" CLASSID="" class="moz-txt-link-rfc2396E" href="CLSID:22571E97-956A-4CDD-AF8D-AE9C26597683">"CLSID:22571E97-956A-4CDD-AF8D-AE9C26597683" CODEBASE="" /OBJECT -- code -end I looked in the OCX demos and saw that it does indeed seem to be handling it completely differently there... instead of using Dispatch, it seems I should use the gencache.EnsureModule() method etc. Problem is, which CLSID should I use for the call (there seems to be several different ones in the MakePY code that was generated). ___ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32