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
A serial library written in TypeScript for Deno without any third party modules.
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 or shared object. These functions are then loaded by deno to establish a serial connection and talk to the devices.
This library and the documentation are still work in progress!
Currently the library does not work correctly!
Features
Communication with serial devices.
Create multiple serial connections at the same time.
List available ports and their properties.
Set timeouts for both reading and writing.
All functions are async (currently not implemented yet).
Uses no third party modules.
Works on different operating systems (check compatibility for mor info).
Compatibility
OS
Tested version
Current state
Windows
Windows 10 (x64)
implemented
Linux
Ubuntu Server 22.04 LTS
implemented
Examples - How to use
To use this library you need the following flags to run it:
--unstable
--allow-ffi
Ports
Get a list with all serial ports and their info that are currently available on your system.
main.ts
import{Serial}from"./mod.ts";// create new instance of a serial objectconstserial=newSerial();// get all available portsconstavailablePorts=serial.getPortsInfo();// console log the listconsole.log(availablePorts);
Send data to a serial device. For exampe to an Arduino.
main.ts
import{Serial,baudrate}from"./mod.ts";// create new instance of a serial objectconstserial=newSerial();// open the connectionserial.open('COM1',baudrate.B9600);// encode the message to a Uint8ArrayconsttextToSend='Hello from TypeScript!';constencodedTextToSend=newTextEncoder().encode(textToSend);// send the messageserial.send(encodedTextToSend,encodedTextToSend.length);
Reading
Read data from a serial device. Again, in our example from an Arduino.
Depending on your Arduino board you may need to press the reset button on the board after uploading the sketch, in order to receive data.
sketch.ino
voidsetup() {
Serial.begin(9600);
while (!Serial) {
;
}
}
voidloop() {
Serial.println("Hello from Arduino!");
}
main.ts
import{Serial,baudrate}from"./mod.ts";// create new instance of a serial objectconstserial=newSerial();// open the connectionserial.open('COM1',baudrate.B9600);// create a new buffer to store incoming bytes,// in this example we want to read a maximum of 100 bytesconstbufferToRead=newUint8Array(100);// read data into the bufferserial.read(bufferToRead,bufferToRead.length);// decode the data from the bufferconstdecodedTextToRead=newTextDecoder().decode(bufferToRead);// console log the textconsole.log(decodedTextToRead);