New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@novastar/codec

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@novastar/codec

Core API for communication with devices using NovaStar protocol

latest
Source
npmnpm
Version
2.1.0
Version published
Maintainers
1
Created
Source

@novastar/codec

Core API for communication with devices using NovaStar protocol.

Go to API documentation.

Installation

Using npm:

npm install --save @novastar/codec@next

or yarn:

yarn add @novastar/codec@next

Usage

  • First, we need to create a connection, for this we need a stream (it can be a serial port or TCP socket)
import { connect, Socket } from 'net';
import SerialPort from 'serialport';
import { Request, Connection, DeviceType } from '@novastar/codec';

let connection;

// TCP socket
const socket = connect(5200, () => {
  connection = new Connection(socket);
})

// Serial port
const port = new SerialPort('COM11', { baudRate: 115200 }, () => {
  connection = new Connection(port);
})

It is recommended to use packages @novastar/serial and @novastar/net. They will contain helper methods to find connected devices

  • Using this connection you can send requests to devices (Sending cards/Receiving cards/Function cards) and receive responses
// Create a request to read a single byte
const readReq = new Request(1);
readReq.deviceType = DeviceType.ReceivingCard;
readReq.address = 0x02000001;
readReq.port = 0;
const { data: [value] } = await connection.send(readReq);
console.log(`Brightness on the first receiving card connected to 0 port is ${value}`);

// And this way you can write data to the device
const writeReq = new Request([255]);
writeReq.deviceType = DeviceType.ReceivingCard;
writeReq.address = 0x02000001;
await connection.send(writeReq);
  • Or you can create a session that implements some API methods. Since the native API contains more than 1000 methods, not all of which you will use, you can include the methods you need. See @novastar/native for details.
import { Session } from '@novastar/codec';
import '@novastar/native/build/main/generated/api/ReadGlobalBrightness';
import '@novastar/native/build/main/generated/api/SetGlobalBrightness';

const session = new Session(connection);
const screenIndex = 0;
const portIndex = 0;
const receivingCardIndex = 0;
// If `broadcast` is `true`, then there is no need to wait for an answer.
const broadcast = false;
const newBrightness = 255;
const currentBrightness = await session.ReadGlobalBrightness(screenIndex, portIndex, receivingCardIndex);
await session.SetGlobalBrightness(screenIndex, portIndex, receivingCardIndex, broadcast, newBrightness);
  • Close the connection
connection.close() // or session.close()

Keywords

NovaStar

FAQs

Package last updated on 28 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts