Esempio n. 1
1
 public function getSerial()
 {
     if (!isset(self::$_serial)) {
         $this->displayDebug('Création de l\'interface série sur le port : ' . $this->getConfiguration('port'));
         $serial = new phpSerial();
         $serial->deviceSet($this->getConfiguration('port'));
         $serial->confBaudRate(9600);
         $serial->confParity('none');
         $serial->confStopBits(1);
         $serial->confCharacterLength(8);
         $serial->confFlowControl('none');
         $serial->sendParameters("-ignbrk -hupcl -onlcr -echo -echok -echoctl -echoke");
         $serial->setValidOutputs(array('OK', 'ERROR', '+CPIN: SIM PIN', '+CPIN: READY', '>', 'COMMAND NOT SUPPORT', '+CMS ERROR: 305'));
         self::$_serial = $serial;
         $this->cleanDevice();
     }
     return self::$_serial;
 }
Esempio n. 2
0
function sendCommand($n)
{
    $serial = new phpSerial();
    $serial->deviceSet("/dev/ttyUSB0");
    $serial->confBaudRate(9600);
    $serial->confParity("none");
    $serial->confCharacterLength(8);
    $serial->confStopBits(1);
    $serial->confFlowControl("none");
    $serial->deviceOpen();
    $serial->sendMessage($n);
    // $read = $serial->readPort();
    $serial->deviceClose();
}
Esempio n. 3
0
function setupSerial($device)
{
    $serial = new phpSerial();
    $serial->deviceSet($device);
    $serial->confBaudRate(9600);
    //Baud rate: 9600
    $serial->confParity("none");
    //Parity (this is the "N" in "8-N-1")
    $serial->confCharacterLength(8);
    //Character length     (this is the "8" in "8-N-1")
    $serial->confStopBits(1);
    //Stop bits (this is the "1" in "8-N-1")
    $serial->confFlowControl("none");
    $serial->deviceOpen();
    return $serial;
}
Esempio n. 4
0
 function init()
 {
     $this->port = $serial = new phpSerial();
     $p = DylosReaderConf::$serialPort;
     $this->log("Opening {$p}");
     $serial->deviceSet($p);
     $serial->confBaudRate(9600);
     $serial->confParity("none");
     $serial->confCharacterLength(8);
     $serial->confStopBits(1);
     $serial->confFlowControl("none");
     // Then we need to open it
     $serial->deviceOpen();
 }
Esempio n. 5
0
 function MySensorMasterCom($device)
 {
     $serial = new phpSerial();
     $serial->deviceSet($device);
     $serial->confBaudRate(115200);
     $serial->confCharacterLength(8);
     $serial->confParity("none");
     $serial->confStopBits(1);
     $serial->confFlowControl("none");
     $this->Serial = $serial;
 }
Esempio n. 6
0
 /**
  *
  *
  * @param string comando
  * @return
  * @access public
  */
 public function enviarComando($comando)
 {
     $serial = phpSerial::getInstance();
     $serial->escribirPuerto($comando);
 }
Esempio n. 7
0
<?php

