denon-avr
v0.0.5
Published
Module for two way communication with Denon AVRs
Downloads
10
Maintainers
Readme
Denon Remote control
Denon AVR remote control via RS232 or IP (Telnet) supporting two way communication.
Installation
npm install denon-avr
RS232 Interface
This is currently a work in progress. See issue #1
I accept no responsibility for any damage done to your computer or equipment.
Usage
Via Telnet
The telnet transport needs to be passed onto the denon-avr module.
Example
var denon = require('denon-avr');
var avr = new denon(new denon.transports.telnet({
host: '', // IP address or hostname
debug: true // Debug enabled
}));
avr.on('connect', function() {
// now connected
// all commands to be placed here
});
Via RS232
TODO
Example
var denon = require('denon-avr');
Methods
A number of examples can be found within the examples directory.
General
connect()
Connect via the provided transport.
Note, this method provides no callback, please see the 'connect' event.
Example
avr.connect();
send(command, prefix, callback, error)
Generic send via provided transport aimed to reduce code duplication throughout the library.
Arguments
command
- String to be sent via the provided transportprefix
- The expected response prefix either as a string (eg. 'MV) or a RegExp instancecallback(err, response)
- Callback function for error/response handlingerror
- Error string provided to the callback
Example
The below example would return the power state of the AVR.
avr.send('PW?', 'PW', function(err, state) {
if (err) {
console.log(err);
return;
}
console.log('The current power state is:', state);
}, 'Unable to get the power state');
parseData(data)
Parse the data received from an event on the AVR.
TODO
See issue #5
Arguments
data
- ??
Example
avr.parseData(data);
parseResponse(data, prefix, callback, error);
Parse the response provided when sending a command, another simple method to reduce code duplication throughout the library, ideally this shouldn't be used outside of the library.
Arguments
data
- String received from the AVRprefix
- The expected response prefix either as a string (eg. 'MV) or a RegExp instancecallback(err, response)
- Callback function for error/response handlingerror
- Error string provided to the callback
Example
The below example would return the power state of the AVR.
var callback = function(err, state) {
if (err) {
console.log(err);
return;
}
console.log('The current power state is:', state);
}
avr.transport.send('PW?', function(err, response) {
if (err) {
callback(err);
return;
}
avr.parseResponse(response, prefix, callback, error);
});
getTransport()
Get the transport object provided when creating the module.
Example
var transport = avr.getTransport();
getConnection()
Get the connection created by the transport.
Example
var connection = avr.getConnection();
parseAsciiVolume(volume, zero)
Parse the volume provided in ASCII format to dB as per the Denon documentation.
For example the master volume would be returned in ASCII as followed:
|ASCII Value|dB Value| |-----------|--------| |80|0dB| |995|-80.5dB|
Arguments
volume
- ASCII value (eg 995 or 99)zero
- Optional value to calculate the zero position. Defaults to 80 to support master volume, provide 50 if dealing with channel volumes
Example
var volume = '995';
console.log(avr.parseAsciiVolume(volume));
// output: -80.5
parseDbVolume(volume, zero)
Parse a dB volume into ASCII format for sending back to the AVR.
Arguments
volume
- Numeric value containing the volume in dB (eg -80.5)zero
- Optional value to calculate the zero position. Defaults to 80 to support master volume, provide 50 if dealing with channel volumes
Example
var volume = -60.5;
console.log(avr.parseDbVolume(volume));
// output: 195
AVR Specific
These are methods aimed at controlling or querying the AVRs specific functions.
All examples below assume a connection has been created to the AVR as per the examples within usage.
setPowerState(state, callback)
Set the power state of the AVR.
Note, that if you try to set the same state the AVR is currently, no response is returned.
Arguments
state
- bool, true to power on, false to power ofcallback(err, volume)
- Callback on completion,volume
to contain ASCII volume level
Example
Power on the AVR.
avr.setPowerState(true, function(err, state) {
if(err) {
console.log(err);
return;
}
console.log('The power state is now:', state);
});
getPowerState(callback)
Get the current power state.
Arguments
callback(err, state)
- Callback on completion,state
to contain either ON/OFF
Example
avr.getPowerState(function(err, state) {
if(err) {
console.log(err);
return;
}
console.log('The power state is:', state);
});
setVolumeUp(callback)
Increase the master zone volume by 0.5dB.
Arguments
callback(err, volume)
- Callback on completion,volume
to provide master zone volume in ASCII format
Example
avr.setVolumeUp(function(err, volume) {
if (err) {
console.log(err.toString());
return;
}
console.log('The volume is now', volume, '/', avr.parseAsciiVolume(volume), 'dB');
});
setVolumeDown(callback)
Decrease the master zone volume by 0.5dB.
Arguments
callback(err, volume)
- Callback on completion,volume
to provide master zone volume in ASCII format
Example
avr.setVolumeDown(function(err, volume) {
if (err) {
console.log(err.toString());
return;
}
console.log('The volume is now', volume, '/', avr.parseAsciiVolume(volume), 'dB');
});
setVolumeAscii(volume, callback)
Set the master zone volume level using ASCII an value.
Arguments
volume
- Volume in ASCII formatcallback(err, volume)
- Callback on completion,volume
to provide master zone volume in ASCII format
Example
Set the volume to -80.0dB
avr.setVolumeAscii('00', function(err, volume) {
if (err) {
console.log(err.toString());
return;
}
console.log('The volume is now', volume, '/', avr.parseAsciiVolume(volume), 'dB');
});
setVolumeDb(volume, callback)
Set the master zone volume level using dB values.
Arguments
volume
- Volume in ASCII formatcallback(err, volume)
- Callback on completion,volume
to provide master zone volume in ASCII format
Example
Set the volume to -80.5dB
avr.setVolumeDb(-80.5, function(err, volume) {
if (err) {
console.log(err.toString());
return;
}
console.log('The volume is now', volume, '/', avr.parseAsciiVolume(volume), 'dB');
});
getVolumeLevel(callback)
Get the master zone volume level.
Arguments
callback(err, volume)
- Callback on completion,volume
to provide master zone volume in ASCII format
Example
avr.setVolumeAscii(function(err, volume) {
if (err) {
console.log(err.toString());
return;
}
console.log('The volume is', volume, '/', avr.parseAsciiVolume(volume), 'dB');
});
setMute(state, callback)
Set the master zone mute state.
Note, the callback may provide an error if you attempt to set the state to the current mute state.
Arguments
state
- bool to enable or disable mute statecallback(err, state)
- Callback on completion,state
to provide new mute state as ON/OFF
Example
Enable mute
avr.setMute(true, function(err, state) {
if (err) {
console.log(err.toString());
return;
}
console.log('The current mute state is', state);
});
getMuteState(callback)
Get the master volume mute state
Arguments
callback(err, state)
- Callback on completion,state
to provide mute state as ON/OFF
Example
Enable mute
avr.getMuteState(true, function(err, state) {
if (err) {
console.log(err.toString());
return;
}
console.log('The current mute state is', state);
});
getSource(callback)
Get the current master zone source.
Results returned directly from AVR in the following format:
- PHONO
- CD
- TUNER
- DVD
- BD
- TV
- SAT/CBL
- DVR
- GAME
- V.AUX
- DOCK
- HDRADIO (AVR-3311-CI model Only)
- IPOD
- NET/USB
- FLICKR
- FAVORITES
- IRADIO
- SERVER
- USB/IPOD
Arguments
callback(err, source)
- Callback on completion,source
to provide source name as above
Example
avr.getSource(function(err, source) {
if (err) {
console.log(err.toString());
return;
}
console.log('The current source is', source);
});
Events
TODO
See issue #5 ...
Notes
This has been written for control of my AVR 3311, assuming the commands should be the same between models.
The full breakdown of the API provided by Denon can be found at http://www.awe-europe.com/documents/Control%20Docs/Denon/Archive/AVR3311CI_AVR3311_991_PROTOCOL_V7.1.0.pdf