예제 #1
0
 /**
  * 扫一位置,再扫一表置确认
  *
  * @param string $billdata
  * @return boolean
  */
 private function confirmInStationBK1($billdata)
 {
     try {
         $type = Session::get('scannertype') ? Session::get('scannertype') : 'type1';
         $stocksmanager = new StocksManagerAction();
         $scanner = new ScannerADD(Session::get('scanneradd'), Session::get('scannerport'), $type);
         $action = new ConfirmStationAction();
         $struct = new StructControlAction();
         $device = null;
         //条码枪地址
         //确认错误信息
         $confirmerror = array();
         //循环参数
         $while = true;
         //删除错误信息
         ShareMemory::delShareMemory("confirmerror");
         //设置共享内存
         ShareMemory::setShareMemory("while", $while);
         //关闭状态
         //开表灯
         $station = '';
         $code = '';
         system_out("starting confirm");
         //进行无限循环
         while ($while) {
             sleep(1);
             //读取是否有人为中断
             $while = ShareMemory::getShareMemory("while");
             if (!$while) {
                 //array_push($confirmerror,"人为中断确认!");
                 ShareMemory::setShareMemory("confirmerror", $confirmerror);
                 break;
             }
             //读取数据
             $rtn = $scanner->readData();
             if (!$rtn) {
                 continue;
             }
             //$rtn = strtoupper($rtn);
             $device = $scanner->device;
             if (substr($rtn, 0, 2) == 'GN') {
                 //如果位置码位空,则设置位置码
                 if ($station == '') {
                     //赋值位置码
                     $station = $rtn;
                     if ($type == 'type1') {
                         $scanner->sendGreenLight($device);
                         $scanner->readData();
                     }
                     continue;
                 } else {
                     //如果已经扫了表位,且不是原来那个,则报错,重新开始
                     if ($station != $rtn) {
                         if ($type == 'type1') {
                             $scanner->sendRedLight($device);
                             $scanner->readData();
                         }
                         $station = '';
                         $code = '';
                         continue;
                     } else {
                         if ($type == 'type1') {
                             $scanner->sendGreenLight($device);
                             $scanner->readData();
                         }
                         continue;
                     }
                 }
             } else {
                 //如果没有扫表位置码,就扫表码,报错,重新开始
                 if ($station == '') {
                     if ($type == 'type1') {
                         $scanner->sendRedLight($device);
                         $scanner->readData();
                     }
                     $station = '';
                     $code = '';
                     continue;
                 }
                 //设置表码
                 $code = $rtn;
             }
             //end if 1
             //如果两者都不为空,则确认
             if (trim($station) != '' && $station != '*' && trim($code) != '' && $code != '*') {
                 //开始确认挂表位置和表的关系
                 $item["station"] = $station;
                 $item["code"] = $code;
                 $result = $action->confirmInstation($billdata, $item);
                 //确认错误
                 if (!$result) {
                     //亮红灯
                     if ($type == 'type1') {
                         $scanner->sendRedLight($device);
                         $scanner->readData();
                     }
                     //获取错误
                     $result = $action->getError();
                     array_push($confirmerror, $result);
                     system_out($result);
                     //将错误信息写进共享内存
                     ShareMemory::setShareMemory('confirmerror', $result);
                     $station = '';
                     $code = '';
                     continue;
                 }
                 //已确认
                 //亮绿灯
                 if ($type == 'type1') {
                     $scanner->sendGreenLight($device);
                     $scanner->readData();
                 }
                 //关闭灯
                 try {
                     system_out("starting trunoff light:{$station} ,length:" . strlen($station));
                     $result = $struct->trunOff(array("No" => substr($station, 0, 4)), array($station), 'put');
                     if ($result) {
                         system_out("trunoff light succeed");
                     } else {
                         system_out("trunoff light fault");
                     }
                 } catch (Exception $e) {
                     system_out("trunoff light error:" . $e->getMessage());
                     $error = $struct->getLogs();
                     system_out("错误日志:" . $error);
                     $station = '';
                     $code = '';
                     continue;
                 }
                 //重置,开始新的等待
                 $station = '';
                 $code = '';
             }
             //end if 2
         }
     } catch (Executive $e) {
         system_out("StocksManager.ConfirmInStationBk1 error{$e}");
         throw new Exception($e);
     }
     //返回值
     return $confirmerror;
 }
예제 #2
0
 /**
  * 打开灯操作
  *
  * @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;
 }
예제 #3
0
 /**
  * 如果是表架的,则删除表架灯开灯记录
  *
  * @param array $data
  * @param string $state
  */
 public function delUnconfirmStation($data, $state)
 {
     try {
         $confirm = new ConfirmStationAction();
         if (is_array($data)) {
             $condition = "`station` in ('" . implode($data, "','") . "') and `state`='{$state}'";
         } else {
             $condition = "`state`='{$state}'";
         }
         $confirm->delUnconfirmStation($condition);
     } catch (Executive $e) {
         system_out("StocksManager.finishConfirn Exceptoin:{$e},condition:{$condition}");
         throw new Exception($e);
     }
     return true;
 }
