Exemple #1
0
$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("COM1");
//
// // We can change the baud rate, parity, length, stop bits, flow control
// $serial->confBaudRate(2400);
// $serial->confParity("none");
// $serial->confCharacterLength(8);
// $serial->confStopBits(1);
// $serial->confFlowControl("none");
//
// or do either of these instead with the same result:
// $serial->confPort( "COM1", 2400, 8, 'none', 1, 'none' );
// $serial->confPort( "COM1", 2400 );
$serial->confPort("COM1", 2400, 8, 'none', 1, 'none');
// Then we need to open it
$serial->deviceOpen();
// To write into
$serial->sendMessage("Hello !\r\n");
// Or to read from
$read = "";
$read_length = $serial->readPort($read);
if ($read_length !== false && $read_length > 0) {
    print "received: {$read}\n";
}
// If you want to change the configuration, the device must be closed
$serial->deviceClose();
// We can change the baud rate
$serial->confBaudRate(2400);
// etc...
            } else {
                throw new RFID_BadKey_Exception("key doesn't pass basic regex checking. received key: {$key}");
            }
        } else {
            throw new RFID_BadKey_Exception("complete 16 bytes expected. received key: {$key}");
        }
    }
}
function errorhandler($errno, $errstr, $errfile, $errline)
{
    throw new Exception(basename($errfile) . '[' . $errline . '] (errno:' . $errno . ') -- ' . $errstr);
}
set_error_handler('errorhandler');
$s = new phpSerial();
try {
    if (!$s->confPort('/dev/ttyAMA0', 9600)) {
        throw new Exception("confPort() failed");
    }
    if (!$s->deviceOpen()) {
        throw new Exception("deviceOpen() failed");
    }
    if (!$s->confBlocking(false)) {
        throw new Exception("confBlocking() failed");
    }
} catch (Exception $e) {
    print "exception: {$e}\n";
    die;
}
$print_after_read = false;
$keystring = "";
do {