2011/3/23 Brendan Simon (eTRIX) <brendan.si...@etrix.com.au>:
> The pyusb tutorial has an example of using the control transfer functions.
>
> http://pyusb.sourceforge.net/docs/1.0/tutorial.html
>
>>>> msg = 'test'
>>>> assert dev.ctrl_transfer(0x40, CTRL_LOOPBACK_WRITE, 0, 0, msg) == len(msg)
>>>> ret = dev.ctrl_transfer(0x40, CTRL_LOOPBACK_READ, 0, 0, len(msg))
>>>> sret = ''.join([chr(x) for x in ret])
>>>> assert sret == msg
>
>
> I was wondering if it would be better (or more efficient) to use some of
> the array functions.
> e.g.
>
>>>> sret = ''.join(ret.tolist())
>
> or
>
>>>> sret = ret.tostring()
>
The best way to know it is to measure, I guess.

>
> Any thoughts on this ??
>
> Also, just out of curiosity, what is the advantage of returning/using an
> array object rather than a string ??
>
If you think from PyUSB point of view, things returned by the device
are raw data,
not string's. There is an abstraction stuff there. Moreover, because
of portability
across different Python versions, I use array objects internally, thus
makes sense
to return these objects.

> Why is a string object used for WRITE instead of a string ??
> The WRITE and READ transfers seem a little inconsistent in the object
> written and returned.
>
Write accepts any kind of sequence that an array object accepts in its
constructor.
On the return of a read, I do need to return something, I cannot
return such a generic sequence,
as in write's.




-- 
Best Regards,
Wander Lairson Costa
LCoN - Laboratório de Computação Natural - Natural Computing Laboratory
(http://www.mackenzie.com.br/lcon.html)
Programa de Pós-Graduação em Engenharia Elétrica (PPGEE)
Faculdade de Computação e Informática (FCI)
Universidade Presbiteriana Mackenzie - SP - Brazil

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

Reply via email to