
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
raw-device
Advanced tools
A module to remotely control devices using LAN-TCP or RS232-serial connections
raw-device is Node module to remotely control devices using LAN/TCP or RS-232/serial connections.
The device control protocal must be based on sending and receiving sequence of bytes/ASCII characters in request-response schema which is a common for communication protocols.
A base object RAW is thought to be a prototype for other, more specific communication objects, but can also be used as stand-alone, full-functional object for simple scenarios.
const RAW = require('raw-device');
//send-receive data for TCP socket device
const dev1 = new RAW({host: '192.168.4.31', port: 9761});
dev1.emitter.on('responseFromDevice', data => console.log(data));
dev1.process('some_command_str\n');
//send data for Serial device
const dev2 = new RAW({path: 'com2'});
dev2.process('00x00x00x00x14x60', '3Bx78x5D');
The primary exported object is RAW, which you'll use directly to communicate with serial or tcp devices or use as prototype for you own objects. This section covers direct use.
new RAW(AddressObject, OptionsObject)AddressObject <Object> - required. Use only properties associated with the desired mode (serial, tcp, stream)
name <string> - default: 'RAWdevice'path <string> - required. Use valid serial path available in system.baudRate <number> - default 9600dataBits <number> - default 8parity <string> - default 'none'stopBits <number> - default 1host <string> - required. Use valid IP addressport <number> - default 23stream <Stream> - required. The stream must be opened read/write Node.js stream. This mode is used when multiple devices are chained with RS232 cables and connected to single system serial port. RAW object does not cares about the stream. You have to maintain stream yourself (open, close, error handling).OptionsObject <Object> - optional, default is {encoding: 'ASCII', duration: 1500, disconnect: true, splitter: {timeout: 1100}}
encoding <string> - default 'ASCII'duration <number> - default 1500 ms. Inter-command period [ms]. A time for device to process command and to prepare and send a response.disconnect <boolean|number> - default true. Connecion cycle scheme. Use true, false or timeout[ms]. True means close connection when command queue is empty, false means do not close connection, number means close connection after time of connection inactivity.splitter <Object> - Used to select one among three supported transform streams which merge incoming data chunks and split it into valid responses. Only single property from delimiter, regex, timeout can be used. Default is {timeout: 1100}
delimiter <string> - use @serialport/parser-delimiter with string delimiterincludeDelimiter <boolean> - if string delimiter is used includeDelimiter decides if delimiter string itself is included in result stringregex <Regex> - use @serialport/parser-regex with regextimeout <number> - use @serialport/parser-inter-byte-timeout with timeout. Response is completed if inter-byte time is longer then timeout. Please consider that timeout must be shorter than duration (inter-command period) and disconnect time (if disconnect use timeout scheme).logger <Object> - used to log data sent to and/or coming from device. Logs are written in program directory. File names are generated automaticly.
devlog <boolean> - log data coming from device.talklog <boolean> - log data sent to and coming from device in single file.dictionary <Map> - default is empty. Sometimes it is more convenient to use friendly commands rather then unnatural sequence of Hex/ASCII. The dictionary is just for that. It must contain friendly commands as keys and corresponding Hex/ASCII sequence as valuesprocess(...commands)Commands can be regular strings or hexadecimal encoded strings. Hexadecimal strings can use x, :(colon) or -(minus) as separator. Usually devices expect commands to be terminated with some special character. Most common is CR(carriage return, 0x0D, \r). Please remember to append termination character manually at the end of command string. Example: process('some_command\r').
There are some internal commands which starts with #. They are not sent to device, but are processed by RAW itself.
#pause number - Append additional pause between neighboring commands as number of miliseconds.#connect - Force to open connection to device.#close - Force to close connection to device.responseFromDeviceEmited when device response is properly decoded.
response <Object>
name <string - device namedev <string> - obsolete, same as nameraw <Buffer> - not decoded raw responsevalue <string> - response decoded to string valuecommandForDeviceEmited when command is properly encoded and sent to device. Of course only encoded property is sent to device itself.
command <Object>
name <string> - device namecommand <string> - a command itself, not parsed or encodedencodedstr <string> - command encoded as stringencoded <Buffer> - command encoded as Bufferduration <number> - time [ms] for device to process the command (and generate a possible response).connectionDataA data which comes directly from device port "as is". Not decoded, merged or chopped by splitter. Event is not emited in stream mode.
dataObj <Object>
name <string> - device nameaddress <string> - device address as stringdata <Buffer> - data itselfconnectionStatusEmited when device connection status changes. Event is not emited in stream mode.
statusObj <Object>
name <string> - device namedev <string> - obsolete, same as nameaddress <string> - device address as stringstatus <string> - connection statusmore <string|Object> - additional status informationFAQs
A module to remotely control devices using LAN-TCP or RS232-serial connections
We found that raw-device demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.