Ejemplo n.º 1
0
$cmdstr = substr($outstr, $lbracket + 1, $rbracket - $lbracket - 1);
// Let's start the class
$serial = new PhpSerial();
// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1, etc)
$serial->deviceSet("/dev/ttyAMA0");
// We can change the baud rate, parity, length, stop bits, flow control
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
// Then we need to open it
do {
    $serial->deviceOpen();
} while (!$serial->_ckOpened());
$serial->_exec("stty -F /dev/ttyAMA0 -isig", $out);
$serial->_exec("stty -F /dev/ttyAMA0 -icanon", $out);
// range of where to send
$destbegin = 0;
$destend = 3;
// for launch command map to a device and index, reformat message
$cmdcode = $cmdstr[0];
if ($cmdcode === 'L') {
    $cmdval = intval(substr($cmdstr, 1));
    $destend = $destbegin = (int) ($cmdval / 20);
    $outstr = "[L" . strval($cmdval % 20) . "]";
    $reqlen = strlen($outstr) + 14;
}
$response = "";
for ($d = $destbegin; $d <= $destend; $d++) {