File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 1
- - [ ] ls to search for all available serials
1
+ - [x] open a serial via file and lock it
2
+ - [x] ls to search for all available serials
2
3
- [ ] reconfiguration of the serial
Original file line number Diff line number Diff line change @@ -22,7 +22,13 @@ type serial_cfg_t = Static<typeof serial_cfg_schema>
22
22
23
23
const core = globalThis [ Symbol . for ( 'tjs.internal.core' ) ] ;
24
24
25
- export function open ( file : string , cfg : serial_cfg_t ) : tjs . FileHandle {
25
+ /**
26
+ * Open a serial device and lock it.
27
+ * @param file the path for the file mapped serial.
28
+ * @param cfg the configuration of the serial.
29
+ * @returns a normal file handle. Just use it as you normally would.
30
+ */
31
+ export function open ( file : string , cfg ?: serial_cfg_t ) : tjs . FileHandle {
26
32
const pcfg = Value . Default ( serial_cfg_schema , cfg )
27
33
//@ts -ignore
28
34
const fd = core . $__MODULE__ . configure ( file , {
@@ -36,6 +42,19 @@ export function open(file: string, cfg: serial_cfg_t) : tjs.FileHandle {
36
42
else throw new Error ( `Unable to use serial connection with [${ file } ]` ) ;
37
43
}
38
44
45
+ /**
46
+ *
47
+ * @returns The list of available files mapping serial devices.
48
+ */
49
+ export async function list ( ) : Promise < string [ ] > {
50
+ const names = [ ]
51
+ const dirIter = await tjs . readdir ( '/dev/serial/by-id/' ) ;
52
+ for await ( const item of dirIter ) {
53
+ names . push ( `/dev/serial/by-id/${ item . name } ` ) ;
54
+ }
55
+ return names ;
56
+ }
57
+
39
58
export {
40
59
serial_cfg_schema , type serial_cfg_t ,
41
60
}
You can’t perform that action at this time.
0 commit comments