Skip to content

Commit e148536

Browse files
committed
Add Androidhelper USB APIs
1 parent 8098fe7 commit e148536

File tree

11 files changed

+513
-4
lines changed

11 files changed

+513
-4
lines changed

docs/_sources/en/guide_androidhelpers.txt

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,3 +1906,127 @@ WebView
19061906

19071907
:param str url: url
19081908
:param bool wait(optional): block until the user exits the WebView
1909+
1910+
USB Host Serial Facade
1911+
======================
1912+
1913+
*QPython 1.3.1+ and QPython3 1.0.3+ contains this feature*
1914+
1915+
SL4A Facade for USB Serial devices by Android USB Host API.
1916+
1917+
1918+
It control the USB-Serial like devices
1919+
from Andoroid which has USB Host Controller .
1920+
1921+
The sample
1922+
`demonstration is also available at youtube video <http://www.youtube.com/watch?v=EJ7qiGXaI74>`_
1923+
1924+
1925+
Requirements
1926+
-------------
1927+
* Android device which has USB Host controller (and enabled in that firmware).
1928+
* Android 4.0 (API14) or later.
1929+
* USB Serial devices (see [Status](#Status)).
1930+
* USB Serial devices were not handled by Android kernel.
1931+
1932+
> I heard some android phone handle USB Serial devices
1933+
> make /dev/ttyUSB0 in kernel level.
1934+
> In this case, Android does not be able to handle the device
1935+
> from OS level.
1936+
1937+
please check Android Applications be able to grab the target USB Devices,
1938+
such as `USB Device Info <https://play.google.com/store/apps/details?id=aws.apps.usbDeviceEnumerator>`_.
1939+
1940+
Status
1941+
---------------
1942+
* probably work with USB CDC, like FTDI, Arduino or else.
1943+
1944+
* 2012/09/10: work with 78K0F0730 device (new RL78) with Tragi BIOS board.
1945+
1946+
`M78K0F0730 <http://www.marutsu.co.jp/shohin_55296/>`_
1947+
1948+
* 2012/09/24: work with some pl2303 devcies.
1949+
1950+
Author
1951+
-------
1952+
This facade developped by `Kuri65536 <https://bitbucket.org/kuri65536/usbhostserialfacade>`_
1953+
you can see the commit log in it.
1954+
1955+
1956+
APIs
1957+
--------
1958+
.. py:function:: usbserialGetDeviceList()
1959+
1960+
Returns USB devices reported by USB Host API.
1961+
1962+
:return: Returns "Map of id and string information Map<String, String>
1963+
1964+
1965+
.. py:function:: usbserialDisconnect(connID)
1966+
1967+
Disconnect all USB-device
1968+
1969+
:param str connID: connection ID
1970+
1971+
.. py:function:: usbserialActiveConnections()
1972+
1973+
Returns active USB-device connections.
1974+
1975+
:return: Returns "Active USB-device connections by Map UUID vs device-name."
1976+
1977+
1978+
.. py:function:: usbserialWriteBinary(base64, connID)
1979+
1980+
Send bytes over the currently open USB Serial connection.
1981+
1982+
:param str base64:
1983+
:param str connId:
1984+
1985+
.. py:function:: usbserialReadBinary(bufferSize, connID)
1986+
1987+
Read up to bufferSize bytes and return a chunked, base64 encoded string
1988+
1989+
:param int bufferSize:
1990+
:param str connId:
1991+
1992+
.. py:function:: usbserialConnect(hash, options)
1993+
1994+
Connect to a device with USB-Host. request the connection and exit
1995+
1996+
:param str hash:
1997+
:param str options:
1998+
1999+
:return: Returns messages the request status
2000+
2001+
.. py:function:: usbserialHostEnable()
2002+
2003+
Requests that the host be enable for USB Serial connections.
2004+
2005+
:return: True if the USB Device is accesible
2006+
2007+
.. py:function:: usbserialWrite(String ascii, String connID)
2008+
2009+
Sends ASCII characters over the currently open USB Serial connection
2010+
2011+
:param str ascii:
2012+
:param str connID:
2013+
2014+
.. py:function:: usbserialReadReady(connID)
2015+
2016+
:param str connID:
2017+
2018+
:return: True if the next read is guaranteed not to block
2019+
2020+
2021+
.. py:function:: usbserialRead(connID, bufferSize)
2022+
2023+
Read up to bufferSize ASCII characters.
2024+
2025+
:param str connID:
2026+
:param int bufferSize:
2027+
2028+
.. py:function:: usbserialGetDeviceName(connID)
2029+
2030+
Queries a remote device for it's name or null if it can't be resolved
2031+
2032+
:param str connID:

docs/_sources/index.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ QPython Communities
6565
* `Join Facebook community <https://www.facebook.com/groups/qpython>`_
6666
* `Join Google group <https://groups.google.com/forum/#!forum/qpython>`_
6767
* `Join Gitter chat <https://gitter.com/qpython-android/qpython>`_
68-
* `Join G+ community <https://plus.google.com/communities/111759148772865961493>`_
68+
* `Join G+ community(For QPython testers) <https://plus.google.com/communities/111759148772865961493>`_
6969
* `QPython on Stackoverflow <http://stackoverflow.com/questions/tagged/qpython>`_
7070

7171
**And you could talk to us through social network**

docs/en/guide.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ <h1>Programming Guide<a class="headerlink" href="#programming-guide" title="Perm
149149
<li class="toctree-l2"><a class="reference internal" href="guide_androidhelpers.html#signalstrengthfacade">SignalStrengthFacade</a></li>
150150
<li class="toctree-l2"><a class="reference internal" href="guide_androidhelpers.html#webcamfacade">WebCamFacade</a></li>
151151
<li class="toctree-l2"><a class="reference internal" href="guide_androidhelpers.html#uifacade">UiFacade</a></li>
152+
<li class="toctree-l2"><a class="reference internal" href="guide_androidhelpers.html#usb-host-serial-facade">USB Host Serial Facade</a></li>
152153
</ul>
153154
</li>
154155
<li class="toctree-l1"><a class="reference internal" href="guide_extend.html">QPython Open API</a><ul>

docs/en/guide_androidhelpers.html

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@
124124
<li class="toctree-l4"><a class="reference internal" href="#webview">WebView</a></li>
125125
</ul>
126126
</li>
127+
<li class="toctree-l3"><a class="reference internal" href="#usb-host-serial-facade">USB Host Serial Facade</a><ul>
128+
<li class="toctree-l4"><a class="reference internal" href="#requirements">Requirements</a></li>
129+
<li class="toctree-l4"><a class="reference internal" href="#status">Status</a></li>
130+
<li class="toctree-l4"><a class="reference internal" href="#author">Author</a></li>
131+
<li class="toctree-l4"><a class="reference internal" href="#apis">APIs</a></li>
132+
</ul>
133+
</li>
127134
</ul>
128135
</li>
129136
<li class="toctree-l2"><a class="reference internal" href="guide_extend.html">QPython Open API</a></li>
@@ -3427,6 +3434,221 @@ <h2>WebView<a class="headerlink" href="#webview" title="Permalink to this headli
34273434
</dd></dl>
34283435
</div>
34293436
</div>
3437+
<div class="section" id="usb-host-serial-facade">
3438+
<h1>USB Host Serial Facade<a class="headerlink" href="#usb-host-serial-facade" title="Permalink to this headline"></a></h1>
3439+
<p><em>QPython 1.3.1+ and QPython3 1.0.3+ contains this feature</em></p>
3440+
<p>SL4A Facade for USB Serial devices by Android USB Host API.</p>
3441+
<p>It control the USB-Serial like devices
3442+
from Andoroid which has USB Host Controller .</p>
3443+
<p>The sample
3444+
<a class="reference external" href="http://www.youtube.com/watch?v=EJ7qiGXaI74">demonstration is also available at youtube video</a></p>
3445+
<div class="section" id="requirements">
3446+
<h2>Requirements<a class="headerlink" href="#requirements" title="Permalink to this headline"></a></h2>
3447+
<ul>
3448+
<li><p class="first">Android device which has USB Host controller (and enabled in that firmware).</p>
3449+
</li>
3450+
<li><p class="first">Android 4.0 (API14) or later.</p>
3451+
</li>
3452+
<li><p class="first">USB Serial devices (see [Status](#Status)).</p>
3453+
</li>
3454+
<li><p class="first">USB Serial devices were not handled by Android kernel.</p>
3455+
<p>&gt; I heard some android phone handle USB Serial devices
3456+
&gt; make /dev/ttyUSB0 in kernel level.
3457+
&gt; In this case, Android does not be able to handle the device
3458+
&gt; from OS level.</p>
3459+
<p>please check Android Applications be able to grab the target USB Devices,
3460+
such as <a class="reference external" href="https://play.google.com/store/apps/details?id=aws.apps.usbDeviceEnumerator">USB Device Info</a>.</p>
3461+
</li>
3462+
</ul>
3463+
</div>
3464+
<div class="section" id="status">
3465+
<h2>Status<a class="headerlink" href="#status" title="Permalink to this headline"></a></h2>
3466+
<ul>
3467+
<li><p class="first">probably work with USB CDC, like FTDI, Arduino or else.</p>
3468+
</li>
3469+
<li><p class="first">2012/09/10: work with 78K0F0730 device (new RL78) with Tragi BIOS board.</p>
3470+
<p><a class="reference external" href="http://www.marutsu.co.jp/shohin_55296/">M78K0F0730</a></p>
3471+
</li>
3472+
<li><p class="first">2012/09/24: work with some pl2303 devcies.</p>
3473+
</li>
3474+
</ul>
3475+
</div>
3476+
<div class="section" id="author">
3477+
<h2>Author<a class="headerlink" href="#author" title="Permalink to this headline"></a></h2>
3478+
<p>This facade developped by <a class="reference external" href="https://bitbucket.org/kuri65536/usbhostserialfacade">Kuri65536</a>
3479+
you can see the commit log in it.</p>
3480+
</div>
3481+
<div class="section" id="apis">
3482+
<h2>APIs<a class="headerlink" href="#apis" title="Permalink to this headline"></a></h2>
3483+
<dl class="function">
3484+
<dt id="usbserialGetDeviceList">
3485+
<code class="descname">usbserialGetDeviceList</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#usbserialGetDeviceList" title="Permalink to this definition"></a></dt>
3486+
<dd><p>Returns USB devices reported by USB Host API.</p>
3487+
<table class="docutils field-list" frame="void" rules="none">
3488+
<col class="field-name" />
3489+
<col class="field-body" />
3490+
<tbody valign="top">
3491+
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Returns &#8220;Map of id and string information Map&lt;String, String&gt;</td>
3492+
</tr>
3493+
</tbody>
3494+
</table>
3495+
</dd></dl>
3496+
<dl class="function">
3497+
<dt id="usbserialDisconnect">
3498+
<code class="descname">usbserialDisconnect</code><span class="sig-paren">(</span><em>connID</em><span class="sig-paren">)</span><a class="headerlink" href="#usbserialDisconnect" title="Permalink to this definition"></a></dt>
3499+
<dd><p>Disconnect all USB-device</p>
3500+
<table class="docutils field-list" frame="void" rules="none">
3501+
<col class="field-name" />
3502+
<col class="field-body" />
3503+
<tbody valign="top">
3504+
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>connID</strong> (<em>str</em>) &#8211; connection ID</td>
3505+
</tr>
3506+
</tbody>
3507+
</table>
3508+
</dd></dl>
3509+
<dl class="function">
3510+
<dt id="usbserialActiveConnections">
3511+
<code class="descname">usbserialActiveConnections</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#usbserialActiveConnections" title="Permalink to this definition"></a></dt>
3512+
<dd><p>Returns active USB-device connections.</p>
3513+
<table class="docutils field-list" frame="void" rules="none">
3514+
<col class="field-name" />
3515+
<col class="field-body" />
3516+
<tbody valign="top">
3517+
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Returns &#8220;Active USB-device connections by Map UUID vs device-name.&#8221;</td>
3518+
</tr>
3519+
</tbody>
3520+
</table>
3521+
</dd></dl>
3522+
<dl class="function">
3523+
<dt id="usbserialWriteBinary">
3524+
<code class="descname">usbserialWriteBinary</code><span class="sig-paren">(</span><em>base64</em>, <em>connID</em><span class="sig-paren">)</span><a class="headerlink" href="#usbserialWriteBinary" title="Permalink to this definition"></a></dt>
3525+
<dd><p>Send bytes over the currently open USB Serial connection.</p>
3526+
<table class="docutils field-list" frame="void" rules="none">
3527+
<col class="field-name" />
3528+
<col class="field-body" />
3529+
<tbody valign="top">
3530+
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
3531+
<li><strong>base64</strong> (<em>str</em>) &#8211; </li>
3532+
<li><strong>connId</strong> (<em>str</em>) &#8211; </li>
3533+
</ul>
3534+
</td>
3535+
</tr>
3536+
</tbody>
3537+
</table>
3538+
</dd></dl>
3539+
<dl class="function">
3540+
<dt id="usbserialReadBinary">
3541+
<code class="descname">usbserialReadBinary</code><span class="sig-paren">(</span><em>bufferSize</em>, <em>connID</em><span class="sig-paren">)</span><a class="headerlink" href="#usbserialReadBinary" title="Permalink to this definition"></a></dt>
3542+
<dd><p>Read up to bufferSize bytes and return a chunked, base64 encoded string</p>
3543+
<table class="docutils field-list" frame="void" rules="none">
3544+
<col class="field-name" />
3545+
<col class="field-body" />
3546+
<tbody valign="top">
3547+
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
3548+
<li><strong>bufferSize</strong> (<em>int</em>) &#8211; </li>
3549+
<li><strong>connId</strong> (<em>str</em>) &#8211; </li>
3550+
</ul>
3551+
</td>
3552+
</tr>
3553+
</tbody>
3554+
</table>
3555+
</dd></dl>
3556+
<dl class="function">
3557+
<dt id="usbserialConnect">
3558+
<code class="descname">usbserialConnect</code><span class="sig-paren">(</span><em>hash</em>, <em>options</em><span class="sig-paren">)</span><a class="headerlink" href="#usbserialConnect" title="Permalink to this definition"></a></dt>
3559+
<dd><p>Connect to a device with USB-Host. request the connection and exit</p>
3560+
<table class="docutils field-list" frame="void" rules="none">
3561+
<col class="field-name" />
3562+
<col class="field-body" />
3563+
<tbody valign="top">
3564+
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
3565+
<li><strong>hash</strong> (<em>str</em>) &#8211; </li>
3566+
<li><strong>options</strong> (<em>str</em>) &#8211; </li>
3567+
</ul>
3568+
</td>
3569+
</tr>
3570+
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Returns messages the request status</p>
3571+
</td>
3572+
</tr>
3573+
</tbody>
3574+
</table>
3575+
</dd></dl>
3576+
<dl class="function">
3577+
<dt id="usbserialHostEnable">
3578+
<code class="descname">usbserialHostEnable</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#usbserialHostEnable" title="Permalink to this definition"></a></dt>
3579+
<dd><p>Requests that the host be enable for USB Serial connections.</p>
3580+
<table class="docutils field-list" frame="void" rules="none">
3581+
<col class="field-name" />
3582+
<col class="field-body" />
3583+
<tbody valign="top">
3584+
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">True if the USB Device is accesible</td>
3585+
</tr>
3586+
</tbody>
3587+
</table>
3588+
</dd></dl>
3589+
<dl class="function">
3590+
<dt id="usbserialWrite">
3591+
<code class="descname">usbserialWrite</code><span class="sig-paren">(</span><em>String ascii</em>, <em>String connID</em><span class="sig-paren">)</span><a class="headerlink" href="#usbserialWrite" title="Permalink to this definition"></a></dt>
3592+
<dd><p>Sends ASCII characters over the currently open USB Serial connection</p>
3593+
<table class="docutils field-list" frame="void" rules="none">
3594+
<col class="field-name" />
3595+
<col class="field-body" />
3596+
<tbody valign="top">
3597+
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
3598+
<li><strong>ascii</strong> (<em>str</em>) &#8211; </li>
3599+
<li><strong>connID</strong> (<em>str</em>) &#8211; </li>
3600+
</ul>
3601+
</td>
3602+
</tr>
3603+
</tbody>
3604+
</table>
3605+
</dd></dl>
3606+
<dl class="function">
3607+
<dt id="usbserialReadReady">
3608+
<code class="descname">usbserialReadReady</code><span class="sig-paren">(</span><em>connID</em><span class="sig-paren">)</span><a class="headerlink" href="#usbserialReadReady" title="Permalink to this definition"></a></dt>
3609+
<dd><table class="docutils field-list" frame="void" rules="none">
3610+
<col class="field-name" />
3611+
<col class="field-body" />
3612+
<tbody valign="top">
3613+
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>connID</strong> (<em>str</em>) &#8211; </td>
3614+
</tr>
3615+
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">True if the next read is guaranteed not to block</td>
3616+
</tr>
3617+
</tbody>
3618+
</table>
3619+
</dd></dl>
3620+
<dl class="function">
3621+
<dt id="usbserialRead">
3622+
<code class="descname">usbserialRead</code><span class="sig-paren">(</span><em>connID</em>, <em>bufferSize</em><span class="sig-paren">)</span><a class="headerlink" href="#usbserialRead" title="Permalink to this definition"></a></dt>
3623+
<dd><p>Read up to bufferSize ASCII characters.</p>
3624+
<table class="docutils field-list" frame="void" rules="none">
3625+
<col class="field-name" />
3626+
<col class="field-body" />
3627+
<tbody valign="top">
3628+
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
3629+
<li><strong>connID</strong> (<em>str</em>) &#8211; </li>
3630+
<li><strong>bufferSize</strong> (<em>int</em>) &#8211; </li>
3631+
</ul>
3632+
</td>
3633+
</tr>
3634+
</tbody>
3635+
</table>
3636+
</dd></dl>
3637+
<dl class="function">
3638+
<dt id="usbserialGetDeviceName">
3639+
<code class="descname">usbserialGetDeviceName</code><span class="sig-paren">(</span><em>connID</em><span class="sig-paren">)</span><a class="headerlink" href="#usbserialGetDeviceName" title="Permalink to this definition"></a></dt>
3640+
<dd><p>Queries a remote device for it&#8217;s name or null if it can&#8217;t be resolved</p>
3641+
<table class="docutils field-list" frame="void" rules="none">
3642+
<col class="field-name" />
3643+
<col class="field-body" />
3644+
<tbody valign="top">
3645+
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>connID</strong> (<em>str</em>) &#8211; </td>
3646+
</tr>
3647+
</tbody>
3648+
</table>
3649+
</dd></dl>
3650+
</div>
3651+
</div>
34303652
</div>
34313653
<div class="articleComments">
34323654
</div>

0 commit comments

Comments
 (0)