2021-01-12 14:29:47 +08:00
|
|
|
## iostream 扩展函数
|
|
|
|
|
|
|
|
### 1.iostream\_get\_istream
|
|
|
|
|
2021-09-09 15:10:12 +08:00
|
|
|
> 获取输入流对象。
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
#### 原型
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
2021-09-09 15:10:12 +08:00
|
|
|
iostream_get_istream(iostream) => object
|
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
2022-08-23 10:34:55 +08:00
|
|
|
var a = iostream_serial_create("COM4");
|
|
|
|
var b = iostream_get_istream(a);
|
2022-08-23 10:12:36 +08:00
|
|
|
```
|
|
|
|
|
2021-01-12 14:29:47 +08:00
|
|
|
### 2.iostream\_get\_ostream
|
|
|
|
|
2021-09-09 15:10:12 +08:00
|
|
|
> 获取输出流对象。
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
#### 原型
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
iostream_get_ostream(iostream) => object
|
2021-09-09 15:10:12 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
2022-08-23 10:34:55 +08:00
|
|
|
var a = iostream_serial_create("COM4");
|
|
|
|
var b = iostream_get_ostream(a);
|
2021-09-09 15:10:12 +08:00
|
|
|
```
|
|
|
|
|
2021-01-12 14:29:47 +08:00
|
|
|
### 更多示例
|
|
|
|
```js
|
|
|
|
//
|
|
|
|
// start serial echo server first
|
|
|
|
// ./bin/serial_recv 4000
|
|
|
|
//
|
|
|
|
|
2022-08-23 10:34:55 +08:00
|
|
|
var a = iostream_serial_create("/dev/ttys001", 0)
|
|
|
|
var b = iostream_get_ostream(a)
|
|
|
|
var c = iostream_get_istream(a)
|
2021-01-12 14:29:47 +08:00
|
|
|
|
|
|
|
assert(ostream_write_uint32(b, 6) == 4)
|
|
|
|
assert(ostream_write_string(b, "hello\n") == 6)
|
|
|
|
|
|
|
|
assert(istream_read_uint32(c, 3000) == 6)
|
|
|
|
assert(istream_read_string(c, 6, 3000) == "hello\n")
|
|
|
|
```
|