Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
linux-device
Advanced tools
Native addon to communicate with linux devices (can also be used for sockets or FIFOs)
Native addon to communicate with linux devices (can also be used for sockets or FIFOs). All read and write operations are done in separate threads, resulting in higher performance compared to NodeJS filesystem functions
Install with npm
:
$ npm install linux-device
new DeviceHandle(String path, Boolean enableWrite, Number objectSize, [Number minimalObjectSize,] Function callback(Error err, Buffer data) )
Creates a new DeviceHandle instance.
Path
A path to a file or deviceenableWrite
True if file should be opened in write modeobjectSize
Maximal size in bytes for each callback eventminimalObjectSize
Minimal size in bytes for each callback event (defaults to ObjectSize)callback(Error err, Buffer data)
Callback function that is invoked whenever data of objectSize
is available.DeviceHandle.write(Buffer data [, Function callback(Error err)] )
Writes data to the device or file.
data
A buffer containing the data to write (append)callback(Error err)
[optional] Callback function containing an optional error while writing.DeviceHandle.ioctl(Number direction, Number type, Number cmd [, Buffer buffer])
Performs an ioctl
on the open device. Linux only.
direction
Either DeviceHandle.IOCTL_READ
, DeviceHandle.IOCTL_WRITE
, DeviceHandle.IOCTL_RW
or DeviceHandle.IOCTL_NONE
type
The type of the ioctlcmd
The command number of the ioctlbuffer
[optional] A buffer containing in and/or output of the ioctlDeviceHandle.ioctl_raw(Number cmd [, Buffer buffer])
Performs a raw ioctl
on the open device. Usage is discouraged. Linux only.
cmd
The command number of the ioctl, including direction, type and cmdbuffer
[optional] A buffer containing in and/or output of the ioctlDeviceHandle.close([Function callback()])
Closes the current device and invoke callback when the device is closed.
callback()
[optional] A callback functionvar DeviceHandle = require('linux-device');
var LIRC_IOCTL_TYPE = "i".charCodeAt(0);
var LIRC_IOCTL_SET_SEND_CARRIER = 0x13;
var LIRC_INTERVAL_SIZE = 4;
//Open device
var device = new DeviceHandle('/dev/lirc0', true, LIRC_INTERVAL_SIZE, function(err, data) {
if(err) return console.log("ERROR:", err);
console.log("received interval:", data.readUInt32LE(0).toString(16));
});
//Sets the IR carrier frequency
function setCarrier(carrier) {
var buffer = new Buffer(4);
buffer.writeUInt32LE(carrier, 0);
try {
device.ioctl(DeviceHandle.IOCTL_WRITE,
LIRC_IOCTL_TYPE, LIRC_IOCTL_SET_SEND_CARRIER, buffer);
} catch(e) {
console.log("An error occurred while performing lirc ioctl:", e);
}
}
//Transmits IR data through LIRC
function writeLircData(data, callback) {
if(!(data instanceof Buffer)) {
throw new Error("data must be an instance of Buffer");
}
var buffer = new Buffer(data.length*LIRC_INTERVAL_SIZE);
data.forEach(function(interval, i) {
buffer.writeUInt32LE(interval, i*LIRC_INTERVAL_SIZE);
}
device.write(data, callback);
}
//set the IR carrier frequency
setCarrier(38000);
//Transmit an IR beam every 2 seconds
var interval = setInterval(function() {
writeLircData([100,200,100,200,100], function() {
console.log("IR beam transmitted!");
});
}, 2000);
//close the device after 20 seconds
setTimeout(function() {
clearInterval(interval);
console.log("Closing device...");
device.close(function() {
console.log("Device closed!");
});
}, 20000);
FAQs
Native addon to communicate with linux devices (can also be used for sockets or FIFOs)
The npm package linux-device receives a total of 20 weekly downloads. As such, linux-device popularity was classified as not popular.
We found that linux-device demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.