В общем застопорился я на этапе невозможности выполнить данный скрипт из Majordomo. Просто из браузера все работает. Тут без помощи Сергея никак...
<?
include_once("./config.php");
include_once("./lib/loader.php");
$db=new mysql(DB_HOST, '', DB_USER, DB_PASSWORD, DB_NAME); // connecting to database
header ('Content-Type: text/html; charset=utf-8');
// BUS Type: RS485 or CAN
define('BUS', 'RS485');
exec('mode '.gg('M236v1.port').': baud='.gg('M236v1.baud').' data=8 stop=1 parity=n xon=off');
$fd = dio_open(gg('M236v1.port'), O_RDWR);
//$fd = fopen("COM3", "r+");
/*
dio_tcsetattr($fd, array(
'baud' => 9600,
'bits' => 8,
'stop' => 1,
'parity' => 0
));
*/
##############
function merc_gd($cmd, $factor = 1, $total = 0)
{
global $fd;
global $sleep_time;
usleep(50000);
flush();
dio_write($fd, $cmd, 6);
// fwrite($fd, $cmd);
usleep($sleep_time);
$result = dio_read($fd, 64);
// $result = fread($fd, 64);
$ret = array();
if ( BUS == "CAN" )
$start_byte = 7;
else
$start_byte = 1;
if ( $total != 1 )
{
for ( $i = 0; $i < 4; $i++ )
{
if ( dechex(ord($result[$start_byte + $i * 3])) >= 40 )
$result[$start_byte + $i * 3] = chr(dechex(ord($result[$start_byte + $i * 3])) - 40);
if ( strlen($result) > $start_byte + 2 + $i * 3 )
$ret[$i] = hexdec(dd($result[$start_byte + $i * 3]).dd($result[$start_byte + $i * 3 + 2]).dd($result[$start_byte + $i * 3 + 1]))*$factor;
}
}
else
$ret[0] = hexdec(dd($result[$start_byte+1]).dd($result[$start_byte]).dd($result[$start_byte+3]).dd($result[$start_byte+2]))*$factor;
return $ret;
}
$sleep_time = 200000;
function dd($data = "")
{
$result = "";
$data2 = "";
for ( $j = 0; $j < count($data); $j++ )
{
$data2 = dechex(ord($data[0]));
if ( strlen($data2) == 1 )
$result = "0".$data2;
else
$result .= $data2;
}
return $result;
}
# Инициализация соединения, передача пароля
$command = explode(',', gg('M236v1.cInit'));
$c="";
for($i=0; $i < count($command); $i++){$c .= chr($command[$i]);}
dio_write($fd,$c, 11);
//fwrite($fd,$c);
usleep($sleep_time);
$result = dio_read($fd, 15);
//$result = fread($fd, 15);
// Общее потребление
$command = explode(',', gg('M236v1.cTot'));
$c="";
for($i=0; $i < count($command); $i++){$c .= chr($command[$i]);}
$Tot = merc_gd($c, 0.001, 1);
echo "Total: $Tot[0]\r\n";
sg('M236v1.Tot',$Tot[0]);
# Мощность по фазам
# =====================================================
$command = explode(',', gg('M236v1.cPv'));
$c="";
for($i=0; $i < count($command); $i++){$c .= chr($command[$i]);}
$Pv = merc_gd($c, 0.01);
echo "Pv: $Pv[0] - $Pv[1] - $Pv[2] \r\n";
sg('M236v1.P1',$Tot[2]);
sg('M236v1.P2',$Tot[1]);
sg('M236v1.P3',$Tot[0]);
# Завершение соединения
$command = explode(',', gg('M236v1.cClose'));
$c="";
for($i=0; $i < count($command); $i++){$c .= chr($command[$i]);}
dio_write($fd, $c, 4);
//fwrite($fd, $c);
usleep($sleep_time);
$result = dio_read($fd, 8);
//$result = fread($fd, 8);
dio_close($fd);
//fclose($fd);
$db->Disconnect(); // closing database connection
?>
----------------------------------------
ошибку выдает такую:
Warning: dio_write() expects parameter 1 to be resource, null given in C:\_majordomo\htdocs\modules\scripts\scripts.class.php(139) : eval()'d code on line 24
Warning: dio_read() expects parameter 1 to be resource, null given in C:\_majordomo\htdocs\modules\scripts\scripts.class.php(139) : eval()'d code on line 27
Total: 0
Warning: dio_write() expects parameter 1 to be resource, null given in C:\_majordomo\htdocs\modules\scripts\scripts.class.php(139) : eval()'d code on line 24
Warning: dio_read() expects parameter 1 to be resource, null given in C:\_majordomo\htdocs\modules\scripts\scripts.class.php(139) : eval()'d code on line 27
Pv: - -
Т.е. проблема с $fd = dio_open(gg('M236v1.port'), O_RDWR);