[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


[pyusb-users] Asynchronous transfers

2014-07-29 Thread Slavko Kocjancic
Hello...

How to make Asynchronous transfers with pyusb?
I look for some example but no luck...

I stuck on the beggining.. Ie I need to allocate some buffer but fail...
I try like this:

import usb
transfer=lib.libusb_alloc_transfer(0)
lib.libusb_free_transfer(transfer)

How to do that?!?

Thanks, Slavko.


--
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-29 Thread Slavko Kocjancic
On 29. 07. 2014 18:20, Wander Lairson Costa wrote:
 2014-07-29 11:28 GMT-03:00 Slavko Kocjancic esla...@gmail.com:
 Hello...

 How to make Asynchronous transfers with pyusb?
 I look for some example but no luck...

 I stuck on the beggining.. Ie I need to allocate some buffer but fail...
 I try like this:

 import usb
 transfer=lib.libusb_alloc_transfer(0)
 lib.libusb_free_transfer(transfer)

 How to do that?!?

 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?


--
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] Select device by name linux / win difference

2014-07-17 Thread Slavko Kocjancic
On 17. 07. 2014 01:01, Wander Lairson Costa wrote:
 2014-07-16 15:05 GMT-03:00 Slavko Kocjancic esla...@gmail.com:
 I download from here
 http://sourceforge.net/projects/pyusb/files/PyUSB%201.0/1.0.0-alpha-3/

 Could you please download from this link [1] and check if it works?

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

Hello...
With that library I got text output on linux too!
Seems that I have multiple install in both systems. I do cleanup of anny 
pyusb and install previous driver. Now work in both system.

Thanks for guide me.

Slavko.

--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


[pyusb-users] Select device by name linux / win difference

2014-07-16 Thread Slavko Kocjancic
Hello...

Attached is simple example. The problem is that it's works in linux but 
not in windows. And I wan't to be portable. Can someone tell me what I 
do wrong?
seems that class 'usb.core.Device' is handeled different in win (it 
return long string?!)




#there is current only one device with correct vid/pid attached
import usb
def openUsb(vid,pid,name=''):
 try:
 devices = usb.core.find(idVendor=vid, idProduct=pid, find_all=True)
 for dev in devices:
 print type (dev)
 print dev
 if (usb.util.get_string(dev,256,2)==name):
 dev.set_configuration()
 return dev
 except Exception as e:
 print e


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


'''
OUTPUT on LINUX#
class 'usb.core.Device'
usb.core.Device object at 0x7ff2647f7290
Device found  usb.core.Device object at 0x7ff2647f7290



OUTPUT on WINDOWS#
class 'usb.core.Device'
DEVICE ID 16d0:06ad on Bus 000 Address 001 =
  bLength:   0x12 (18 bytes)
  bDescriptorType:0x1 Device
  bcdUSB :  0x110 USB 1.1
  bDeviceClass   :0x0 Specified at interface
  bDeviceSubClass:0x0
  bDeviceProtocol:0x0
  bMaxPacketSize0:0x8 (8 bytes)
  idVendor   : 0x16d0
  idProduct  : 0x06ad
  bcdDevice  :0x1 Device 0.01
  iManufacturer  :0x1 CAA
  iProduct   :0x2 Q_ANALISER
  iSerialNumber  :0x0
  bNumConfigurations :0x1
   CONFIGURATION 1: 400 mA ==
bLength  :0x9 (9 bytes)
bDescriptorType  :0x2 Configuration
wTotalLength :   0x1b (27 bytes)
bNumInterfaces   :0x1
bConfigurationValue  :0x1
iConfiguration   :0x0
bmAttributes :   0xc0 Self Powered
bMaxPower:   0xc8 (400 mA)
 INTERFACE 0: Human Interface Device 
  bLength:0x9 (9 bytes)
  bDescriptorType:0x4 Interface
  bInterfaceNumber   :0x0
  bAlternateSetting  :0x0
  bNumEndpoints  :0x0
  bInterfaceClass:0x3 Human Interface Device
  bInterfaceSubClass :0x0
  bInterfaceProtocol :0x0
  iInterface :0x0
Device not found
Press any key to continue . . .



'''


--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] Select device by name linux / win difference

