lg-signage
v1.0.1
Published
An object to remotely control LG signage displays using TCP or RS-232 connections
Downloads
3
Maintainers
Readme
Introduction
lg-signage
is module to control LG displays (LG digital signage, monitor signage) over LAN-TCP or RS232-serial connections. It is NOT for use with LG TV sets.
Main features
- different connection modes: tcp/serial/stream
- different schemas of connect-disconnect cycle
- command queuing and timing management
- events driven
Usage
const LG = require('lg-signage');
//send-receive data using TCP socket
const disp1 = new LG({host: '192.168.4.31', id: 1});
disp1.emitter.on('responseFromDevice', data => console.log(data));
disp1.process('sn?', 'input?'); //ask for serial number and active input
//send command using serial
const disp2 = new LG({path: 'com2', id: 2});
disp2.process('backlight 30'); //adjust display backlight to 30
LGDS Object
The primary exported object is LGDS
. It extensively uses RAW
object from raw-device
as its prototype. Data neccesery to process commands is in lgds.xml
file.
Constructor new LGDS(AddressObject, OptionsObject)
AddressObject <Object>
- required. Use only properties associated with the desired mode (serial, tcp, stream)name <string>
- default 'LGDigitalSignage'id <number>
- default 1. NOTEs for serial mode: all displays in RS-232 chain must have unique id number. If you set id: 0 inAddressObject
, all displays execute commands, but no one of them return a response.
//for serialpath <string>
- required. Use valid serial path available in system.baudRate <number>
- default 9600dataBits <number>
- default 8parity <string>
- default 'none'stopBits <number>
- default 1
//for tcphost <string>
- required. Use valid IP addressport <number>
- default 9761mac <string>
- MAC address of display. Use only if you will need#wakeup
commandbroadcast <string>
- broadcast address of used network. Use only if you will need#wakeup
command on Windows
//for streamstream <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. LGDS object does not care about the stream. You have to maintain stream yourself (open, close, error handling).
OptionsObject <Object>
- optional, default is{encoding: 'ASCII', wDuration: 500, rDuration: 300, disconnect: true, splitter: {regex: /x$/}}
encoding <string>
- default 'ASCII'wDuration <number>
- default 500 ms. Inter-command period [ms] for set commands. A time for device to process command and to prepare and send a response.rDuration <number>
- default 300 ms. Inter-command period [ms] for read commands. A time for device 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 some ms. of connection inactivity.splitter <Object>
Used to select one among three supported transform streams which merge incoming data chunks and split it into valid messages. Only single property from delimiter, regex, timeout can be used. Default is{regex: /x$/}
delimiter <string>
- use@serialport/parser-delimiter
with string delimiterregex <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)
Method process(...commands)
Encode and send commands to device. You can use multiple commands in single call. Commands will be queued and executed FIFO.
Regular commands
Commands based on LG control protocol. Commands are strings in human friendly form command[?] [parameter]
.
Some examples:power off
- power off the displaybacklight 30
- set backlight to 30 (0-100)tilemode 2x3
- set tile mode (internal signal scaller)input?
- get active inputsn?
- get display serial number.
Not all protocol commands are supported. NOT supported are commands with multiple parameters or extended commands ('sn' commands).
All supported commands with their usage are listed in lgds.xml
file.
Internal commands
There are some internal commands which start with #
. They are not sent to device, but are processed by LGDS object itself.
#pause duration
- Append additional pause between neighboring commands as number of miliseconds.#wakeup [duration]
- Send WOL package to display. In tcp modepower on
command will not work. You have to use#wakeup [duration]
command insted. Default duration is 20000 ms.
Event: responseFromDevice
Emited when device response is properly decoded.
response <Object>
dev <string>
- device nameraw <Buffer>
- not decoded raw responsereq <string>
- request id, used to identify response value. In most cases it is just a command name which response is forstatus <string>
- decoded response status. OK|NG. NG status means that command parameter was incorrect or command couldn't be executed in current display statevalue <string|number|Object>
- decoded response value. Returned type depends on request id (command name). Seelgds.xml
Event: commandForDevice
Emited 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.
Event: connectionData
A data which comes directly from device port "as is". Not decoded, merged or chopped by splitter. Event is not emited in stream mode.
data <Buffer>
Event: connectionStatus
Emited when device connection status changes. Event is not emited in stream mode.
statusObj <Object>
dev <string>
- device nameaddress <string>
- device address as stringstatus <string>
- connection statusmore <string|Object>
- additional status information