include "php_serial.class.php";
session_start();
/*session is started if you don't write this line can't use $_Session  global variable*/
$_SESSION["newsession"] = $value;
// 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");
// 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");
// Then we need to open it
$serial->deviceOpen();
// To write into
$serial->sendMessage($value);
// 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...
//
//
/* Notes from Jim :
Esempio n. 8
0
<?php

include "php_serial.class.php";
$codigo = $_REQUEST["codigo"];
// 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("COM67");
$serial->confBaudRate(9600);
// Then we need to open it
$serial->deviceOpen();
// To write into
$serial->sendMessage("n" . $codigo);
// 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
// etc...
Esempio n. 9
0
We then echo back the result received, and present the form again for additional input changes.
*/
function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return (double) $usec + (double) $sec;
}
$the_input = $_POST['the_input'];
if ($the_input == '') {
    echo "<div id='newrequestbox'>";
    echo "<form id='FormName' name='FormName' action='example_VS421CPNTA.php' method='post'>\n\t\t\t<table width=500>\n\t\t\t\t<tr>\n\t\t\t\t\t<td>Switch to input? :</td>\n\t\t\t\t\t<td><input type=text name=the_input  maxlength=30 size=30></td>\n\t\t\t\t\t<td><input type=submit value='Switch'></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t</form>";
    echo "</div>";
} else {
    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");
    $serial->deviceSet("/dev/cu.usbserial-FTDY7ID6");
    // 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");
    // Then we need to open it
    $serial->deviceOpen();
    // To write into
    $serial->sendMessage("I" . $the_input);
    // Or to read from
Esempio n. 10
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();
Esempio n. 11
0
 public static function getInstance()
 {
     if (!self::$instancia instanceof self) {
         self::$instancia = new self();
     }
     return self::$instancia;
 }
Esempio n. 12
0
function rdssend($songName, $artistName, $datePassed)
{
    // The shared memory segment you stored the date in
    $segment_id = 881;
    // You have to attach to the shared memory segment first
    $shm = shm_attach($segment_id, PHP_INT_SIZE, 0600);
    // Then get the date currently stored in the shared memory segment
    $dateStored = shm_get_var($shm, 1);
    // Everytime the RDS sender script gets called the Logbook updates the
    // time saved in the shared memory so we know if we should leave this script
    if ($datePassed != $dateStored) {
        // Detach the shared memory segment and exit
        shm_detach($shm);
    }
    // Declare the new Com port
    $COM = new phpSerial();
    // Set the serial device "/dev/ttyS0" for linux, "COM1" for windows
    if (substr(PHP_OS, 0, 3) == 'WIN') {
        $COM->deviceSet("COM1");
    } else {
        $COM->deviceSet("/dev/ttyS0");
    }
    /*	I suppose PHP doesn't have permissions to execute the mode command, but it's
    	fine because we are using the defaults anyway
    	// Set the baud rate, parity, length, stop bits, flow control
    	$COM->confBaudRate(9600);
    	$COM->confParity("none");
    	$COM->confCharacterLength(8);
    	$COM->confStopBits(1);
    	$COM->confFlowControl("none");
    */
    // Remove the bad words and make it all uppercase
    $artistName = censor($artistName);
    $songName = censor($songName);
    // if your song name is the password, we'll keep on sending until Now Playing gets updated
    if ($songName == PASSWORD) {
        // See how long the string is so we can see if we need to shorten it
        $artistNameLength = strlen($artistName);
        // if the string is longer than the DPS_MAX, get rid of the " THE "s
        if ($artistNameLength > DPS_MAX) {
            $artistName = str_replace(" THE ", " ", $artistName);
            $artistNameLength = strlen($artistName);
        }
        // if it's still too long, just cut it down to size.
        if ($artistNameLength > DPS_MAX) {
            $artistName = substr($artistName, 0, DPS_MAX);
            $artistNameLength = strlen($artistName);
        }
        // Make the DPS output
        // The Inovonics 730 requires a carriage return at the end of every string
        $dpsOut = "DPS=" . $artistName . chr(13);
        // if the string is longer than the TEXT_MAX, get rid of the " THE "s.
        if ($artistNameLength > TEXT_MAX) {
            $artistName = str_replace(" THE ", " ", $artistName);
            $artistNameLength = strlen($artistName);
        }
        // if it's still too long, just cut it down to size.
        if ($artistNameLength > TEXT_MAX) {
            $artistName = substr($artistName, 0, TEXT_MAX);
        }
        // Make the RT output
        $rtOut = "TEXT=" . $artistName . chr(13);
        // Get the date stored again to see if it's been updated
        $dateStored = shm_get_var($shm, 1);
        // if the stored date hasn't changed, send the output every three minutes
        while ($datePassed == $dateStored) {
            // Open the COM port
            $COM->deviceOpen();
            // Send the strings
            $COM->sendMessage($dpsOut);
            $COM->sendMessage($rtOut);
            // Close the port when you're done
            $COM->deviceClose();
            sleep(180);
            // Grab the stored date again
            $dateStored = shm_get_var($shm, 1);
        }
        // Detach from the shared memory segment
        shm_detach($shm);
        $fs = fopen('test_output.txt', 'w');
        fwrite($fs, $dpsOut);
        fwrite($fs, $rtOut);
        fclose($fs);
    } elseif ($songName == "LIVE SESSION" || $songName == "LIVE SESSIONS") {
        $dpsOut = "LIVE SESSION WITH " . $artistName . " ON " . STATION_NAME;
        $dpsLen = strlen($dpsOut);
        $rtOut = $artistName . " LIVE ON " . STATION_NAME;
        $rtLen = strlen($rtOut);
        $stationLen = strlen(STATION_NAME) - 1;
        // if it's too long we'll drop the station name
        if ($dpsLen > DPS_MAX) {
            $dpsOut = "LIVE SESSION WITH " . $artistName;
            $dpsLen = strlen($dpsOut);
        }
        // if it's still too long then we'll drop the " THE "s.
        if ($dpsLen > DPS_MAX) {
            $dpsOut = str_replace(" THE ", " ", $dpsOut);
            $dpsLen = strlen($dpsOut);
        }
        // And if it's still too long, we'll just cut it short
        if ($dpsLen > DPS_MAX) {
            $dpsOut = substr($dpsOut, 0, DPS_MAX);
        }
        // Put it in the format the Inovonics 730 likes
        $dpsOut = "DPS=" . $dpsOut . chr(13);
        // Now for the Radio Text, except to make it fun, we need to know
        // the length of the artist name when we go back to calculate the RT+
        // if it's too long drop the " THE "s.
        if ($rtLen > TEXT_MAX) {
            $artistName = str_replace(" THE ", " ", $artistName);
            $rtOut = $artistName . " LIVE ON " . STATION_NAME;
            $rtLen = strlen($rtOut);
        }
        // if it's still too long we cut the artist name down to size
        if ($rtLen > TEXT_MAX) {
            // The longest the artist name can be is the TEXT_MAX length,
            // minus the length of the STATION_NAME, plus the 9 characters
            // for " LIVE ON " plus 1 because station len is the length minus 1
            $artMax = TEXT_MAX - ($stationLen + 10);
            $artistName = substr($artistName, 0, $artMax);
            $rtOut = $artistName . " LIVE ON " . STATION_NAME;
        }
        // Format the output for the Inovonics 730
        $rtOut = "TEXT=" . $rtOut . chr(13);
        // Let's calculate some RT+
        // The count starts at zero
        $artistNameLength = strlen($artistName) - 1;
        // This will give the starting position of STATION_NAME
        $stationStart = $artistNameLength + 10;
        // This makes it so they are all two digits
        $artistNameLength = str_pad($artistNameLength, 2, "0", STR_PAD_LEFT);
        $stationLen = str_pad($stationLen, 2, "0", STR_PAD_LEFT);
        $stationStart = str_pad($stationStart, 2, "0", STR_PAD_LEFT);
        // Type,Starting Position,Length, Type,Starting Position,Length
        $rtpOut = "RTP=04,00," . $artistNameLength . ",31," . $stationStart . "," . $stationLen . chr(13);
        // Grab the date currently stored in memory
        $dateStored = shm_get_var($shm, 1);
        // if it is still the same as the date passed in, send it every three minutes until it no longer is
        while ($datePassed == $dateStored) {
            // Open the COM port
            $COM->deviceOpen();
            // Send the strings
            $COM->sendMessage($dpsOut);
            $COM->sendMessage($rtOut);
            $COM->sendMessage($rtpOut);
            // Close the port when you're done
            $COM->deviceClose();
            sleep(180);
            // Check the date again
            $dateStored = shm_get_var($shm, 1);
        }
        // Detach from the shared memory and exit
        shm_detach($shm);
        $fs = fopen('test_output.txt', 'w');
        fwrite($fs, $dpsOut);
        fwrite($fs, $rtOut);
        fwrite($fs, $rtpOut);
        fclose($fs);
    } else {
        // Call the trim function to cut them down to size for DPS and make the right string
        list($songName, $artistName) = shorten($songName, $artistName, DPS_MAX);
        $dpsOut = "DPS=" . $songName . " BY " . $artistName . " ON " . STATION_NAME . chr(13);
        // Call the trim function to cut them down to size for RT and make the string
        list($songName, $artistName) = shorten($songName, $artistName, TEXT_MAX);
        $rtOut = "TEXT=" . $songName . " BY " . $artistName . chr(13);
        // Start calculating the RT+ value
        $artistNameLength = strlen($artistName) - 1;
        $songNameLength = strlen($songName) - 1;
        // The starting value of the artist name is the length of the song name, plus 4 for " BY "
        // and plus one because the length of the song name is one less than it actually is
        $artistStart = $songNameLength + 5;
        // Make it so that they are two digit numbers
        $artistNameLength = str_pad($artistNameLength, 2, "0", STR_PAD_LEFT);
        $songNameLength = str_pad($songNameLength, 2, "0", STR_PAD_LEFT);
        $artistStart = str_pad($artistStart, 2, "0", STR_PAD_LEFT);
        // Make the RT+ output with the right format
        $rtpOut = "RTP=01,00," . $songNameLength . ",04," . $artistStart . "," . $artistNameLength . chr(13);
        // Get the stored date from the shared memory segment
        $dateStored = shm_get_var($shm, 1);
        // if the passed date is the same as the stored date, go ahead and send it
        if ($dateStored == $datePassed) {
            // Open the COM port
            $COM->deviceOpen();
            // Send the DPS String
            $COM->sendMessage($dpsOut);
            $COM->sendMessage($rtOut);
            $COM->sendMessage($rtpOut);
            // Close the port when you're done
            $COM->deviceClose();
        }
        // Detach the shared memory segment and exit
        shm_detach($shm);
        $fs = fopen('test_output.txt', 'w');
        fwrite($fs, $dpsOut);
        fwrite($fs, $rtOut);
        fwrite($fs, $rtpOut);
        fclose($fs);
    }
}
Esempio n. 13
0
        $com = "GET {$file} HTTP/1.1\r\nAccept: */*\r\nAccept-Language: de-ch\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\nHost: {$server}:{$port}\r\nConnection: Keep-Alive\r\n\r\n";
        fputs($fp, $com);
        /* Don't realy need to fetch output as it slows us down
               while (!feof($fp))
               {
                   $cont .= fread($fp, 500);
               }
        */
        fclose($fp);
        //       $cont = substr($cont, strpos($cont, "\r\n\r\n") + 4);
        //       return $cont;
    }
}
include "php_serial.class.php";
// Let's start the class
$serial = new phpSerial();
$serial->deviceSet("/dev/ttyAMA0");
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
// We may need to return if nothing happens for 10 seconds
//stream_set_timeout($serial->_dHandle, 10);
// Then we need to open it
//$serial->deviceOpen();
//$serial->sendMessage("210g");
//$serial->sendMessage("7i");
//$serial->sendMessage("8b");
echo "Started..\r\n";
while (1) {
Esempio n. 14
0
<?php

include "php_serial.class.php";
//
// Let's start the class
//
$serial = new phpSerial();
//
// First we must specify the device.
// Comm settings assumed correct or use Mode to correct
//
$serial->deviceSet("COM1");
//
// Then we need to open it
//
$serial->deviceOpen("w+");
// All relays off
//$serial->sendMessage(sprintf("#050000%c",13),0);
$serial->sendMessage(sprintf("#050000\r\n"), 0);
usleep(200000);
//
// If you want to change the configuration, the device must be closed
//
$serial->deviceClose();
//
                    throw new RFID_BadKey_Exception("bad checksum for received key: {$frmtkey}");
                }
            } 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;
