From: Tormod Volden <debian.tor...@gmail.com>

Makes legacy byteWrite() and interruptWrite() more compatible
with pyusb 0.4.x

Signed-off-by: Tormod Volden <debian.tor...@gmail.com>
---

On Thu, Mar 29, 2012 at 2:29 PM, Tormod Volden wrote:
> On Thu, Mar 29, 2012 at 1:47 PM, Wander Lairson Costa wrote:
>>> Thanks. I could not find it in the bug tracker, but I found a post
>>> from Sarah Messer seeing the same problem here:
>>> http://sourceforge.net/mailarchive/message.php?msg_id=27131804
>>>
>>
>> There it is.
>>
>>> Maybe we should just try return array.array('c', data) before or after
>>> trying array.array('u', data)?
>>>
>>
>> This maybe a workaround for this specific case, but I mimic the
>> behavior of the C version, things get more complicated. Anyway, if you
>> provide a patch, I will accept, it is better than nothing.
>
> When you say C version, is that pyusb 0.4.x? It is exactly
> compatibility with 0.4.x I am interested in.
>
> I can make a patch doing the above array.array('c', data) for now.
>
> Tormod

 usb/_interop.py |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/usb/_interop.py b/usb/_interop.py
index 6069d5e..5abdcdb 100644
--- a/usb/_interop.py
+++ b/usb/_interop.py
@@ -129,7 +129,10 @@ def as_array(data=None):
     try:
         return array.array('B', data)
     except TypeError:
-        # When you pass a unicode string, you got a TypeError
-        # if first parameter is not 'u'
-        return array.array('u', data)
+        # When you pass a unicode string or a character sequence,
+        # you get a TypeError if first parameter does not match
+        try:
+            return array.array('c', data)
+        except TypeError:
+            return array.array('u', data)
 
-- 
1.7.0.4


------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

Reply via email to