You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Build Linux SO]: https://img.shields.io/github/actions/workflow/status/TypeScriptPlayground/Serial/build_linux.yml?label=Build%20Linux%20SO&labelColor=343b42&logo=github&logoColor=959DA5'Linux Build'
[](https://github.com/TypeScriptPlayground/Serial/actions/workflows/build_linux.yml)
<ahref="https://deno.land"><imgalign="right"src="https://deno.land/logo.svg"height="150px"alt="the deno mascot dinosaur standing in the rain"></a>
7
12
8
13
A [serial](https://en.wikipedia.org/wiki/Serial_communication) library written in TypeScript for [Deno](https://deno.land) without any third party modules.
9
14
10
15
This library provides an interface for the communication with serial devices and **doesn't use any third party modules**. It uses C++ functions which are included in a [dynamic link library](https://de.wikipedia.org/wiki/Dynamic_Link_Library) or [shared object](https://en.wikipedia.org/wiki/Library_(computing)#Shared_libraries). These functions are then loaded by deno to establish a serial connection and talk to the devices.
11
16
12
-
A big thanks goes out to [@Katze719](https://github.com/Katze719) who wrote most of the C++ files and functions!
13
-
14
17
<br>
15
18
16
19
> <picture>
@@ -20,7 +23,7 @@ A big thanks goes out to [@Katze719](https://github.com/Katze719) who wrote most
20
23
>
21
24
> This library and the documentation are still work in progress!
22
25
23
-
###Features
26
+
## Features
24
27
- Communication with serial devices.
25
28
- Create multiple serial connections at the same time.
26
29
- List available ports and their properties.
@@ -29,129 +32,113 @@ A big thanks goes out to [@Katze719](https://github.com/Katze719) who wrote most
29
32
- Uses no third party modules.
30
33
- Works on different operating systems (check [compatibility](#compatibility) for mor info).
31
34
32
-
### Compatibility
33
-
-[x] Windows (implemented)
34
-
-[ ] Linux (in progress)
35
+
## Compatibility
36
+
| OS | Tested version | Current state |
37
+
|---------|------------------|---------------|
38
+
| Windows | Windows 10 (x64) | implemented |
39
+
| Linux | - | in progress |
35
40
36
-
###Possible/Known issues
41
+
## Possible/Known issues
37
42
- What happens if you open multiple connections from the same instance.
38
43
- Every function returns the status code although it is previously checked.
39
44
- What happens if you async read 2 times directly after each other.
40
45
- Linux write currently not working
41
46
42
-
### Usage
43
-
#### `class` Serial
47
+
## Examples - How to use
48
+
### Ports
49
+
Get a list with all serial ports and their info that are currently available on your system.
50
+
51
+
`main.ts`
44
52
```typescript
45
-
/**
46
-
* Create a new instance of a serial connection.
47
-
*/
48
-
newSerial()
49
-
```
53
+
import { Serial } from"./mod.ts";
50
54
51
-
<br>
55
+
// create new instance of a serial object
56
+
const serial =newSerial();
52
57
53
-
#### `getter property` Serial.isOpen
54
-
```typescript
55
-
/**
56
-
* Get the current connection status of the serial connection.
57
-
* @returns{boolean} Returns `true` if the serial connection is open, otherwise returns `false`
58
-
*/
59
-
getisOpen() : boolean
58
+
// get all available ports
59
+
const availablePorts =serial.getPortsInfo();
60
+
61
+
// console log the list
62
+
console.log(availablePorts);
60
63
```
61
64
62
-
<br>
65
+
> Example output:
66
+
> ```
67
+
> [
68
+
> { name: 'COM1' },
69
+
> { name: 'COM2' },
70
+
> ...
71
+
> { name: 'tty/USB1' }
72
+
> ]
73
+
> ```
63
74
64
-
#### `methode` Serial.open()
75
+
### Sending
76
+
Send data to a serial device. For exampe to an [Arduino](https://www.arduino.cc/).
77
+
78
+
`main.ts`
65
79
```typescript
66
-
/**
67
-
* Opens the serial connection.
68
-
* @param{string}port The port to connect
69
-
* @param{number}baudrate The baudrate
70
-
* @param{SerialOptions}serialOptions Additional options for the serial connection (`data bits`, `parity`, `stop bits`)
71
-
* @returns{number} The status code
72
-
*/
73
-
open(
74
-
port : string,
75
-
baudrate : number,
76
-
serialOptions?:SerialOptions
77
-
) : number
78
-
```
80
+
import { Serial } from "./mod.ts";
79
81
80
-
<br>
82
+
// create new instance of a serial object
83
+
const serial = new Serial();
81
84
82
-
#### `methode` Serial.close()
83
-
```typescript
84
-
/**
85
-
* Closes the serial connection.
86
-
*/
87
-
close() : number
88
-
```
85
+
// open the connection
86
+
serial.open();
89
87
90
-
<br>
88
+
// encode the message to a Uint8Array
89
+
const textToSend = 'Hello from TypeScript!'
90
+
const encodedTextToSend = new TextEncoder().encode(textToSend)
91
91
92
-
#### `methode` Serial.read()
93
-
```typescript
94
-
/**
95
-
* Read data from serial connection.
96
-
* @param{Uint8Array}buffer Buffer to read the bytes into
97
-
* @param{number}bytes The number of bytes to read
98
-
* @param{number}timeout The timeout in `ms`
99
-
* @param{number}multiplier The timeout between reading individual bytes in `ms`
0 commit comments