Possible thru serial connection?

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
 
That's a pretty sparse question but I think the answer is "yes".
 
Of course the hardware issuing the serial commands needs to be connected to something that can respond to said commands.
 
ok. So I hooked my laptop and got readings. However, I can't send any command. Is there something I need to enable in my M1 before I can start changing OUTPUTS? I mean, even if I tried to send a command, looks like M1 is ignoring it.
 
An example command I sent is
 
0Ecn0090000000D8 then I press Enter
 
This will turn output 9 to ON
 
When I check it on my keypad, it's still OFF
 
When you press enter, do you have things configured to send a CR/LF pair of characters?   It needs to send both for the M1 to recognize the message.  Often, terminal emulator software sends just one or the other.
 
[Edit]:
 
I think your checksum should be D1 rather than D8.  An incorrect checksum will also cause problems.
 
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.
 
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?
 
if in case someone in the future also needs it, they'll find it here. It might help me too if in case I lost my code in the future
 
Code:
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'));
 
Here is a new version. It pads zero if result is a single character
 
Code:
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.
 
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.
 
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?
 
 
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.
 
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.
 
You're very welcome! :)
 
drvnbysound said:
What physical connections are you using to do this?
 
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
 
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
 
DB-9 directly to the serial connection on the M1G board?
 
I'm using that port for the XEP. Any idea if what you are doing is possible via an XSP?
 
Back
Top