
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@cutos/drivers
Advanced tools
CUTOS drivers is used to simulate the hardware behavior of the serial port, including receiving and sending data, control signals, etc.
Developing with a serial port simulator is a convenient, safe, and efficient way to develop drivers. It does not require
real devices and is easier to control the test environment. It is especially suitable for the early development stage
and development that requires various test scenarios.
It is used to simulate the hardware behavior of the serial port, including receiving and sending data, control signals,
etc.
The Serialport class is used to handle serial port communication. It uses the serial port path, baud rate, callback
function, and simulator to create a new serial port object.
The SerialPortSimulator class creates a new serial port simulator to simulate serial port behavior.
Serial port: an extended interface using serial communication.
Serial port communication: a communication method in which the serial port sends and receives bytes bit by bit.
The Serialport class is used to handle serial port communication. It creates a new serial port object using the serial port path, baud rate, callback function, and simulator. It is used to simulate serial port communication data.
npm install @cutos/drivers
const {SerialPort} = require("@cutos/drivers");
constructor(path, baudRate, callback = null, simulator = null)
The driver creates a new serialport instance and returns the port result, which is often used in device connection related methods.
let serialport = new SerialPort('/dev/ttySS3', 19200, error => {
if (error) {
console.log(error)
}
}, simulator)
See @serialport/stream
Local libraries, such as ID card reader devices, require calling local dll libraries.
npm install @cutos/drivers
const {NativeLib} = require("@cutos/drivers");
constructor(lib_path, simulator = null)
let lib = new NativeLib('ghcmio.dll');
Find function
NativeLib.func(declaration);
Reference KOFFI
this.lib.func('size_t __stdcall mio_open(char* psport, char* psexport, int32_t baud)')
DeviceSimulator is the base class for simulator development. Currently, there are two derived classes: SerialPortSimulator and NativeLibSimulator.
Constructor
constructor(config, state)
Function that provides information to the simulator. Currently supported information includes: README.md and protocol.
Need to be rewritten in the derived class of the specific device simulator.
Return result {readme, doc}
getInfo()
{
let readme = fs.readFileSync(path.join(__dirname, 'README.md'), 'utf-8');
let doc = fs.readFileSync(path.join(__dirname, 'doc.pdf'), 'base64');
return {readme, doc}
}
When the emit command without parameters is used in the console, this function will be called to send default data to the driver.
Need to be overridden in the derived class of the specific device simulator.
Developing with a serial port simulator is a convenient, safe, and efficient way to develop drivers. It does not require real devices and is easier to control the test environment. It is especially suitable for the early development stage and development that requires various test scenarios. It is used to simulate the hardware behavior of the serial port, including receiving and sending data, control signals, etc. SerialPortSimulator inherits from DeviceSimulator.
Constructor, create a serialPortSimulator instance
constructor(config, state = null)
Port opening event.
If the derived class needs to handle the event after the port is opened, rewrite this function.
Receive data from the driver, and the driver uses the SerialPort.write(data) method to send data.
Derived classes need to rewrite this function to handle their own protocols.
serialPortSimulator.onReceiveData(data)
Send data to the driver, parameter data type is Buffer. The driver receives data in the SerialPort.on('data',(data)=>{}) function.
serialPortSimulator.emitData(data)
serialPortSimulator.emitData(Buffer.from([0xF5, 0x09, 0x00, 0x00, 0x00, 0x00, 0x09, 0xF5]))
| Name | Description | Download |
|---|---|---|
| device-height-weight-scale-v3.3.3 | Physical examination body height and weight device driver | Download |
simulator/device-height-weight-scale-simulator.js
const fs = require('node:fs');
const {Buffer} = require("node:buffer");
const path = require('node:path');
const config = require('../config.json');
const {SerialPortSimulator} = require('@cutos/drivers')
const {request, response} = require('../device-height-weight-scale-protocol')
class DeviceHeightWeightScaleSimulator extends SerialPortSimulator {
constructor() {
super(config, {height: 170, weight: 70});
this.responsing = false;
}
switchOn() {
if (this.timer) return
this.timer = setInterval(() => {
if (!this.responsing) {
let weight = +this.state.weight
this.emitData(response.generate_weight_data(weight))
}
}, 1000)
}
switchOff() {
clearInterval(this.timer)
}
onReceiveData(data) {
this.responsing = true
if (!Buffer.compare(request.GET_HEIGHT_WEIGHT, data)) {
let count = 0
let timer = setInterval(() => {
let height = +this.state.height
let weight = +this.state.weight
this.emitData(response.generate_height_weight_data(height, weight))
if (++count === 3) {
clearInterval(timer)
this.responsing = false
}
}, 1000)
}
if (!Buffer.compare(request.SWITCH_ON, data)) {
this.switchOn()
this.emitData(response.SWITCH_ON)
this.responsing = false
}
if (!Buffer.compare(request.SWITCH_OFF, data)) {
this.switchOff()
this.emitData(response.SWITCH_OFF)
this.responsing = false
}
}
getInfo() {
const readme = fs.readFileSync(path.join(__dirname, 'README.md'), 'utf8')
return {readme}
}
}
module.exports = {
DeviceHeightWeightScaleSimulator
}
NativeLibSimulator inherits from DeviceSimulator and is used for simulators with local dependency libraries, such as simulators for ID card reader devices.
Constructor
constructor(config, state = null)
Constructor, create a serialPortSimulator instance
let serialPortSimulator = new DeviceNFCSimulator(name);
sdk creates a device
let device = new DeviceFingerprint('mock');
Driver development uses the simulator
if (name === 'mock') {
this.simulator = new DeviceFingerprintSimulator()
}
The listening port is open and can be used to perform certain operations
serialPortSimulator.onOpen()
Emit serialPortSimulator data
serialPortSimulator.emitData(data)
serialPortSimulator.emitData(Buffer.from([0xF5, 0x09, 0x00, 0x00, 0x00, 0x00, 0x09, 0xF5]))
Handle events
serialPortSimulator.onEvent(event, params, callback)
onEvent(event, params, callback)
{
if (event === 'wake') {
this.userID = params.id;
this.emitData(Buffer.from([0xF5, 0x09, 0x00, 0x00, 0x00, 0x00, 0x09, 0xF5]))
callback('success')
} else {
callback('unsupported event')
}
}
Get help
serialPortSimulator.getHelp()
FAQs
CUTOS drivers is used to simulate the hardware behavior of the serial port, including receiving and sending data, control signals, etc.
We found that @cutos/drivers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

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.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.