Exemple #1
0
 /**
  * Returns array of serial ports. Can return fake list for testing purposes.
  * 
  * @return array Array of serial ports.
  */
 public static function getAvailableComPortsList()
 {
     if (Yii::app()->params['show_fake_com_ports']) {
         return array('COM1' => 'COM1', 'COM2' => 'COM2');
     }
     $output = null;
     $result = array();
     if (It::isLinux()) {
         exec('setserial -g /dev/ttyS*', $output);
         if (is_array($output)) {
             foreach ($output as $line) {
                 $matches = array();
                 if (preg_match('/\\/dev\\/ttyS([0-9])/', $line, $matches)) {
                     $serialPort = 'COM' . ($matches[1] + 1);
                     $result[$serialPort] = $matches[0];
                 }
             }
         }
         $result = array_unique($result);
     } else {
         if (it::isWindows()) {
             exec('wmic path Win32_SerialPort get Description, DeviceID /format:csv', $output);
             if (is_array($output) && count($output) > 1) {
                 $output = array_slice($output, 2);
                 foreach ($output as $line) {
                     $values = explode(',', $line);
                     $result[$values[2]] = $values[1];
                 }
             }
         }
     }
     return $result;
 }
Exemple #2
0
<?php

class it
{
    function readDir($dir)
    {
        $handle = opendir($dir);
        while (false !== ($filename = readdir($handle))) {
            if ($filename == '.' or $filename == '..' or $filename[0] == '.') {
                continue;
            }
            if (is_dir($dir . "/" . $filename)) {
                $this->readDir($dir . "/" . $filename);
                continue;
            }
            $filesize = filesize($dir . "/" . $filename);
            $this->writeFileToLog($filename, $filesize);
        }
        closedir($handle);
    }
    function writeFileToLog($filename, $bytesize)
    {
        $fp = fopen("versioning.log", "a+");
        fwrite($fp, $filename . " - " . $bytesize . "\r\n");
        fclose($fp);
    }
}
// end of class
$dir = dirname(__FILE__);
$it = new it();
$it->readDir($dir);