예제 #4
0
 /**
  * /表架开一位置灯,确认一表
  *
  * @param string $billdate
  * @param array $data
  * @return boolean
  */
 private function confirmInStationBK2($billdate, $data)
 {
     try {
         $stocksmanager = new StocksManagerAction();
         $scanner = new ScannerADD(Session::get('scanneradd'), Session::get('scannerport'));
         $action = new ConfirmStationAction();
         $struct = new StructControlAction();
         $device = null;
         //条码枪地址
         //确认错误信息
         $confirmerror = array();
         //循环参数
         $while = true;
         //删除错误信息
         ShareMemory::delShareMemory("confirmerror");
         //设置共享内存
         ShareMemory::setShareMemory("while", $while);
         $station = '';
         $code = '';
         $limit = 0;
         //第一个灯位
         if (sizeof($data) > 0) {
             $station = $data[0];
             //开灯
             $struct->trunOnPutLightByStation(array($station));
         } else {
             return;
         }
         //进行无限循环
         while ($while) {
             sleep(1);
             //当前的位置码
             //system_out("station:".$station);
             //如果错了三次,则该表位跳过
             if ($limit >= 3) {
                 array_push($confirmerror, "[{$station}]表位确认不成功!");
                 ShareMemory::setShareMemory('confirmerror', $confirmerror);
                 //将该位置码去掉
                 array_shift($data);
                 //获取新的位置码,并重新初始
                 if (sizeof($data) > 0) {
                     $station = $data[0];
                     $code = '';
                     $limit = 0;
                     //开灯
                     $struct->trunOnPutLightByStation($station);
                 } else {
                     array_push($confirmerror, "表位进行确认完毕,如果还有表位没确认,请重新开始程序!");
                     ShareMemory::setShareMemory("confirmerror", $confirmerror);
                     return true;
                 }
             }
             //读取是否有人为中断
             $while = ShareMemory::getShareMemory("while");
             if (!$while) {
                 system_out("break by user");
                 //array_push($confirmerror,"人为中断确认!");
                 ShareMemory::setShareMemory("confirmerror", $confirmerror);
                 break;
             }
             //读取数据
             $rtn = $scanner->readData();
             if ($rtn == '' || $rtn == null || $rtn == false) {
                 continue;
             }
             $rtn = strtoupper($rtn);
             //system_out("result:".$rtn);
             $device = substr($rtn, 0, 2);
             $rtn = substr($rtn, 2);
             //如果编码是表位,则退出
             if (substr($rtn, 0, 2) == 'GN') {
                 //亮红灯
                 $scanner->sendRedLight($device);
                 $scanner->readData();
                 array_push($confirmerror, "请扫描表码,不要扫描位置码!");
                 ShareMemory::setShareMemory('confirmerror', $confirmerror);
                 $limit++;
                 continue;
             } else {
                 //设置表码
                 $code = $rtn;
             }
             //end if 1
             //如果两者都不为空,则确认
             if ($station != '' && $station != '*' && $code != '' && $code != '*') {
                 //开始确认挂表位置和表的关系
                 $item["station"] = $station;
                 $item["code"] = $code;
                 $result = $action->confirmInstation($billdate, $item);
                 //确认失败
                 if (!$result) {
                     //亮红灯
                     $scanner->sendRedLight($device);
                     $scanner->readData();
                     $result = $action->getError();
                     //输出错误
                     system_out("confirm error:" . $result);
                     array_push($confirmerror, $result);
                     //将错误信息写进共享内存
                     ShareMemory::setShareMemory('confirmerror', $confirmerror);
                     $code = '';
                     $limit++;
                     continue;
                 }
                 //确认成功
                 //亮绿灯
                 $scanner->sendGreenLight($device);
                 $scanner->readData();
                 //将该位置码去掉
                 array_shift($data);
                 //如果所有的表都扫完了,则终止循环
                 if (sizeof($data) == 0) {
                     array_push($confirmerror, "表位进行确认完毕,如果还有表位没确认,请重新开始程序!");
                     ShareMemory::setShareMemory("confirmerror", $confirmerror);
                     ShareMemory::setShareMemory("while", false);
                     $struct->close(array("No" => substr($station, 0, 4)), 'put');
                     break;
                 } else {
                     $station = $data[0];
                     $code = '';
                     $limit = 0;
                     //开灯
                     $struct->trunOnPutLightByStation(array($station));
                 }
             }
             //end if 2
         }
     } catch (Executive $e) {
         system_out("StocksManager.confirmInStationBK2 error:{$e}");
         throw new Exception($e);
     }
     //返回值
     return $confirmerror;
 }
 /**
  * 确认出库表
  *
  * @param array $data  	//单据信息
  * @param string $station  //周转想
  * @param string $code     //表码
  * @retur Boolean
  */
 private function confirmOutStation($data, $station = '', $code = '')
 {
     try {
         $confirm = new ConfirmStationAction();
         $currentstocks = new StocksManagerAction();
         //单表出仓
         if ($code != '') {
             $result = $currentstocks->queryCurrentStocks("code = '{$code}'");
             if (!$result) {
                 return "库存里没有该表计[{$code}]!";
             }
             $rtn = $confirm->confirmOutstation($data, $code);
             if (!$rtn) {
                 $rtn = $confirm->getError();
             }
             return $rtn;
         } elseif ($station != '') {
             $result = $currentstocks->queryCurrentStocks("station = '{$station}'");
             if (sizeof($result) == 0) {
                 return "库存里该周转箱[{$station}]没有表计!";
             }
             for ($i = 0; $i < sizeof($result); $i++) {
                 $rtn = $confirm->confirmOutstation($data, $result[$i]["code"]);
                 if (!$rtn) {
                     $rtn = $confirm->getError();
                     return $rtn;
                 }
             }
             return $rtn;
         }
     } catch (Exception $e) {
         system_out("confirmOutStationBK1.confirmOutStation Error:" . $e->getMessage());
         throw new Exception($e);
     }
     return true;
 }
