Skip to content

Commit 65bfdab

Browse files
committed
Update docs
1 parent 0ded250 commit 65bfdab

File tree

6 files changed

+100
-48
lines changed

6 files changed

+100
-48
lines changed

docs/API.js.html

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ <h1 class="page-title">API.js</h1>
4444
<article>
4545
<pre class="prettyprint source linenums"><code>import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
4646
import SerialPort from './SerialPort';
47-
48-
const { SerialPortAPI } = NativeModules;
47+
const {
48+
SerialPortAPI
49+
} = NativeModules;
4950
const eventEmitter = Platform.OS === 'android' ? new NativeEventEmitter(SerialPortAPI) : null;
50-
5151
export default class API {
5252
/**
5353
* @callback stringArrayCallback
@@ -59,21 +59,21 @@ <h1 class="page-title">API.js</h1>
5959
* @param {string} value
6060
*/
6161

62-
6362
/**
6463
* @typedef {Object} openOptions
6564
* @property {number} baudRate such as 9600
6665
* @property {number} [parity=0] 0: none, 1: odd, 2: even
6766
* @property {number} [dataBits=8] 5~8
6867
* @property {number} [stopBits=1] 1 or 2
68+
* @property {number} [readBufferSize=64] set read buffer size
6969
*/
7070

7171
/**
7272
* Get serial port device names
7373
* @param {stringArrayCallback} callback
7474
*/
7575
static deviceNames(callback) {
76-
if (Platform.OS !== 'android') throw new Error(`Not support ${Platform.OS}`)
76+
if (Platform.OS !== 'android') throw new Error(`Not support ${Platform.OS}`);
7777
SerialPortAPI.deviceNames(callback);
7878
}
7979

@@ -82,7 +82,7 @@ <h1 class="page-title">API.js</h1>
8282
* @param {stringArrayCallback} callback
8383
*/
8484
static devicePaths(callback) {
85-
if (Platform.OS !== 'android') throw new Error(`Not support ${Platform.OS}`)
85+
if (Platform.OS !== 'android') throw new Error(`Not support ${Platform.OS}`);
8686
SerialPortAPI.devicePaths(callback);
8787
}
8888

@@ -91,8 +91,8 @@ <h1 class="page-title">API.js</h1>
9191
* @returns {Promise&lt;Array&lt;string>>} paths
9292
*/
9393
static devicePathsAsync() {
94-
if (Platform.OS !== 'android') throw new Error(`Not support ${Platform.OS}`)
95-
return new Promise((resolve, reject) => {
94+
if (Platform.OS !== 'android') throw new Error(`Not support ${Platform.OS}`);
95+
return new Promise(resolve => {
9696
SerialPortAPI.devicePaths(resolve);
9797
});
9898
}
@@ -102,7 +102,7 @@ <h1 class="page-title">API.js</h1>
102102
* @param {string} suPath
103103
*/
104104
static setSuPath(suPath) {
105-
if (Platform.OS !== 'android') throw new Error(`Not support ${Platform.OS}`)
105+
if (Platform.OS !== 'android') throw new Error(`Not support ${Platform.OS}`);
106106
SerialPortAPI.setSuPath(suPath);
107107
}
108108

@@ -111,8 +111,8 @@ <h1 class="page-title">API.js</h1>
111111
* @param {stringCallback} callback
112112
*/
113113
static getSuPath(callback) {
114-
if (Platform.OS !== 'android') throw new Error(`Not support ${Platform.OS}`)
115-
SerialPortAPI.getSuPath(callback)
114+
if (Platform.OS !== 'android') throw new Error(`Not support ${Platform.OS}`);
115+
SerialPortAPI.getSuPath(callback);
116116
}
117117

118118
/**
@@ -121,15 +121,21 @@ <h1 class="page-title">API.js</h1>
121121
* @param {openOptions} options
122122
* @returns {Promise&lt;SerialPort>} connected serial port
123123
*/
124-
static open(devicePath, {baudRate, parity = 0, dataBits = 8, stopBits = 1}) {
125-
if (Platform.OS !== 'android') throw new Error(`Not support ${Platform.OS}`)
126-
return SerialPortAPI.open(devicePath, baudRate, parity, dataBits, stopBits)
127-
.then(serialPort => {
128-
return Promise.resolve(new SerialPort(serialPort, eventEmitter));
129-
})
124+
static open(devicePath, _ref) {
125+
let {
126+
baudRate,
127+
parity = 0,
128+
dataBits = 8,
129+
stopBits = 1,
130+
readBufferSize = 64
131+
} = _ref;
132+
if (Platform.OS !== 'android') throw new Error(`Not support ${Platform.OS}`);
133+
return SerialPortAPI.open(devicePath, baudRate, parity, dataBits, stopBits, readBufferSize).then(serialPort => {
134+
return Promise.resolve(new SerialPort(serialPort, eventEmitter));
135+
});
130136
}
131137
}
132-
</code></pre>
138+
//# sourceMappingURL=API.js.map</code></pre>
133139
</article>
134140
</section>
135141

@@ -143,7 +149,7 @@ <h1 class="page-title">API.js</h1>
143149
<br class="clear">
144150

145151
<footer>
146-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Mon May 02 2022 08:46:19 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
152+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Thu Jun 15 2023 15:23:59 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
147153
</footer>
148154

149155
<script>prettyPrint();</script>

docs/SerialPort.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ <h4 class="name" id="close"><span class="type-signature"></span>close<span class
9090

9191
<dt class="tag-source">Source:</dt>
9292
<dd class="tag-source"><ul class="dummy"><li>
93-
<a href="SerialPort.js.html">SerialPort.js</a>, <a href="SerialPort.js.html#line78">line 78</a>
93+
<a href="SerialPort.js.html">SerialPort.js</a>, <a href="SerialPort.js.html#line88">line 88</a>
9494
</li></ul></dd>
9595

9696

@@ -177,7 +177,7 @@ <h4 class="name" id="getPath"><span class="type-signature"></span>getPath<span c
177177

178178
<dt class="tag-source">Source:</dt>
179179
<dd class="tag-source"><ul class="dummy"><li>
180-
<a href="SerialPort.js.html">SerialPort.js</a>, <a href="SerialPort.js.html#line40">line 40</a>
180+
<a href="SerialPort.js.html">SerialPort.js</a>, <a href="SerialPort.js.html#line47">line 47</a>
181181
</li></ul></dd>
182182

183183

@@ -282,7 +282,7 @@ <h4 class="name" id="onReceived"><span class="type-signature"></span>onReceived<
282282

283283
<dt class="tag-source">Source:</dt>
284284
<dd class="tag-source"><ul class="dummy"><li>
285-
<a href="SerialPort.js.html">SerialPort.js</a>, <a href="SerialPort.js.html#line58">line 58</a>
285+
<a href="SerialPort.js.html">SerialPort.js</a>, <a href="SerialPort.js.html#line65">line 65</a>
286286
</li></ul></dd>
287287

288288

@@ -440,7 +440,7 @@ <h4 class="name" id="send"><span class="type-signature"></span>send<span class="
440440

441441
<dt class="tag-source">Source:</dt>
442442
<dd class="tag-source"><ul class="dummy"><li>
443-
<a href="SerialPort.js.html">SerialPort.js</a>, <a href="SerialPort.js.html#line49">line 49</a>
443+
<a href="SerialPort.js.html">SerialPort.js</a>, <a href="SerialPort.js.html#line56">line 56</a>
444444
</li></ul></dd>
445445

446446

@@ -601,7 +601,7 @@ <h5>Returns:</h5>
601601
<br class="clear">
602602

603603
<footer>
604-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Mon May 02 2022 08:46:19 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
604+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Thu Jun 15 2023 15:23:59 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
605605
</footer>
606606

607607
<script>prettyPrint();</script>

docs/SerialPort.js.html

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@ <h1 class="page-title">SerialPort.js</h1>
4242

4343
<section>
4444
<article>
45-
<pre class="prettyprint source linenums"><code>import { NativeModules } from 'react-native';
45+
<pre class="prettyprint source linenums"><code>function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
46+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
47+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
48+
import { NativeModules } from 'react-native';
4649
import { Buffer } from 'buffer';
47-
48-
const { SerialPortAPI } = NativeModules;
50+
const {
51+
SerialPortAPI
52+
} = NativeModules;
4953
const DataReceivedEvent = 'dataReceived';
50-
5154
/**
5255
* @name Subscription
5356
* @class
@@ -72,10 +75,14 @@ <h1 class="page-title">SerialPort.js</h1>
7275
*/
7376
class SerialPort {
7477
constructor(serialPort, eventEmitter) {
78+
_defineProperty(this, "path", void 0);
79+
_defineProperty(this, "eventEmitter", void 0);
80+
_defineProperty(this, "listeners", void 0);
81+
_defineProperty(this, "subscriptions", void 0);
7582
this.path = serialPort.path;
76-
this.serialPort = serialPort;
7783
this.eventEmitter = eventEmitter;
7884
this.listeners = [];
85+
this.subscriptions = [];
7986
}
8087

8188
/**
@@ -91,7 +98,7 @@ <h1 class="page-title">SerialPort.js</h1>
9198
* @returns {Promise} success promise
9299
*/
93100
send(hex) {
94-
return SerialPortAPI.send(this.path, hex)
101+
return SerialPortAPI.send(this.path, hex);
95102
}
96103

97104
/**
@@ -100,36 +107,38 @@ <h1 class="page-title">SerialPort.js</h1>
100107
* @returns {Subscription} subscription
101108
*/
102109
onReceived(listener) {
103-
const listenerProxy = (event) => {
110+
const listenerProxy = event => {
111+
if (!event.path || this.path !== event.path) {
112+
return;
113+
}
104114
if (!event.data) {
105115
return;
106116
}
107-
108117
const buff = Buffer.from(event.data, 'hex');
109118
listener(buff);
110-
}
111-
119+
};
112120
this.listeners.push({
113121
event: DataReceivedEvent,
114122
listener: listenerProxy
115123
});
116-
return this.eventEmitter.addListener(DataReceivedEvent, listenerProxy)
124+
const sub = this.eventEmitter.addListener(DataReceivedEvent, listenerProxy);
125+
this.subscriptions.push(sub);
126+
return sub;
117127
}
118128

119129
/**
120130
* Close serial port
121131
*/
122132
close() {
123-
for (var i = 0; i &lt; this.listeners.length; i++) {
124-
let {event, listener} = this.listeners[i];
125-
this.eventEmitter.removeListener(event, listener)
133+
for (var i = 0; i &lt; this.subscriptions.length; i++) {
134+
const sub = this.subscriptions[i];
135+
sub.remove();
126136
}
127-
return SerialPortAPI.close(this.path)
137+
return SerialPortAPI.close(this.path);
128138
}
129139
}
130-
131140
export default SerialPort;
132-
</code></pre>
141+
//# sourceMappingURL=SerialPort.js.map</code></pre>
133142
</article>
134143
</section>
135144

@@ -143,7 +152,7 @@ <h1 class="page-title">SerialPort.js</h1>
143152
<br class="clear">
144153

145154
<footer>
146-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Mon May 02 2022 08:46:19 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
155+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Thu Jun 15 2023 15:23:59 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
147156
</footer>
148157

149158
<script>prettyPrint();</script>

docs/Subscription.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ <h4 class="name" id="remove"><span class="type-signature"></span>remove<span cla
8888

8989
<dt class="tag-source">Source:</dt>
9090
<dd class="tag-source"><ul class="dummy"><li>
91-
<a href="SerialPort.js.html">SerialPort.js</a>, <a href="SerialPort.js.html#line13">line 13</a>
91+
<a href="SerialPort.js.html">SerialPort.js</a>, <a href="SerialPort.js.html#line16">line 16</a>
9292
</li></ul></dd>
9393

9494

@@ -178,7 +178,7 @@ <h4 class="name" id="remove"><span class="type-signature"></span>remove<span cla
178178
<br class="clear">
179179

180180
<footer>
181-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Mon May 02 2022 08:46:19 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
181+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Thu Jun 15 2023 15:23:59 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
182182
</footer>
183183

184184
<script>prettyPrint();</script>

docs/global.html

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ <h4 class="name" id="listener"><span class="type-signature"></span>listener<span
976976

977977
<dt class="tag-source">Source:</dt>
978978
<dd class="tag-source"><ul class="dummy"><li>
979-
<a href="SerialPort.js.html">SerialPort.js</a>, <a href="SerialPort.js.html#line19">line 19</a>
979+
<a href="SerialPort.js.html">SerialPort.js</a>, <a href="SerialPort.js.html#line22">line 22</a>
980980
</li></ul></dd>
981981

982982

@@ -1104,7 +1104,7 @@ <h4 class="name" id="openOptions">openOptions</h4>
11041104

11051105
<dt class="tag-source">Source:</dt>
11061106
<dd class="tag-source"><ul class="dummy"><li>
1107-
<a href="API.js.html">API.js</a>, <a href="API.js.html#line19">line 19</a>
1107+
<a href="API.js.html">API.js</a>, <a href="API.js.html#line18">line 18</a>
11081108
</li></ul></dd>
11091109

11101110

@@ -1312,6 +1312,43 @@ <h5 class="subsection-title">Properties:</h5>
13121312
</tr>
13131313

13141314

1315+
1316+
<tr>
1317+
1318+
<td class="name"><code>readBufferSize</code></td>
1319+
1320+
1321+
<td class="type">
1322+
1323+
1324+
<span class="param-type">number</span>
1325+
1326+
1327+
1328+
</td>
1329+
1330+
1331+
<td class="attributes">
1332+
1333+
&lt;optional><br>
1334+
1335+
1336+
1337+
</td>
1338+
1339+
1340+
1341+
<td class="default">
1342+
1343+
<code>64</code>
1344+
1345+
</td>
1346+
1347+
1348+
<td class="description last">set read buffer size</td>
1349+
</tr>
1350+
1351+
13151352
</tbody>
13161353
</table>
13171354

@@ -1619,7 +1656,7 @@ <h5>Parameters:</h5>
16191656
<br class="clear">
16201657

16211658
<footer>
1622-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Mon May 02 2022 08:46:19 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
1659+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Thu Jun 15 2023 15:23:59 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
16231660
</footer>
16241661

16251662
<script>prettyPrint();</script>

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ <h2>Development</h2>
106106
<br class="clear">
107107

108108
<footer>
109-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.10</a> on Mon May 02 2022 08:46:19 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
109+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Thu Jun 15 2023 15:23:59 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
110110
</footer>
111111

112112
<script>prettyPrint();</script>

0 commit comments

Comments
 (0)