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(); }
<?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+"); // RL2 is bit 1,2,3 Engine off $serial->sendMessage(sprintf("#051000\r\n"), 0); // turn slow off usleep(25000); $serial->sendMessage(sprintf("#051100\r\n"), 0); // turn medium off usleep(25000); $serial->sendMessage(sprintf("#051200\r\n"), 0); // turn fast off usleep(25000); // // If you want to change the configuration, the device must be closed // $serial->deviceClose(); //
<?php require "../includes/php_serial.class.php"; $serial = new phpSerial(); $serial->deviceSet("/dev/ttyACM0"); $serial->confBaudRate(115200); $serial->deviceOpen(); $serial->sendMessage("light"); $done = false; $line = ""; while (!$done) { $read = $serial->readPort(); for ($i = 0; $i < strlen($read); $i++) { if ($read[$i] == "\n") { $done = true; echo $line; $line = ""; } else { $line .= $read[$i]; } } } $serial->deviceClose();
<?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();
$_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 : > 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! > The following link was very helpful in figuring this out, my USB/Serial
<?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();
* */ <?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; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head>
} } 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();
} echo "Started CORS!"; $comPort = "/dev/ttyACM0"; //The com port address. This is a debian address $msg = ''; if (isset($_POST["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("Well hello!"); $serial->deviceClose(); $msg = "You message has been sent! WOHOO!"; } ?> <html> <head> <title>Arduino control</title> </head> <body>
* */ <?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('1'); } else { if ($_GET['action'] == "off") { $serial->sendMessage('0'); } } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>UDOO - Serial Example</title>
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); include "php_serial.class.php"; $value = str_replace("_", "\r\n", $value); $serial = new phpSerial(); $serial->deviceSet("/dev/ttyAMA0"); $serial->confBaudRate(9600); $serial->confParity("none"); $serial->confCharacterLength(8); $serial->confStopBits(1); $serial->deviceOpen(); $serial->sendMessage($value . "\r\n"); //CONFIG $scans = 360; $deg = 360 / $scans; //deg to move every time //CLEAR DIR function emptyDirectory($dirname, $self_delete = false) { if (is_dir($dirname)) { $dir_handle = opendir($dirname); } if (!$dir_handle) { return false; } while ($file = readdir($dir_handle)) { if ($file != "." && $file != "..") { if (!is_dir($dirname . "/" . $file)) { @unlink($dirname . "/" . $file);
#!/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();
<?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(); //
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); } }
// // // 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... // // /* Notes from Jim : > Also, one last thing that would be good to document, maybe in example.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 $read = ''; $theResult = ''; $start = microtime_float(); while ($read == '' && microtime_float() <= $start + 0.5) { $read = $serial->readPort(); if ($read != '') { $theResult .= $read; $read = ''; } } // If you want to change the configuration, the device must be closed $serial->deviceClose(); // etc... echo "Read data: " . $theResult . "<br>";
<?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;
<?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("3\r\n"); $serial->sendMessage("F1\r"); $file = fopen("water_reading.txt", "w"); fwrite($file, "3"); fclose($file); shell_exec("sh ./water_reader.sh"); $serial->deviceClose();
<?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...
$db->MakeQuery($query); $command = $command . "0"; } if (isset($_POST['LumensRange'])) { $lumensrthershold = $_POST['LumensRange'] * 30 / 100; $query = "UPDATE Switch SET SetAutoLumens={$lumensrthershold} WHERE ID='BF'"; $db->MakeQuery($query); $command = $command . $lumensrthershold; } $command = $command . "N"; $db->Close(); require "../includes/php_serial.class.php"; $serial = new phpSerial(); $serial->deviceSet("/dev/ttyUSB0"); $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(); $serial->sendMessage($command); $serial->deviceClose(); if (error_get_last()) { header("Location: /Devices/switch.php?Command=Error"); } else { header("Location: /Devices/switch.php?Command=OK"); }
$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++) { $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>
<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(); if (!empty($_GET['waterPlant'])) { $serial->deviceOpen(); $serial->sendMessage("W"); $serial->deviceClose();
$result = stream_select($read, $write, $except, 0); if ($result === false) { throw new Exception('stream_select failed'); } if ($result === 0) { return false; } $data = stream_get_line($fd, 1); return true; } $flag = 1; while (!feof($sensors)) { $x = ""; if (non_block_read(STDIN, $x) && $x == 'q' || trim(file_get_contents('/tmp/controller.run')) != '1') { //stop(); $exec = '@q#'; $serial->deviceOpen(); // sleep(0.5); $serial->sendMessage($exec); // sleep(0.1); $serial->deviceClose(); // sleep(1); //sleep(1); break; } // Quit on F10 //sleep(0.01); refreshDIYData($sensors); carscript(); } echo "Main loop broke";
<?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();
<?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...
$feed = isset($_POST['feed']) && $_POST['feed'] != '' ? $_POST['feed'] : $feed; 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>