/** * 打开灯操作 * * @param String $struct 表架参数 Example:struct = array("No" = "GN01","xNum"=>10,"yNum"=>5) * @param String array $places 表位 Example:places = array("A"=>array("GN01A0101","GN01A0102") * "B"=>array("GN01B0101","GN01B0102")) * @param String $stype 类型 get(取表),put(挂表) * @return Array */ public function trunOn($struct, $places, $stype) { //system_out("places:".print_r($places,true)); //DEBUG if (true == STRUCT_DEBUG) { $confirm = new ConfirmStationAction(); try { $confirm->saveUnconfirmStation($places, $struct["No"], $stype == 'put' ? "U" : "D"); } catch (Executive $e) { //system_out("StructControlAction.trunOn:" . print_r($e,true)); throw new Exception($e); } $rtn["stype"] = $stype; $rtn["places"] = $places; return $rtn; } //如果表架没有xNum或者yNum,则获取 if (!$struct["xNum"] || !$struct["yNum"]) { $structparm = $this->getStructparmBySingle($struct["No"]); if ($structparm) { $struct["xNum"] = $structparm["xNum"]; $struct["yNum"] = $structparm["yNum"]; $struct["comport"] = $structparm["comport"]; $struct["hardadd"] = $structparm["hardadd"]; $struct["ipaddress"] = $structparm["ipaddress"]; $struct["delay"] = Session::get('structdelay'); } } $this->setLogs("structparms of turnon light:" . print_r($struct, true)); $this->address = $struct["ipaddress"] ? $struct["ipaddress"] : $this->address; $this->com = $struct["comport"] ? $struct["comport"] : 'COM1'; $add = $struct["hardadd"] ? $struct["hardadd"] : (int) substr($struct["No"], 2, 2); $ycbk = new YCBK($this->address, $this->port, $this->com, $this->comToNetType); //system_out("places:".print_r($places,true)); $placesNo = AddressCover::NameToNumber($places, $struct["xNum"], $struct["yNum"]); $ycbk->close(); //system_out(Session::id()); if (!Session::is_set($struct["No"])) { system_out("StructControlAccino.trunOn:is not set"); //硬件操作 for ($i = 0; $i < $this->looptimes; $i++) { $ycbk->open(); //获取表架使用情况 $station = $ycbk->querySwitchStatus($add); $ycbk->close(); if ($station) { break; } usleep($this->waittime); } if (!$station) { throw new Exception("查询表架[" . $add . "]使用情况出错:" . $ycbk->getError(), 101); } } else { $station = Session::get($struct["No"]); //system_out("test:".print_r($station,true)); } //设置A面放表的表位的标记 for ($i = 0; $i < sizeof($placesNo["A"]); $i++) { $index = $placesNo["A"][$i]; $stype == 'put' ? $station[$index]["A"] = "U" : ($station[$index]["A"] = "D"); } //设置B面放表的表位的标记 for ($i = 0; $i < sizeof($placesNo["B"]); $i++) { $index = $placesNo["B"][$i]; $stype == 'put' ? $station[$index]["B"] = "U" : ($station[$index]["B"] = "D"); } //执行硬件操作 for ($i = 0; $i < $this->looptimes; $i++) { $ycbk->open(); //挂表 if ($stype == 'put') { //转换码 $station = AddressCover::changeCodeForPut($station); //system_out("after addresscover station:".print_r($station,true)); $result = $ycbk->uploadMeterStateLight($add, $station); } else { //转换码 $station = AddressCover::changeCodeForGet($station); //system_out("after addresscover station,get:".print_r($station,true) ); $result = $ycbk->downloadMeterStateLight($add, $station); } $ycbk->close(); if ($result) { break; } usleep($this->waittime); } if (!$result) { throw new Exception("开启表架[" . $add . "]灯出错:" . $ycbk->getError(), 102); } //保存开了的灯进数据库 $confirm = new ConfirmStationAction(); try { $confirm->saveUnconfirmStation($places, $struct["No"], $stype == 'put' ? "U" : "D"); } catch (Executive $e) { $this->close($struct, $stype); throw new Exception($e); } $rtn["stype"] = $stype; $rtn["places"] = $places; $this->setLogs($ycbk->getLogs()); return $rtn; }