/** * 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; }