Skip to content

Commit a812e3a

Browse files
committed
Added details about USB serial communication
1 parent 5b99047 commit a812e3a

File tree

7 files changed

+142
-10
lines changed

7 files changed

+142
-10
lines changed

_build/pages/android.markdown

+78
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,84 @@ wend
223223

224224
The code snippet demonstrates how to use REQUEST to interact with a specified endpoint, providing necessary data and token for authentication.
225225

226+
## IoT Device Communication
227+
228+
### USB Serial Support
229+
230+
These functions allow you to connect, send, and receive data over a USB serial connection.
231+
232+
🔌 Open a USB Serial Connection
233+
234+
```smallbasic
235+
const usb = android.openUsbSerial(vendorId, [baud], [timeout])
236+
```
237+
238+
Parameters:
239+
240+
- `vendorId`: (required) The USB device's Vendor ID.
241+
- `baud`: (optional) The baud rate for communication (default: 19200).
242+
- `timeout`: (optional) imeout in milliseconds for receive operations (default: 5000 ms).
243+
244+
Returns:
245+
246+
- A USB serial object to be used with other USB functions.
247+
248+
❌ Close the USB Connection
249+
250+
```smallbasic
251+
usb.close()
252+
```
253+
254+
Closes the current USB connection. Always call this when you're done using the device.
255+
256+
📋 Get Device Description
257+
258+
```smallbasic
259+
usb.description()
260+
```
261+
262+
Returns a string with details about the connected USB device, such as product name or manufacturer info (if available).
263+
264+
📥 Receive Data
265+
266+
```smallbasic
267+
dat = usb.receive()
268+
```
269+
270+
Reads incoming data from the connected USB device.
271+
272+
Returns:
273+
274+
A string containing the received data, or an empty string if no data is received before timeout.
275+
276+
📤 Send Data
277+
278+
```smallbasic
279+
n = usb.send(dat)
280+
```
281+
282+
Sends data to the connected USB device.
283+
284+
Parameters:
285+
286+
dat – The data to send as a string.
287+
288+
Returns:
289+
290+
The number of bytes successfully sent.
291+
292+
📝 Example
293+
294+
```
295+
import android
296+
usb = android.openUsbSerial(0x16C0)
297+
while 1
298+
input k
299+
n = usb.send(k);
300+
print "sent "; n
301+
print usb.receive()
302+
wend
303+
```
226304

227305
## How to edit and run a program
228306

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ <h2 id="more-information">More information</h2>
140140
articles in the <a href="/pages/articles.html">article section</a>.</p>
141141
</div>
142142
<div class="pagefooter">
143-
This page was last edited on Thu, 20 Feb 2025 21:34:29 +0100
143+
This page was last edited on Thu, 13 Mar 2025 20:29:49 +0100
144144
|
145145
<a href="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
146146
processed with

pages/android.html

