v1rtu0s1ty
Senior Member
Am I right that we can issue a command using a terminal software and get a reading of a sensor or even turn on an output?
Thanks!
Neil
Thanks!
Neil
function generateChecksum(command) {
var sum = 0;
for (i = 0; i < command.length; i++) {
sum += command[i].charCodeAt();
};
sum = -(sum % 256) & 0xFF;
return sum.toString(16).toUpperCase()
}
console.log(generateChecksum('0Ecn0010001000'));
pad = function (str, max) {
str = str.toString();
return str.length < max ? pad("0" + str, max) : str;
}
function generateChecksum(command) {
var sum = 0;
for (i = 0; i < command.length; i++) {
sum += command[i].charCodeAt();
};
sum = -(sum % 256) & 0xFF;
return sum.toString(16).toUpperCase()
}
console.log(pad(generateChecksum('0Ecn0010001000'), 2));
v1rtu0s1ty said:I got it working by using \r\n at the end. This is what I wrote in textpad, 0Ecn0090000000D1\r\n, I also pressed Enter key on textpad then I highlighted the whole line. I pasted it on terminal and it turned on output 9. However, I tried sending the off command but it doesn't work. Maybe my checksum is also wrong
The command i tried to turn it off output 9 but failed is
09cf00900DC\r\n
By the way, I got those commands from year 2009 serial documentation of Elk M1.
v1rtu0s1ty said:I got it working perfectly now.
Now, I need to convert the python checksum calculator code into javascript. Can someone explain how the string we will send is calculated?
RAL said:The problem with the off command is also a bad checksum. Should be D5 by my calculation.
There is a newer version of the Elk RS232 document. The one I have is dated rev 1.81 dated August 8, 2011.
I'm glad you've got it working. I tried your javascript code and it does generate good checksums!
Thanks for sharing the code. I'm sure it will save someone else some time down the road.
drvnbysound said:What physical connections are you using to do this?
v1rtu0s1ty said:Just a regular usb to db-9 cable(my mac doesn't have 9-pin serial port). I had to install a usb-to-serial driver on my mac so that osx will create the device in /dev. The block device that gets created when I connect to my M1 is /dev/tty.usbserial