2014-07-16 Thread Slavko Kocjancic
On 16. 07. 2014 12:33, Wander Lairson Costa wrote:
 2014-07-16 6:05 GMT-03:00 Slavko Kocjancic esla...@gmail.com:
 Hello...

 Attached is simple example. The problem is that it's works in linux but
 not in windows. And I wan't to be portable. Can someone tell me what I
 do wrong?
 seems that class 'usb.core.Device' is handeled different in win (it
 return long string?!)




 #there is current only one device with correct vid/pid attached
 import usb
 def openUsb(vid,pid,name=''):
   try:
   devices = usb.core.find(idVendor=vid, idProduct=pid, find_all=True)
   for dev in devices:
   print type (dev)
   print dev
   if (usb.util.get_string(dev,256,2)==name):
   dev.set_configuration()
   return dev
   except Exception as e:
   print e


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


 '''
 OUTPUT on LINUX#
 class 'usb.core.Device'
 usb.core.Device object at 0x7ff2647f7290
 Device found  usb.core.Device object at 0x7ff2647f7290



 OUTPUT on WINDOWS#
 class 'usb.core.Device'
 DEVICE ID 16d0:06ad on Bus 000 Address 001 =
bLength:   0x12 (18 bytes)
bDescriptorType:0x1 Device
bcdUSB :  0x110 USB 1.1
bDeviceClass   :0x0 Specified at interface
bDeviceSubClass:0x0
bDeviceProtocol:0x0
bMaxPacketSize0:0x8 (8 bytes)
idVendor   : 0x16d0
idProduct  : 0x06ad
bcdDevice  :0x1 Device 0.01
iManufacturer  :0x1 CAA
iProduct   :0x2 Q_ANALISER
iSerialNumber  :0x0
bNumConfigurations :0x1
 CONFIGURATION 1: 400 mA ==
  bLength  :0x9 (9 bytes)
  bDescriptorType  :0x2 Configuration
  wTotalLength :   0x1b (27 bytes)
  bNumInterfaces   :0x1
  bConfigurationValue  :0x1
  iConfiguration   :0x0
  bmAttributes :   0xc0 Self Powered
  bMaxPower:   0xc8 (400 mA)
   INTERFACE 0: Human Interface Device 
bLength:0x9 (9 bytes)
bDescriptorType:0x4 Interface
bInterfaceNumber   :0x0
bAlternateSetting  :0x0
bNumEndpoints  :0x0
bInterfaceClass:0x3 Human Interface Device
bInterfaceSubClass :0x0
bInterfaceProtocol :0x0
iInterface :0x0
 Device not found
 Press any key to continue . . .


 Hi,

 It feels like you are using different git revisions for Windows and
 Linux, aren't you?

It's should be same.
But don't know how to check wich backend pyusb use at linux and win... 
In win there should be only one, but in linux I have at least 3 and need 
all... (for other things)

Slavko.

--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] Select device by name linux / win difference

2014-07-16 Thread Slavko Kocjancic
On 16. 07. 2014 12:52, Wander Lairson Costa wrote:
 2014-07-16 7:39 GMT-03:00 Slavko Kocjancic esla...@gmail.com:
 On 16. 07. 2014 12:33, Wander Lairson Costa wrote:
 2014-07-16 6:05 GMT-03:00 Slavko Kocjancic esla...@gmail.com:
 Hello...

 Attached is simple example. The problem is that it's works in linux but
 not in windows. And I wan't to be portable. Can someone tell me what I
 do wrong?
 seems that class 'usb.core.Device' is handeled different in win (it
 return long string?!)




 #there is current only one device with correct vid/pid attached
 import usb
 def openUsb(vid,pid,name=''):
try:
devices = usb.core.find(idVendor=vid, idProduct=pid, 
 find_all=True)
for dev in devices:
print type (dev)
print dev
if (usb.util.get_string(dev,256,2)==name):
dev.set_configuration()
return dev
except Exception as e:
print e


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


 '''
 OUTPUT on LINUX#
 class 'usb.core.Device'
 usb.core.Device object at 0x7ff2647f7290
 Device found  usb.core.Device object at 0x7ff2647f7290



 OUTPUT on WINDOWS#
 class 'usb.core.Device'
 DEVICE ID 16d0:06ad on Bus 000 Address 001 =
 bLength:   0x12 (18 bytes)
 bDescriptorType:0x1 Device
 bcdUSB :  0x110 USB 1.1
 bDeviceClass   :0x0 Specified at interface
 bDeviceSubClass:0x0
 bDeviceProtocol:0x0
 bMaxPacketSize0:0x8 (8 bytes)
 idVendor   : 0x16d0
 idProduct  : 0x06ad
 bcdDevice  :0x1 Device 0.01
 iManufacturer  :0x1 CAA
 iProduct   :0x2 Q_ANALISER
 iSerialNumber  :0x0
 bNumConfigurations :0x1
  CONFIGURATION 1: 400 mA ==
   bLength  :0x9 (9 bytes)
   bDescriptorType  :0x2 Configuration
   wTotalLength :   0x1b (27 bytes)
   bNumInterfaces   :0x1
   bConfigurationValue  :0x1
   iConfiguration   :0x0
   bmAttributes :   0xc0 Self Powered
   bMaxPower:   0xc8 (400 mA)
INTERFACE 0: Human Interface Device 
 bLength:0x9 (9 bytes)
 bDescriptorType:0x4 Interface
 bInterfaceNumber   :0x0
 bAlternateSetting  :0x0
 bNumEndpoints  :0x0
 bInterfaceClass:0x3 Human Interface Device
 bInterfaceSubClass :0x0
 bInterfaceProtocol :0x0
 iInterface :0x0
 Device not found
 Press any key to continue . . .


 Hi,

 It feels like you are using different git revisions for Windows and
 Linux, aren't you?

 It's should be same.
 But don't know how to check wich backend pyusb use at linux and win...
 In win there should be only one, but in linux I have at least 3 and need
 all... (for other things)

 I said that because you have different results when you do print dev
 on Linux and Windows. You can do a git pull origin master on both
 repositories to make sure you are using git HEAD.

That different result confuse me too.
And I do install same pyusb-1.0.0.b1 in both systems.
The only difference can be the libusb driver itself. for win probably 
libusb-win and for linux probably libusb1.0 but don't know wich one the 
pyusb pick.


--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] Select device by name linux / win difference

2014-07-16 Thread Slavko Kocjancic
...but I newer installed GIT version on Win system. So where it came?
--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] Select device by name linux / win difference

2014-07-16 Thread Slavko Kocjancic
I download from here
http://sourceforge.net/projects/pyusb/files/PyUSB%201.0/1.0.0-alpha-3/


2014-07-16 16:08 GMT+01:00 Wander Lairson Costa wander.lair...@gmail.com:

 2014-07-16 11:47 GMT-03:00 Slavko Kocjancic esla...@gmail.com:
  ...but I newer installed GIT version on Win system. So where it came?
 

 I guess you downloaded the zip from walac.github.io/pyusb, which is
 just a packaged git HEAD.

 This website is temporary because SF finished trac support.

 Best Regards,
 Wander Lairson Costa


 --
 Want fast and easy access to all the code in your enterprise? Index and
 search up to 200,000 lines of code with a free copy of Black Duck
 Code Sight - the same software that powers the world's largest code
 search on Ohloh, the Black Duck Open Hub! Try it now.
 http://p.sf.net/sfu/bds
 ___
 pyusb-users mailing list
 pyusb-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/pyusb-users

--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


Re: [pyusb-users] ctrl_transfer failed...

2014-05-21 Thread Slavko Kocjancic
On 05/21/2014 05:27 PM, Wander Lairson Costa wrote:
 2014-05-21 3:00 GMT-03:00 Slavko Kocjancic esla...@gmail.com:
 On 05/21/2014 03:36 AM, Wander Lairson Costa wrote:
 2014-05-20 13:26 GMT-03:00 Slavko Kocjancic esla...@gmail.com:
 Hello...

 I'm new to python (and pyusb).
 I try to port some VUSB device to work with python, but get at trouble
 in beggining. I can't send bytes...
 here is my example (stripped from manual...)

 import usb.core
 import usb.util

 from array import *
 dev = usb.core.find(idVendor=0x16c0, idProduct=0x05df)
 if dev is None:
raise ValueError('Device not found')
 dev.set_configuration()

 msg = 'test'
 print dev.ctrl_transfer(32+128, 9, 0, 0, msg)

 I guess the first argument should be just 32.
 Well I want write. And bit 7 of first argument tells if this is write or
 read.
 and msg (at least by manual) behave as buffer for tx, and integer for
 size in receive mode.

 Yes, with this bit set, the request is an IN transfer, and the `msg`
 parameter is (wrongly) interpreted as the length of the transfer.

I realized that when I wan't to read from device. I'm interpreted this 
bit just opposite. But have other problem with win driver and take a lot 
of time to discover what are wrong. At least it works now.


--
Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free.
http://p.sf.net/sfu/SauceLabs
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users


[pyusb-users] ctrl_transfer failed...

2014-05-20 Thread Slavko Kocjancic
Hello...

I'm new to python (and pyusb).
I try to port some VUSB device to work with python, but get at trouble 
in beggining. I can't send bytes...
here is my example (stripped from manual...)

import usb.core
import usb.util

from array import *
dev = usb.core.find(idVendor=0x16c0, idProduct=0x05df)
if dev is None:
 raise ValueError('Device not found')
dev.set_configuration()

msg = 'test'
print dev.ctrl_transfer(32+128, 9, 0, 0, msg)

and there is error report

Traceback (most recent call last):
   File pyusbtest.py, line 13, in module
 print dev.ctrl_transfer(32+128, 9, 0, 0, msg)
   File /usr/local/lib/python2.7/dist-packages/usb/core.py, line 711, 
in ctrl_transfer
 self.__get_timeout(timeout)
   File /usr/local/lib/python2.7/dist-packages/usb/backend/libusb1.py, 
line 823, in ctrl_transfer
 buff = _interop.as_array((0,) * data_or_wLength)
TypeError: can't multiply sequence by non-int of type 'str'

how to proceed? (python2.7 on ubuntu)
slavko.



--
Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free.
http://p.sf.net/sfu/SauceLabs
___
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users