+58-5
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ <h2 id="getting-started">Getting started</h2>
5252
</iframe>
5353
</div>
5454
<p>Please note, that at the first start of the Android version of
55-
SmallBASIC, the editor is turned off. A mouse click on a program name
56-
will start it immediately. If you want to edit the file, please turn on
57-
the editor by clicking on the three dots in the lower right corner and
58-
choosing the entry <code>Editor [OFF]</code> to enable the editor.</p>
55+
SmallBASIC, the editor is turned off. A tap on a program name will start
56+
it immediately. If you want to edit the file, please turn on the editor
57+
by tapping on the three dots in the lower right corner and choosing the
58+
entry <code>Editor [OFF]</code> to enable the editor.</p>
5959
<h2 id="step-by-step-guide">Step-by-Step Guide</h2>
6060
<p><img src="/images/android_menu1.png"
6161
title="System Menu button" /></p>
@@ -235,6 +235,59 @@ <h2 id="https-web-request">HTTPS Web request</h2>
235235
<p>The code snippet demonstrates how to use REQUEST to interact with a
236236
specified endpoint, providing necessary data and token for
237237
authentication.</p>
238+
<h2 id="iot-device-communication">IoT Device Communication</h2>
239+
<h3 id="usb-serial-support">USB Serial Support</h3>
240+
<p>These functions allow you to connect, send, and receive data over a
241+
USB serial connection.</p>
242+
<p>🔌 Open a USB Serial Connection</p>
243+
<div class="sourceCode" id="cb15"><pre
244+
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="dt">const</span> usb = android.openUsbSerial(vendorId, [baud], [timeout])</span></code></pre></div>
245+
<p>Parameters:</p>
246+
<ul>
247+
<li><code>vendorId</code>: (required) The USB device’s Vendor ID.</li>
248+
<li><code>baud</code>: (optional) The baud rate for communication
249+
(default: 19200).</li>
250+
<li><code>timeout</code>: (optional) imeout in milliseconds for receive
251+
operations (default: 5000 ms).</li>
252+
</ul>
253+
<p>Returns:</p>
254+
<ul>
255+
<li>A USB serial object to be used with other USB functions.</li>
256+
</ul>
257+
<p>❌ Close the USB Connection</p>
258+
<div class="sourceCode" id="cb16"><pre
259+
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a>usb.<span class="fu">close</span>()</span></code></pre></div>
260+
<p>Closes the current USB connection. Always call this when you’re done
261+
using the device.</p>
262+
<p>📋 Get Device Description</p>
263+
<div class="sourceCode" id="cb17"><pre
264+
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>usb.description()</span></code></pre></div>
265+
<p>Returns a string with details about the connected USB device, such as
266+
product name or manufacturer info (if available).</p>
267+
<p>📥 Receive Data</p>
268+
<div class="sourceCode" id="cb18"><pre
269+
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>dat = usb.receive()</span></code></pre></div>
270+
<p>Reads incoming data from the connected USB device.</p>
271+
<p>Returns:</p>
272+
<p>A string containing the received data, or an empty string if no data
273+
is received before timeout.</p>
274+
<p>📤 Send Data</p>
275+
<div class="sourceCode" id="cb19"><pre
276+
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a>n = usb.send(dat)</span></code></pre></div>
277+
<p>Sends data to the connected USB device.</p>
278+
<p>Parameters:</p>
279+
<p>dat – The data to send as a string.</p>
280+
<p>Returns:</p>
281+
<p>The number of bytes successfully sent.</p>
282+
<p>📝 Example</p>
283+
<pre><code>import android
284+
usb = android.openUsbSerial(0x16C0)
285+
while 1
286+
input k
287+
n = usb.send(k);
288+
print &quot;sent &quot;; n
289+
print usb.receive()
290+
wend</code></pre>
238291
<h2 id="how-to-edit-and-run-a-program">How to edit and run a
239292
program</h2>
240293
<h3 id="internal-editor">Internal editor:</h3>
@@ -304,7 +357,7 @@ <h2 id="privacy-policy">Privacy Policy <a
304357
<p><a href="privacy.html">Privacy Policy</a></p>
305358
</div>
306359
<div class="pagefooter">
307-
This page was last edited on Mon, 7 Apr 2025 22:04:07 +0200
360+
This page was last edited on Mon, 7 Apr 2025 22:40:38 +0200
308361
|
309362
<a href="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
310363
processed with

pages/android_changelog.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ <h1 id="android-changelog">Android Changelog</h1>
450450
</ul>
451451
</div>
452452
<div class="pagefooter">
453-
This page was last edited on Fri, 26 Apr 2024 06:53:31 +0930
453+
This page was last edited on Sat, 22 Mar 2025 21:01:31 +1030
454454
|
455455
<a href="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
456456
processed with

pages/android_file_transfer.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ <h2 id="step-by-step-guide">Step-by-Step Guide</h2>
6060
</div>
6161
</div>
6262
<div class="pagefooter">
63-
This page was last edited on |
63+
This page was last edited on Wed, 16 Apr 2025 21:04:07 +0200
64+
|
6465
<a href="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
6566
processed with
6667
<a href="https://pandoc.org/MANUAL.html#pandocs-markdown" target="_blank" rel="nofollow">pandoc 3.1.12.1</a>

pages/articles.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ <h2 id="miscellaneous">Miscellaneous</h2>
100100
</ul>
101101
</div>
102102
<div class="pagefooter">
103-
This page was last edited on Thu, 20 Feb 2025 21:34:29 +0100
103+
This page was last edited on Wed, 16 Apr 2025 21:04:07 +0200
104104
|
105105
<a href="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
106106
processed with

pages/guide.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ <h2 id="ExceptionHandling">Exception Handling</h2>
16361636
href="https://smallbasic.github.io/reference/1425.html">TRY</a>.</p>
16371637
</div>
16381638
<div class="pagefooter">
1639-
This page was last edited on Mon, 7 Apr 2025 22:04:07 +0200
1639+
This page was last edited on Wed, 16 Apr 2025 21:04:07 +0200
16401640
|
16411641
<a href="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
16421642
processed with

0 commit comments

Comments
 (0)