SR-1640 Пример на PHP - Последовательное перемещение карты 0-15 банк и выброс карты во внешний накопитель

SR-Navigator и прочие WEB-панели
Ответить
Аватара пользователя
Nikita
Администратор
Сообщения: 228
Зарегистрирован: 11 дек 2017, 18:11

SR-1640 Пример на PHP - Последовательное перемещение карты 0-15 банк и выброс карты во внешний накопитель

Сообщение Nikita » 16 фев 2018, 11:30

Код: Выделить всё

<?
// ======================================================
// SIM Roulette / 2018
// http://intellectadvert.ru
// Последовательное перемещение карты 0-15 банк
// Выброс карты во внешний накопитель
// ======================================================

set_time_limit(600);
$token='12345';
$ip='192.168.1.96';

$begin=time();
$error=0;
$step=100; // Начальный шаг
$step_answer=1000; // Начальный шаг для пустых запросов

$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:0'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}                                
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 00 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:1'); test_command($step); $step++;	
	set_command($step,'func_card_put'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 01 PUT    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:1'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 01 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:2'); test_command($step); $step++;	
	set_command($step,'func_card_put'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 02 PUT    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:2'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 02 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:3'); test_command($step); $step++;	
	set_command($step,'func_card_put'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 03 PUT    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:3'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 03 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:4'); test_command($step); $step++;	
	set_command($step,'func_card_put'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 04 PUT    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:4'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 04 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:5'); test_command($step); $step++;	
	set_command($step,'func_card_put'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 05 PUT    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:5'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 05 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:6'); test_command($step); $step++;	
	set_command($step,'func_card_put'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 06 PUT    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:6'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 06 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:7'); test_command($step); $step++;	
	set_command($step,'func_card_put'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 07 PUT    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:7'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 07 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:8'); test_command($step); $step++;	
	set_command($step,'func_card_put'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 08 PUT    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:8'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 08 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:9'); test_command($step); $step++;	
	set_command($step,'func_card_put'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 09 PUT    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:9'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 09 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:10'); test_command($step); $step++;	
	set_command($step,'func_card_put'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 10 PUT    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:10'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 10 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:11'); test_command($step); $step++;	
	set_command($step,'func_card_put'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 11 PUT    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:11'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 11 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:12'); test_command($step); $step++;	
	set_command($step,'func_card_put'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 12 PUT    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:12'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 12 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:13'); test_command($step); $step++;	
	set_command($step,'func_card_put'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 13 PUT    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:13'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 13 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:14'); test_command($step); $step++;	
	set_command($step,'func_card_put'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 14 PUT    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:14'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 14 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:15'); test_command($step); $step++;	
	set_command($step,'func_card_put'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 15 PUT    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_bank_com:15'); test_command($step); $step++;	
	set_command($step,'func_card_get'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:BANK: 15 GET    ERRORS: '.$error); test_command($step,0); $step++;
$n=5; $a='NULL';
while ($a=='NULL' && $n) // Цикл забора карты
{
	$n--;
	set_command($step,'func_card_out'); $a=test_command($step,0); $step++;
}
if (!$n){br();}
$error=$error+4-$n; set_command($step,'lcd_msg:DONE!           ERRORS: '.$error); test_command($step,0); $step++;

// Повторяем цикл
$k++;
html_reload($k);

function test_command($step,$exit=1)
{
	$n=40; 
	while ($n)
	{
		$a=get_answer($step_answer); 
		$step_answer++;
		if ($a[0]==$step && $a[1]=='NULL' && $exit){br();}
		elseif ($a[0]==$step && $a[1])
		{
			return($a[1]);
		}
		$n--;
	}
	return(0);
}

function set_command($step,$c) // Отправляем команду в SIM Roulette
{
	sleep(1);
        $ch = curl_init();
       	curl_setopt($ch, CURLOPT_TIMEOUT, 10);
       	curl_setopt($ch, CURLOPT_HEADER, 0);
       	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
       	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$link='http://'.$GLOBALS['ip'].'/port?data='.$GLOBALS['token'].'||'.$step.'||'.urlencode($c); // Формируем строку запроса
        curl_setopt($ch, CURLOPT_URL, $link);
	$response = curl_exec($ch);
        curl_close($ch);

// Ведем лог
	$mas=fopen("log.dat", "a");
	fwrite($mas,date('H:i:s d.m.Y').' Отправлена команда: '.$c.' Шаг > '.$step.'
');
}

function get_answer($step) // Делаем пустой запрос для получения ответа в SIM Roulette на отправленную ранее команду
{
	sleep(1); // Запрос делаем каждую секунду
	$ch = curl_init();
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
       	curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
       	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$link='http://'.$GLOBALS['ip'].'/port?data='.$GLOBALS['token'].'||'.$step.'||request'; // Формируем строку запроса
        curl_setopt($ch, CURLOPT_URL, $link);
       	$response = curl_exec($ch);
        curl_close($ch);
	$a=explode('#!#',$response);
// Ведем лог
	$mas=fopen("log.dat", "a");
	fwrite($mas,date('H:i:s d.m.Y').' Получен ответ: '.$response.'
');
	return($a);
}

function br($txt='Ошибка!') // Выход с ошибкой
{
	set_command($GLOBALS['step'],'error'); $a=test_command($step); $step++;
	set_command($GLOBALS['step'],'sound:alarm'); $a=test_command($step); $step++;
	echo $txt;
	exit();
}

function html_reload($txt='Продолжаем...') // Перезагрузка страницы средствами HTML для продолжения цикла
{
?><html>
  <head>
    <link rel="stylesheet" href="style.css">
	<meta http-equiv="Refresh" content="1" />
  </head>
<body> 
<?=$txt?>
</body>
</html>
<?
}
?>
SIM Roulette — Must Have!

Ответить