Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add functionality to connect to serial via NodeJS #98

66 changes: 66 additions & 0 deletions example/nodeSerial/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { SerialPort } from "serialport";
import { NodeSerialConnection } from "./dist/index.js";

const Connect = async () => {
const connection = new NodeSerialConnection();
// COM4 is the port that works for me, you'll have to get your path from SerialPort.list()
await connection.connect({
portPath: "COM4",
concurrentLogOutput: false,
});
console.log(await SerialPort.list());
connection.events.onMessagePacket.subscribe((packet) => {
onMessage(packet.from, packet.data);
});

connection.events.onPrivatePacket.subscribe((packet) => {
onMessage(packet.from, packet.data);
});

connection.events.onLogEvent.subscribe((packet) => {
console.log("LogEvent: ", packet);
});

connection.events.onDeviceMetadataPacket.subscribe((packet) => {
console.log("DeviceMetadataPacket: ", packet);
});

connection.events.onDeviceDebugLog.subscribe((packet) => {
console.log("DeviceDebugLog: ", packet);
});

connection.events.onFromRadio.subscribe((packet) => {
console.log("FromRadio: ", packet);
});

connection.events.onDeviceStatus.subscribe((packet) => {
console.log("DeviceStatus: ", packet);
});

connection.events.onMyNodeInfo.subscribe((packet) => {
console.log("NodeInfo: ", packet);
});
const onMessage = (sender, message) => {
console.log(`Message from: ${sender}`);
console.log(`Message was: ${message}`);
};

connection.events.onRemoteHardwarePacket.subscribe((packet) => {
console.log("Remote Hardware Packet: ", packet);
});

connection.events.onRoutingPacket.subscribe((packet) => {
console.log("Routing packet: ", packet);
});

connection.events.onConfigPacket.subscribe((packet) => {
console.log("Config: ", packet);
});

// Request configuration data from device (I think this will help trigger other serial events being processed)
await connection.configure();
};

Connect().catch((err) => {
console.log(err);
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dependencies": {
"crc": "^4.3.2",
"ste-simple-events": "^3.0.11",
"serialport": "^12.0.0",
"tslog": "^4.9.3"
},
"devDependencies": {
Expand Down
168 changes: 168 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./bleConnection.js";
export * from "./httpConnection.js";
export * from "./serialConnection.js";
export * from "./nodeSerialConnection.js";
Loading
Loading