I want to Read the current time from the controller but Im not sure how to properly convert it to the actual time.
For example:
I sent the Following API bytes to the controller:
170 2 65 99 80
I recieved:
170 8 50 3 22 24 18 3 24 144 210
How do I convert the 7 time bytes 50 3 22 24 18 3 24
and the checksum 144 to compare the controller’s time with time.nist.gov?
My goal is to write code to update the taralist controllers every few hours from time.nist.gov to be sure all break buzzers go off at the same time in our plant. Several single relay taralist controllers with xport modules will be on the network with a single app running on a server, monitoring time.
Parsing isnt the real issue for me. Looking at Ryans code for Base I am able to send API commands to the controller and parse the response and control relays. However, if its 405pm and you ask the controller what time its got and it returns 50 3 22 24 18 3 24 , im like what?? LoL
The source for Base doesnt actually convert the 7 bytes from the controller…it just receives it and displays it
I think this is what you’re looking for, run each byte through this (I wrote it in javascript because it’s easy)
function BCD(v){
//divide byte value by 16 and round down
var a = Math.floor(v/16);
//grab the remainder (modulus)
var mod = v%16;
//Convert to integer
return a * 10 + mod;
}
the byte order is: second, minute, hour, day of month, month, day of week, year
After a 2 month long Hiatus from this project I am jumping back into it.
Your Code Helped me calculate the bytes coming from the controller…but what is the proper calculation to take time from the system clock and send back to the controller in the form of 7 bytes+checksum as described in the command set for the Taralist relay?
It should be the inverse, so run your real world values through this:
function DCB(v){
var a = Math.floor(v/10);
var mod = v%10;
return a * 16 + mod;
}
The checksum calculation is pretty simple, just add all of the resulting bytes together and perform a bitwise AND (&) with 255:
function build_payload(bytes){
var sum = 0;
for(var i = 0;i<bytes.length;i++){
sum += bytes[i];
}
bytes.push(sum & 255);
return bytes;
}
Bear in mind that I haven’t tested this, I don’t actually have a Taralist board at my desk (and I didn’t build the API), so there may be a need to look at the source code for base station above if you run into problems, but I’m fairly confident this should work.