Last active
August 23, 2017 10:46
-
-
Save gabonator/0c3280acd9df02609a0ceab8bc06164d to your computer and use it in GitHub Desktop.
Advantech adam ASCII modbus UDP emulator for synology surveillance station (nodejs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dgram = require('dgram'); | |
var server = dgram.createSocket('udp4'); | |
server.on('listening', function () { | |
var address = server.address(); | |
console.log('Advantech ADAM emulator running on UDP ' + address.address + ":" + address.port); | |
}); | |
server.on('message', function (message, remote) { | |
var request = message.toString(); | |
var response = ""; | |
if ( request.substr(0, 5) == "$01PW" ) | |
response = ">01\r"; | |
if ( request == "$01C\r" ) | |
response = "!01" + "000000000000" + "000000000000" + "000000000000" + "\r"; | |
else | |
if ( request.substr(0, 4) == "$01C" ) | |
response = ">\r"; | |
if ( request == "$016\r" ) | |
response = ((((new Date()).getTime()/1000) % 30) <= 5) ? | |
"!01"+"01"+"FFFF\r" : // address, outputs, inputs | |
"!01"+"00"+"FFFF\r"; | |
if ( request.substr(0, 4) == "#011" ) | |
{ | |
console.log("Channel[0x"+request.substr(4, 2)+"] = " +request.substr(6, 1)); | |
response = ">\r"; | |
} | |
if (response != "") | |
{ | |
server.send(new Buffer(response), 0, response.length, remote.port, remote.address, function(err) | |
{ | |
if (err) | |
console.log(err); | |
}); | |
} | |
console.log(remote.address + ": '" + | |
request.replace("\r", "") + "' -> '" + | |
response.replace("\r", "") + "'"); | |
}); | |
server.bind(1025); |
THX A LOT! This is exactly what i was looking 4!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any notes on how to use this? This could be really helpful if it could help other devices interface with SS. Thanks for the start.