Пример #1
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();
}
Пример #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("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...
Пример #3
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);
    }
}
Пример #4
0
$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;
}
if (!$f) {
    die("Could not find a DMX interface!\n");
}
$d = '';
dmx_set_levels($d);
$d1 = str_pad('', 512, chr(0));
$d2 = str_pad('', 512, chr(0));
dmx_set_levels_U1($d1);
dmx_set_levels_U2($d2);
for ($i = 0; $i <= 255; $i++) {
    $d1 = str_pad('', 512, chr($i));
    $d2 = str_pad('', 512, chr(255 - $i));
    dmx_set_levels_U1($d1);
    dmx_set_levels_U2($d2);
    if ($must_exit) {
        break;
    }
}
$dmx->deviceClose();
Пример #5
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();