<?php
// 允許跨網域呼叫
header("Access-Control-Allow-Origin: *");
// 防止session file lock
session_write_close();
require_once 'Parameters.php';
require_once 'class.OPC_Soft.inc';

$output = array();
try {
	//讀取Soft點位
	$OPC = new OPC_Soft($Socket_Host, $Socket_Port, true);
	$cmd = urldecode($_GET['tag_cmd']);
	$rtn = $OPC->Commend($cmd);
	if (substr($cmd, 0, 1)=='W' && $rtn!=$cmd) {
		throw new Exception('error');
	}
	// OK
	$output = array(
		'result'  => true,
		'message' => $rtn
	);
} catch (Exception $e) {
	// GG
	$output = array(
		'result'  => false,
		'message' => $e->getMessage()
	);
}
// response
die(json_encode($output));
?>