Esempio n. 16
0
<?php

include "php_serial.php";
ini_set('display_errors', 'On');
error_reporting(E_ALL);
// 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("COM5");
// 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", 1);
var_dump($serial->readPort());
$serial->sendMessage("AT+CMGF=1\n\r", 1);
var_dump($serial->readPort());
$serial->sendMessage("AT+CMGL=\"0754111222\"\n\r", 2);
var_dump($serial->readPort());
// If you want to change the configuration, the device must be closed
$serial->deviceClose();
Esempio n. 17
0
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
</head>
<body>
<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();
Esempio n. 18
0
<?php 
ini_set('display_errors', '1');
error_reporting(E_ALL);
include "PhpSerial.php";
$comPort = "/dev/ttyACM0";
//The com port address. This is a debian address
$msg = '';
$data = '';
$read = array();
$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++) {
Esempio n. 19
0
<?php

if (isset($_GET['action'])) {
    require_once 'php_serial.class.php';
    $action = $_GET['action'];
    $msec = isset($_GET['msec']) ? $_GET['msec'] : 500000;
    $times = isset($_GET['times']) ? $_GET['times'] : 5;
    $serial = new phpSerial();
    $serial->deviceSet('/dev/ttyUSB0');
    $serial->confBaudRate(9600);
    $serial->deviceOpen();
    $actions = array('on' => 1, 'off' => 0);
    if (in_array($action, array_keys($actions))) {
        $serial->sendMessage($actions[$action]);
    }
    if ($action == 'blink') {
        for ($i = 1; $i <= $times * 2; $i++) {
            $_action = $i % 2 ? 'on' : 'off';
            $serial->sendMessage($actions[$_action]);
            usleep($msec);
        }
    }
    $serial->deviceClose();
}
?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>Arduino LED control</title>
</head>
<?php

require "php_serial.class.php";
$serial = new phpSerial();
$serial->deviceSet("/dev/ttyUSB0");
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
$serial->deviceOpen();
$serial->sendMessage("1\r\n");
$file = fopen("testFile.txt", "w");
fwrite($file, "1");
fclose($file);
$serial->deviceClose();
//tachitita roda dexia
$DIYrodar = '080';
//GLOBAL tachitita gia a kai d
$DIYrodarotation = "050";
//GLOBAL tachitita gia stop
$DIYrodastop = "050";
// ************************************************
// ***************** include **********************
// ************************************************
// vriski tin thessi tou auto
require_once "/root/phpscripts/position.php";
// ************************************************
// ***************** fopen **********************
// ************************************************
//fopen motor write
$serial = new phpSerial();
$serial->deviceSet($DIYmotors);
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
// fopen for write data cloud
if (!($DIYpipecloud = fopen("/root/arduinocloud", "r+"))) {
    echo "Cannot link with sonar, wrong usb connected";
    exit;
}
// fopen for read sonar data
if (!($sensors = fopen("/dev/ttysonar", "r"))) {
    echo "Cannot link with sonar, wrong usb connected";
    exit;
Esempio n. 22
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");
//
// // 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
Esempio n. 23
0
              result.innerHTML = event.target.result;
            };

            reader.readAsText(selectedFile);
          }
            
        </script>
    </head>
    <body>
        <h1>Branje podatkov</h1>
        <?php 
