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; }
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; }
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(); }
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(); }
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; }
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 $read = ''; $theResult = ''; $start = microtime_float(); while ($read == '' && microtime_float() <= $start + 0.5) {
<?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++) { $rcv = $rcv . $read[$i];
<?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();
<?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 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...
<?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();
#!/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 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>
$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; }
<?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("COM4"); // 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=\"ALL\"\n\r", 2); var_dump($serial->readPort()); // 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); } }
echo '</select> Baud Rate <select name="baud">'; for ($i = 0; $i < $count2; $i++) { echo '<option value="' . $baud_list[$i] . '">' . $baud_list[$i] . '</option>'; } echo '</select> <input type="submit" value="Select" /> </form> <hr />'; // 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 ($_POST['comm'] == 'None') { echo 'There\'s no active comm-port that can be used. Please check the connection<br /> (Right Click on My Computer->Select Properties->Hardware->Device Manager->Ports (COM & LPT))<br /> If there is a comm-port is active, make sure that it is not being used'; } else { if (isset($_POST['comm'])) { $serial->deviceSet($_POST['comm']); $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("Hello!"); // Or to read from $read = $serial->readPort(); // If you want to change the configuration, the device must be closed $serial->deviceClose(); } else { echo 'Error';
} } 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();
$argc = $_SERVER["argc"]; $argv = $_SERVER["argv"]; //$argv is an array if ($argc == 0) { error(usage()); } $args = parse_args($argc, $argv); if (isset($args['d'])) { $debug = $args['d']; } elseif (isset($args['debug'])) { $debug = $args['debug']; } else { $debug = 0; } $dmx = new phpSerial(); $dmx->deviceSet(DMX_DEV); $dmx->confBaudRate(SERIAL_BAUD); if (!$dmx->deviceOpen()) { die("Could not open DMX Interface on " . DMX_DEV . "\n"); } $f = 0; if ($sn = dmx_request_serial_number()) { printf("Found DMX Interface with Serial Number: %s\n", $sn); if ($fw = dmx_request_parameters()) { printf("Firmware Version: %s\n", $fw['FW_VER']); printf("DMX Output Break Time: %s x 10.67 = %.02f us\n", $fw['DMX_BR_TIME'], $fw['DMX_BR_TIME'] * 10.67); printf("DMX Mark After Break Time: %s x 10.67 = %.02f us\n", $fw['DMX_MABR_TIME'], $fw['DMX_MABR_TIME'] * 10.67); printf("DMX Output Rate: %s packets/sec\n", $fw['DMX_OUTPUT_RATE']); } $f = 1; }
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) { $serial->deviceOpen();
// echo '<form action="' . $_SERVER['PHP_SELF'] . '"method="post" target="frame"> // <input type="file" name="dat2"/> // <input type="submit" name="file" value="Odpri"/> // </form>'; // First we must specify the device. This works on both linux and windows (if // your linux serial device is /dev/ttyS0 for COM1, etc) //Z klikom na gumb "Odpri" odpremo COM port na določenih vratih z določeno "baud rate" //TO-DO dodaj še ostale parametre kot so: stop bit, pariteto itd... if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($_POST['comm'] == 'None') { echo 'There\'s no active comm-port that can be used. Please check the connection<br /> (Right Click on My Computer->Select Properties->Hardware->Device Manager->Ports (COM & LPT))<br /> If there is a comm-port is active, make sure that it is not being used'; } else { if (isset($_POST['comm'])) { $serial->deviceSet($_POST['comm']); $serial->confBaudRate($_POST['baud']); $serial->confParity("none"); $serial->confCharacterLength(7); $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!");
<?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...
* 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; }
<?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...
include '/var/www/lib/config.php'; $feed = 1000; $raspi_still = false; if ($_SERVER['REQUEST_METHOD'] == 'POST') { include "php_serial.class.php"; $value = isset($_POST['c']) && $_POST['c'] != '' ? $_POST['c'] : ''; $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));
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; }