Skip to content

Instantly share code, notes, and snippets.

@deNULL
Created February 8, 2017 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deNULL/8406dcb976e8d1a5e3de333301f165f2 to your computer and use it in GitHub Desktop.
Save deNULL/8406dcb976e8d1a5e3de333301f165f2 to your computer and use it in GitHub Desktop.
defineVirtualDevice('rs485_c0135_64', {
title: 'Relay Board-4 64',
cells: {
K1: {
type: 'switch',
value: false
},
K2: {
type: 'switch',
value: false
},
K3: {
type: 'switch',
value: false
},
K4: {
type: 'switch',
value: false
}
}
});
function setup_port() {
runShellCommand('stty -F /dev/ttyAPP1 ospeed 9600 ispeed 9600 raw clocal -crtscts -echo cs8');
}
defineRule('_c0135_64_K1_switch_on', {
asSoonAs: function () {
return dev.rs485_c0135_64.K1;
},
then: function() {
runShellCommand("/usr/bin/printf '\\x64\\x05\\x00\\x01\\x01\\x00\\x94\\x6f' > /dev/ttyAPP1");
}
});
defineRule('_c0135_64_K1_switch_off', {
asSoonAs: function () {
return !dev.rs485_c0135_64.K1;
},
then: function() {
runShellCommand("/usr/bin/printf '\\x64\\x05\\x00\\x01\\x00\\x00\\x95\\xff' >/dev/ttyAPP1");
}
});
defineRule('_c0135_64_K2_switch_on', {
asSoonAs: function () {
return dev.rs485_c0135_64.K2;
},
then: function() {
runShellCommand("/usr/bin/printf '\\x64\\x05\\x00\\x02\\x01\\x00\\x64\\x6f' > /dev/ttyAPP1");
}
});
defineRule('_c0135_64_K2_switch_off', {
asSoonAs: function () {
return !dev.rs485_c0135_64.K2;
},
then: function() {
runShellCommand("/usr/bin/printf '\\x64\\x05\\x00\\x02\\x00\\x00\\x65\\xff' >/dev/ttyAPP1");
}
});
defineRule('_c0135_64_K3_switch_on', {
asSoonAs: function () {
return dev.rs485_c0135_64.K3;
},
then: function() {
runShellCommand("/usr/bin/printf '\\x64\\x05\\x00\\x03\\x01\\x00\\x35\\xaf' > /dev/ttyAPP1");
}
});
defineRule('_c0135_64_K3_switch_off', {
asSoonAs: function () {
return !dev.rs485_c0135_64.K3;
},
then: function() {
runShellCommand("/usr/bin/printf '\\x64\\x05\\x00\\x03\\x00\\x00\\x34\\x3f' >/dev/ttyAPP1");
}
});
defineRule('_c0135_64_K4_switch_on', {
asSoonAs: function () {
return dev.rs485_c0135_64.K4;
},
then: function() {
runShellCommand("/usr/bin/printf '\\x64\\x05\\x00\\x04\\x01\\x00\\x84\\x6e' > /dev/ttyAPP1");
}
});
defineRule('_c0135_64_K4_switch_off', {
asSoonAs: function () {
return !dev.rs485_c0135_64.K4;
},
then: function() {
runShellCommand("/usr/bin/printf '\\x64\\x05\\x00\\x04\\x00\\x00\\x85\\xfe' >/dev/ttyAPP1");
}
});
setTimeout(setup_port, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment