Here's a simple yet complete tutorial on how to set relays and get their status:
<?php
require_once('kit108.php');
$k=new Kit108('/dev/ttyS0');
if (!$k->isHealthy()) {
echo "Failed: ".$k->getErrors();
exit;
}
echo "Init successful!\n";
echo "Relays BEFORE toggling: ".$k->getRelays()."\n";
// Reset relays
$k->write("S0");
// Let's hear some clicking
echo "Status: ".$k->read()."\n";
echo "1-".$k->getRelays()."\n";
echo "2-".$k->setRelays(0)."\n";
echo "3-".$k->getRelays()."\n";
echo "4-".$k->sendOrder('RFF')."\n";
echo "5-".$k->getRelays()."\n";
echo "6-".$k->setRelays(0)."\n";
echo "7-".$k->getRelays()."\n";
echo "8-".$k->toggleRelay(1)."\n";
echo "9-".$k->getRelays()."\n";
echo "10-".$k->toggleRelay(1)."\n";
echo "11-".$k->getRelays()."\n";
echo "12-".$k->relayOn(0)."\n";
echo "13-".$k->getRelays()."\n";
echo "14-".$k->relayOff(0)."\n";
echo "15-".$k->getRelays()."\n";
echo "--\n";
echo "Errors:\n";
echo $k->getErrors();
?>
If all goes well, you should receive the following output:
Init successful! Relays BEFORE toggling: 00 Status: 00 1-00 2-1 3-00 4-1 5-FF 6-1 7-00 8-1 9-02 10-1 11-00 12-1 13-01 14-1 15-00 -- Errors:
All that's left out are the methods related to inputs, but you should be able to infer their usage by grafting the respective methods in the reference manual onto this sample.
On the other hand, if you specify the wrong serial port you might get the following output from the script above:
Failed: Wrong answer from device (previous command not returned)! This doesn't appear to be a Kit108 device (it doesn't return a proper version)!
Copyright © 2008 Bogdan Stancescu
All code available under GNU GPL v3 or later; all text/documentation available under GFDL v1.2 or later.