Мониторинг выходных портов


Вызов функции spc_request для мониторинга выходных портов

spc_request($sid, 4, $cmd);

Структура командной строки выглядит следующим образом:

"get $port output"

Возврат значений

Стандартный ответ выглядит следующим образом:

"200,$state"

Пример

<?php
include "/lib/sd_spc.php";
spc_reset();
spc_sync_baud(115200);
$sid = 1;

echo "turn all output ports on\r\n";
spc_request($sid, 4, "set 0 output high");
spc_request($sid, 4, "set 1 output high");
spc_request($sid, 4, "set 2 output high");
spc_request($sid, 4, "set 3 output high");

// get status of input ports
echo "Port 0: ", spc_request($sid, 4, "get 0 output"), "\r\n";
echo "Port 1: ", spc_request($sid, 4, "get 1 output"), "\r\n";
echo "Port 2: ", spc_request($sid, 4, "get 2 output"), "\r\n";
echo "Port 3: ", spc_request($sid, 4, "get 3 output"), "\r\n";

sleep(1);

echo "turn all output ports off\r\n";
spc_request($sid, 4, "set 0 output low");
spc_request($sid, 4, "set 1 output low");
spc_request($sid, 4, "set 2 output low");
spc_request($sid, 4, "set 3 output low");

// get status of input ports
echo "Port 0: ", spc_request($sid, 4, "get 0 output"), "\r\n";
echo "Port 1: ", spc_request($sid, 4, "get 1 output"), "\r\n";
echo "Port 2: ", spc_request($sid, 4, "get 2 output"), "\r\n";
echo "Port 3: ", spc_request($sid, 4, "get 3 output"), "\r\n"
?>