Exemple #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;
 }
 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;
 }
Exemple #3
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();
}
Exemple #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();
 }
Exemple #5
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;
}
$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;
}
// ************************************************
// ***************** function cloud *********
// ************************************************
//function for write data cloud
// 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;
    if ($strLog != "") {
        $strAllLog .= $strLog;
        sleep(5);
        continue;
    }
    if ($strAllLog != "") {
        $arrLog = explode("\n", $strAllLog);
    }
}
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();