예제 #6
0
 /**
  * 周转箱确认方式
  *
  * @param string $billdata
  * @return boolean
  */
 private function confirmInStationBK3($billdata)
 {
     try {
         $type = Session::get('scannertype') ? Session::get('scannertype') : 'type1';
         $stocksmanager = new StocksManagerAction();
         $scanner = new ScannerADD(Session::get('scanneradd'), Session::get('scannerport'), $type);
         $action = new ConfirmStationAction();
         $struct = new StructControlAction();
         $device = null;
         //条码枪地址
         //确认错误信息
         $confirmerror = array();
         //循环参数
         $while = true;
         //删除错误信息
         ShareMemory::delShareMemory("confirmerror");
         //设置共享内存
         ShareMemory::setShareMemory("while", $while);
         $boxhead = Session::get('boxhead');
         $boxheadlength = Session::get('boxheadlength');
         $station = '';
         $code = '';
         system_out("start confirmInStationBK3");
         //进行无限循环
         while ($while) {
             sleep(1);
             //读取是否有人为中断
             $while = ShareMemory::getShareMemory("while");
             if (!$while) {
                 //array_push($confirmerror,"人为中断确认!");
                 ShareMemory::setShareMemory("confirmerror", $confirmerror);
                 break;
             }
             //读取数据
             $rtn = $scanner->readData();
             if (!$rtn) {
                 continue;
             }
             //$rtn = strtoupper($rtn);
             $device = $scanner->device;
             //如果是周转箱字母头,则设置station
             if (substr($rtn, 0, $boxheadlength) == $boxhead) {
                 system_out("statino:" . $rtn);
                 $station = $rtn;
                 if ($type == 'type1') {
                     $scanner->sendGreenLight($device);
                     $scanner->readData();
                 }
             } else {
                 //如果没有扫周转箱码,就扫表码,报错,重新开始
                 if ($station == '') {
                     if ($type == 'type1') {
                         $scanner->sendRedLight($device);
                         $scanner->readData();
                     }
                     $code = '';
                     array_push($confirmerror, "请先扫描周转箱:");
                     ShareMemory::setShareMemory('confirmerror', $confirmerror);
                     continue;
                 } else {
                     //设置表码
                     $code = $rtn;
                 }
             }
             //end if 1
             //system_out("station:".$station);
             //system_out("code:".$code);
             //如果两者都不为空,则确认
             if (trim($station) != '' && $station != null && trim($code) != '' && $code != null) {
                 //system_out('begin confirm');
                 //开始确认挂表位置和表的关系
                 $item["station"] = $station;
                 $item["code"] = $code;
                 $result = $action->confirmInstation($billdata, $item);
                 //确认失败
                 if (!$result) {
                     $result = $action->getError();
                     array_push($confirmerror, $result);
                     system_out($result);
                     //将错误信息写进共享内存
                     ShareMemory::setShareMemory('confirmerror', $confirmerror);
                     $code = '';
                     if ($type == 'type1') {
                         $scanner->sendRedLight($device);
                         $scanner->readData();
                     }
                     continue;
                 }
                 //确认成功
                 if ($type == 'type1') {
                     $scanner->sendGreenLight($device);
                     $scanner->readData();
                 }
                 //清空条码继续等待扫描
                 $code = '';
             }
             //end if 2
         }
     } catch (Executive $e) {
         system_out("StocksManager.confirmInStationBK3 error:{$e}");
         throw new Executive($e);
     }
     //返回值
     return $confirmerror;
 }