[pyusb-users] libusb1 Callback thread

2014-07-30 Thread Slavko Kocjancic
Hello...
I try to do some async transfer. The program bellow actualy 'near' work.
It setup 10 transfers and should print the received bytes in callback.
The problem is that callback is not done at receive complete!
In example below I expect callback while sleep comand is executed but 
instead got all callbacks when I close device...
I know that USBPoller/USBPollerThread has something to do with my 
problem but don't know how to use it.

Here is my test program:
#***
import usb1,time

def openUsb(vid,pid,name):
 context = usb1.USBContext()
 for dev in context.getDeviceList(skip_on_error=True):
 if (dev.getVendorID()==vid)  (dev.getProductID()==pid):
 if dev.getProduct()==name:
 return dev.open()

USBdev=openUsb(0x16d0,0x06ad,'Q_ANALISER')
if not USBdev:
 print Device not found
 exit(0)

def callback(transfer):
 print Just received %4.0f Bytes % transfer.getActualLength()

transfer=[]
for i in range(10):
 transfer.append(USBdev.getTransfer())
 transfer[-1].setControl(160, 3, 0, 0, 4096, callback, None, 1000)
 transfer[-1].submit()


time.sleep(1)
print sleep 1 done.
time.sleep(1)
print sleep 2 done.

USBdev.close()
print Device closed.
#***


And this is output. (received length is as expected 1'st frame is 1 as 
this indicated overrun in my device and other's are actual packets)

sleep 1 done.
sleep 2 done.
Just received1 Bytes
Just received 2870 Bytes
Just received 2870 Bytes
Just received 2870 Bytes
Just received 2870 Bytes
Just received 2870 Bytes
Just received 2870 Bytes
Just received 2870 Bytes
Just received 2870 Bytes
Just received 2870 Bytes
Device closed.


--
(program exited with code: 0)
Press return to continue


--
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071iu=/4140/ostg.clktrk
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] libusb1 Callback thread

2014-07-30 Thread Slavko Kocjancic
On 30. 07. 2014 11:52, Xiaofan Chen wrote:
 On Wed, Jul 30, 2014 at 2:45 PM, Slavko Kocjancic esla...@gmail.com wrote:
 Hello...
 I try to do some async transfer. The program bellow actualy 'near' work.
 It setup 10 transfers and should print the received bytes in callback.
 The problem is that callback is not done at receive complete!
 In example below I expect callback while sleep comand is executed but
 instead got all callbacks when I close device...
 I know that USBPoller/USBPollerThread has something to do with my
 problem but don't know how to use it.

 Here is my test program:
 #***
 import usb1,time

 def openUsb(vid,pid,name):
   context = usb1.USBContext()
   for dev in context.getDeviceList(skip_on_error=True):
   if (dev.getVendorID()==vid)  (dev.getProductID()==pid):
   if dev.getProduct()==name:
   return dev.open()

 It seems to me that you are not using pyusb, but rather python-libusb1.
 https://github.com/vpelletier/python-libusb1/blob/master/testUSB1.py

 I am not so sure if people in this list are working with
 python-libusb1 or not.


Yes it is python-libusb1 as libusb doesn't handle async transfer at all.


--
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071iu=/4140/ostg.clktrk
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] Asynchronous transfers

2014-07-30 Thread Slavko Kocjancic
On 29. 07. 2014 18:51, Wander Lairson Costa wrote:
 Unfortunately, PyUSB doesn't have async support yet :(


 Ouch...

 So what can be done?
 Direct acess to lubusb? Is it possible to make callback in python?!?
 Or another library in c is way to go?!?

 any hint?

 For PyUSB there is nothing to be done on short term, but you can try
 [1]. It is a thin Python wrapper around libusb 1.0.

 [1] https://github.com/vpelletier/python-libusb1

 Best Regards,
 Wander Lairson Costa


Ok I managed somehow to work in linux but now I stuck as I can't manage 
ro run in windows.
I know that I use python-libusb1

https://github.com/vpelletier/python-libusb1

and this should work with libusb1.0 (but not libusb-win32). But I don't 
know how to test if this is libusb or libusb-win as both dll have same 
name? And seems that I use wrong dll (btw it's near impossible to find 
precompiled libusb-1.0.dll to be not libusb-win32 type??)

Does someone have links to working solution? (ie python wrapper to 
libusb and correct libusb, to be able to work in linux and win with 
async support?)

Thanks.

--
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071iu=/4140/ostg.clktrk
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] Trouble specifying a backend on embedded.

2014-07-30 Thread Wander Lairson Costa
2014-07-30 15:01 GMT-03:00 Samuel Thurston samuel-thurs...@uiowa.edu:
 Hello all,

 I'm trying to use pyusb on an embedded yocto linux running on an intel
 Galileo board.  I'm running into problems trying to load the custom
 backend as specified in the tutorial page.  Since there is no compile
 environment I'm missing ldconfig.  When I go to get a handle to the
 device the normal way I get this error:

   dev = usb.core.find(idVendor = vid, idProduct = pid)
 Traceback (most recent call last):
File stdin, line 1, in module
File /usr/lib/python2.7/site-packages/usb/core.py, line 864, in find
  raise ValueError('No backend available')
 ValueError: No backend available

 I located the library to link at /lib/libusb-1.0.so.0

 so I tried to use the method described to specify a find_library function.


  
   backend = usb.backend.libusb1.get_backend(find_library=lambda x:
 /lib/libusb-1.0.so.0)
 Traceback (most recent call last):
File stdin, line 1, in module
 TypeError: get_backend() takes no arguments (1 given)


 I don't really understand the mechanism at play here, so I don't have
 any ideas for next steps.  If anyone can provide some guidance I'd be
 very grateful.

 for what it's worth, here's the DATA section from help(usb)

 DATA
  __all__ = ['legacy', 'core', 'backend', 'util']
  __author__ = 'Wander Lairson Costa'
  __version__ = '1.0.0b1'



Hmm, unfortunately this feature is not available on any tagged version
yet. Could you please test with [1] ?

[1] https://github.com/walac/pyusb/tarball/master

-- 
Best Regards,
Wander Lairson Costa

--
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071iu=/4140/ostg.clktrk
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users