include "php_serial.php";
include 'check_active_comm_port.class.php';
ini_set('max_execution_time', 300);
// Let's start the class
$serial = new phpSerial();
$odprto = false;
//Get the port and baud rate
$com = new windows_comm_port();
$comm_list = $com->comm_list();
$baud_list = $com->baud_list();
$count = count($comm_list);
$count2 = count($baud_list);
$data;
echo '<iframe name="frame" style="display:none;"></iframe>';
echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post" target="frame">
	Port <select name="comm">';
for ($i = 0; $i < $count; $i++) {
    echo '<option value="' . $comm_list[$i] . '">' . $comm_list[$i] . '</option>';
}
echo '</select> Baud Rate <select name="baud">';
Esempio n. 24
0
//GLOBAL tachitita gia w kai s
//tachitita roda aristeri
$DIYrodal = '080';
//tachitita roda dexia
$DIYrodar = '083';
//80
//GLOBAL tachitita gia a kai d
$DIYrodarotation = "060";
//GLOBAL tachitita gia stop
$DIYrodastop = "060";
//Lock gia to serial
$DIYlocked = 0;
require_once "/root/dimitris/functions.php";
require_once "/root/dimitris/position.php";
//fopen motor write
$serial = new phpSerial();
$serial->deviceSet($DIYmotors);
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
/*$exec='@w'.$rodal.':'.$rodar.'#';
        $serial->deviceOpen();
        $serial->sendMessage("@w080:080#");
        $serial->deviceClose();
     sleep(5);
     echo"TELEIWSE H FORWARD";
stop();
echo"TELEIWSE TO STOP";
sleep(5);     
*
*  This libraries are distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/

<?php 
define("PORT", "/dev/ttymxc3");
if (isset($_GET['action'])) {
    include "php_serial.class.php";
    $serial = new phpSerial();
    $serial->deviceSet(PORT);
    $serial->confBaudRate(115200);
    $serial->confParity("none");
    $serial->confStopBits(1);
    $serial->confFlowControl("none");
    $serial->deviceOpen();
    if ($_GET['action'] == "on") {
        $serial->sendMessage(chr(13) . chr(1));
    } else {
        if ($_GET['action'] == "off") {
            $serial->sendMessage(chr(13) . chr(0));
        }
    }
    $read = $serial->readPort();
    print $read;
Esempio n. 26
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...
Esempio n. 27
0
<?php

include "php_serial.class.php";
include "common.php";
$command = "";
$cmd = $_GET["cmd"];
if ($cmd != "" && array_key_exists($cmd, $gCommands)) {
    $command = $gCommands[$cmd];
} else {
    echo "error";
    return;
}
$serial = new phpSerial();
$serial->deviceSet("/dev/ttyACM0");
$serial->confBaudRate(115200);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
$serial->deviceOpen();
sleep(1);
for ($i = 0; $i < strlen($command); $i++) {
    $serial->sendMessage($command[$i]);
}
$serial->deviceClose();
header('Refresh: 1; URL=/');
echo "Done " . $command;
Esempio n. 28
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("COM2");
// 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(9600);
// etc...
Esempio n. 29
0
    // $newLog = "$today|$logEvent";
    $allLog = file_get_contents($logfilename);
    $newLog = "{$today}|" . hash("md5", $allLog) . "|{$logEvent}\n";
    file_put_contents($logfilename, $newLog, FILE_APPEND);
    echo $logEvent;
}
//
// main
//
// $device = '/dev/ttyUSB0';
// $write = 'w+';
// sleep(3);
//
// $handle = fopen( $device, $write ); # Write +
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;
Esempio n. 30
-5
function getSerialConnection()
{
    static $serial = null;
    if (!$serial) {
        print "Opening serial connection .. ";
        $serial = new phpSerial();
        if ($serial->deviceSet('/dev/ttyACM0')) {
            $serial->confBaudRate(9600);
            $serial->deviceOpen();
        } else {
            print "ERROR\n";
            exit(1);
        }
        print "OK\n";
    }
    return $serial;
}