Exemple #1
1
// $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...
//
//
/* Notes from Jim :
> Also, one last thing that would be good to document, maybe in example.php:
>  The actual device to be opened caused me a lot of confusion, I was
> attempting to open a tty.* device on my system and was having no luck at
> all, until I found that I should actually be opening a cu.* device instead!
Exemple #2
0
<?php

include "php_serial.class.php";
// 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("COM1");
// Then we need to open it
$serial->deviceOpen();
// To write into
$serial->sendMessage("Hello !");
// Or to read from
$read = $serial->readPort();
// If you want to change the configuration, the device must be closed
$serial->deviceClose();
// We can change the baud rate
$serial->confBaudRate(2400);
// etc...
Exemple #3
0
$buff = '';
$cnt = 1;
$rcv = '';
if (isset($_GET["hi"])) {
    $data = $_GET["hi"];
    $serial = new phpSerial();
    $serial->deviceSet($comPort);
    $serial->confBaudRate(9600);
    $serial->confParity("none");
    $serial->confCharacterLength(8);
    $serial->confStopBits(1);
    $serial->deviceOpen();
    sleep(2);
    //Unfortunately this is nessesary, arduino requires a 2 second delay in order to receive the message
    $serial->sendMessage($data);
    $read[$cnt] = $serial->readPort();
    while (substr($read[$cnt], -1, 1) != "a") {
        $cnt++;
        $read[$cnt] = $serial->readPort();
    }
    for ($i = 1; $i < $cnt + 1; $i++) {
        $rcv = $rcv . $read[$i];
    }
    $rcv = rtrim($rcv, "a");
    $serial->deviceClose();
    $msg = "You message has been sent! WOHOO! Read data: " . $rcv . " And Last : " . $read[$cnt] . "";
}
?>

<html>
include "php_serial.class.php";
$serial = new phpSerial();
#$serial->deviceSet("/dev/ttyACM0");
$serial->deviceSet("/dev/ttyUSB0");
$serial->confBaudRate("9600");
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confFlowControl("none");
$serial->confStopBits(2);
$serial->deviceOpen();
sleep(3);
// Or to read from
$strAllLog = "";
while (true) {
    // $strLog = fgets( $handle ); # Read data from device
    $strLog = $serial->readPort();
    //echo $strLog;
    if ($strLog != "") {
        $strAllLog .= $strLog;
        sleep(5);
        continue;
    }
    if ($strAllLog != "") {
        $arrLog = explode("\n", $strAllLog);
        print_r($arrLog);
        foreach ($arrLog as $log) {
            logger2($log);
        }
    }
    $strAllLog = "";
}
Exemple #5
0
<?php

include "php_serial.class.php";
// 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)
// If you are using Windows, make sure you disable FIFO from the modem's
// Device Manager properties pane (Advanced >> Advanced Port Settings...)
$serial->deviceSet("/dev/ttyUSB1");
// Then we need to open it
$serial->deviceOpen('w+');
// We may need to return if nothing happens for 10 seconds
stream_set_timeout($serial->_dHandle, 10);
// We can change the baud rate
$serial->confBaudRate(9600);
// SMS inbox query - mode command and list command
$serial->sendMessage("AT\n\r", 1);
var_dump($serial->readPort());
$serial->sendMessage("AT+CMGF=1\n\r", 1);
var_dump($serial->readPort());
$serial->sendMessage("AT+CMGL=\"ALL\"\n\r", 2);
var_dump($serial->readPort());
// If you want to change the configuration, the device must be closed
$serial->deviceClose();
    if (!$s->confBlocking(false)) {
        throw new Exception("confBlocking() failed");
    }
} catch (Exception $e) {
    print "exception: {$e}\n";
    die;
}
$print_after_read = false;
$keystring = "";
do {
    $r = array($s->getFilehandle());
    $w = null;
    $e = null;
    $ready_count = stream_select($r, $w, $e, NULL);
    if ($ready_count !== false && $ready_count > 0) {
        $keylen = $s->readPort($keystring);
        if ($print_after_read) {
            print "readPort() returned {$keylen} bytes\n";
        }
        if (strlen($keystring) >= 16) {
            try {
                $key = new rfid_key($keystring);
                print "received valid rfid key: {$key}\n";
                $keystring = "";
                // consume the string after success
            } catch (Exception $e) {
                print "exception: {$e}\n";
            }
            // just in case parsing the key fails repeated we truncate
            // remove leading, useless data from time to time.
            if (strlen($keystring) >= 32) {
Exemple #7
0
<h1>Bonsai Life Support</h1>
<h2>Status:</h2>
<?php 
echo "Tank Level: ";
error_reporting(E_ALL);
ini_set('display_errors', '1');
include "php_serial.class.php";
$serial = new phpSerial();
$serial->deviceSet("/dev/ttyAMA0");
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->deviceOpen();
$serial->sendMessage("L");
$data = $serial->readPort();
echo $data;
echo " %";
echo "</br>";
echo "Soil Moisture: ";
$serial->sendMessage("M");
$data = $serial->readPort();
echo $data;
echo " %";
echo "</br>";
$serial->deviceClose();
if (!empty($_GET['waterPlant'])) {
    $serial->deviceOpen();
    $serial->sendMessage("W");
    $serial->deviceClose();
    echo "Plant Watered!</br>";
Exemple #8
0
     $serial->confStopBits(1);
     $serial->confFlowControl("none");
     // Then we need to open it
     $serial->deviceOpen();
     $odprto = true;
     $podatki;
     $cas = time();
     $minute = $cas + 1.5 * 60;
     $time = date('m-d-Y H:i:s', $cas);
     $finish_time = date('m-d-Y H:i:s', $minute);
     $tmp;
     $f = fopen("textfile.txt", "w", "a") or die("Unable to open file!");
     while ($time < $finish_time) {
         $time = date('m-d-Y H:i:s', time());
         //Pobiramo podatke iz serijskega porta
         $podatki = fwrite($f, $serial->readPort());
         $tmp = $tmp . $podatki;
     }
     $serial->deviceClose();
     fclose($f);
     echo '<script>alert("Podatki prebrani!")</script>';
     echo '<script>
                     var el = document.getElementById("result");
                     el.innerHTML = "' . $tmp . '"
                     </script>';
 } else {
     if (isset($_POST['gumb_start'])) {
         //                        if (substr(php_uname(), 0, 7) == "Windows"){
         //                        pclose(popen("start /B ". "serial.exe start", "r"));
         //                        }
         //                        else {
    }
}
if (!$SWITCHER_FOUND) {
    logEntry("switcher command not found: exiting");
    exit(0);
}
$cmd = explode(",", $SWITCHER_CMD);
//print_r($cmd);
$i = 0;
for ($i = 0; $i <= count($cmd); $i++) {
    $switcher_cmd .= chr($cmd[$i]);
}
$SWITCHER_CMD = $switcher_cmd;
logEntry("-------");
logEntry("Sending command");
logEntry("Switcher cmd: " . $SWITCHER_CMD);
logEntry("Sending SERIAL COMMAND");
logEntry("SERIAL DEVICE: " . $SERIAL_DEVICE);
$serial = new phpSerial();
$serial->deviceSet($SERIAL_DEVICE);
$serial->confBaudRate($SWITCHER_BAUD);
$serial->confParity($SWITCHER_PARITY);
//        $serial->confFlowControl("none");
$serial->confCharacterLength($SWITCHER_CHAR_BITS);
$serial->confStopBits($SWITCHER_STOP_BITS);
$serial->deviceOpen();
$serial->sendMessage($SWITCHER_CMD);
sleep(1);
logEntry("RETURN DATA: " . hex_dump($serial->readPort()));
logEntry("RETURN DATA: " . $serial->readPort());
$serial->deviceClose();
Exemple #10
0
#!/usr/bin/php
<?php 
include "lib/php_serial.class.php";
$s = new phpSerial();
$s->deviceSet("/dev/ttyUSB0");
$s->confBaudRate(9600);
$s->deviceOpen();
$s->sendMessage("Hello!");
$r = $s->readPort();
print $r;
$s->deviceClose();
Exemple #11
0
    if ($value != '') {
        if ($value == 'mdi') {
            $value = isset($_POST['mdi-code']) && $_POST['mdi-code'] != '' ? strtoupper($_POST['mdi-code']) : '';
        }
        if (strpos($value, 'G0') !== false) {
            $value .= ' F' . $feed;
        }
        $serial = new phpSerial();
        $serial->deviceSet(PORT_NAME);
        $serial->confBaudRate(BOUD_RATE);
        $serial->confParity("none");
        $serial->confCharacterLength(8);
        $serial->confStopBits(1);
        $serial->deviceOpen();
        $serial->sendMessage($value . "\r\n");
        $reply = $serial->readPort();
        $serial->deviceClose();
    }
    if (isset($_POST['s']) && $_POST['s'] == 1) {
        $raspi_still = true;
        exec('sudo raspistill -hf -w 512 -h 320 -o /var/www/temp/picture.jpg -t 1');
        $filename = "/var/www/temp/picture.jpg";
        $handle = fopen($filename, "rb");
        $contents = fread($handle, filesize($filename));
        fclose($handle);
    }
}
include 'header.php';
?>
	<style>
		.uppercase {