/** * 扫一位置,再扫一表置确认 * * @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; }
/** * 完成确认,返回确认错误信息 * * @param array $data * @param string $state */ public function finishConfirm($type = '') { try { ShareMemory::setShareMemory('while', false); //暂停一下 //sleep(2); $confirmerror = ShareMemory::getShareMemory('confirmerror'); $rtn = $confirmerror ? $confirmerror : ''; //是否有两个表,确认了同一个表位 $confirm = new ConfirmStationAction(); $result = $confirm->checkWhetherDuplic(); if ($result) { if ($rtn == '') { $rtn = array(); } for ($i = 0; $i < sizeof($result); $i++) { $err = "[" . $result[$i]["station"] . "]表位确认了多个表[" . $result[$i]['code'] . "]请更正"; array_push($rtn, $err); } } //如果没有值,则返回成功 return $rtn ? $rtn : true; } catch (Executive $e) { system_out("StocksManager.finishConfirm error:{$e}"); throw new Exception($e); } }
/** * 周转箱/表出仓方式 * * @param array $data 表头数据 * @return array */ public function confirmOutStationBK1($data) { try { //system_out("scanneradd:".Session::get('scanneradd')); $scanner = new ScannerADD(Session::get('scanneradd'), Session::get('scannerport')); $action = new ConfirmStationAction(); $device = null; //条码枪地址 //确认错误信息 $confirmerror = array(); //循环参数 $while = true; //删除错误信息 ShareMemory::delShareMemory("confirmerror"); //设置共享内存 ShareMemory::setShareMemory("while", $while); $boxhead = Session::get('boxhead'); $boxheadlenght = Session::get('boxheadlength'); $station = ''; $code = ''; //进行无限循环 while ($while) { sleep(1); //读取是否有人为中断 $while = ShareMemory::getShareMemory("while"); if (!$while) { break; } //读取数据 $rtn = $scanner->readData(); if (trim($rtn) == '' || $rtn == null || $rtn == false || substr($rtn, 2) == 'OK') { continue; } $rtn = strtoupper($rtn); $device = substr($rtn, 0, 2); $rtn = substr($rtn, 2); system_out("out rtn:" . $rtn); //如果是周转箱字母头,则周转箱出仓 if (substr($rtn, 0, $boxheadlenght) == $boxhead) { $station = $rtn; $code = ''; } else { $station = ''; $code = $rtn; } //end if 1 //如果两者有一不为空,则确认 if (trim($station) != '' || trim($code) != '') { //system_out("out station:".$station); //system_out("out code:".$code); $result = $this->confirmOutStation($data, $station, $code); //确认失败 if (is_string($result)) { system_out("confirmOutStationBK1.error:" . $result); //写错误信息 array_push($confirmerror, $result); //将错误信息写进共享内存 ShareMemory::setShareMemory('confirmerror', $confirmerror); $station = ''; $code = ''; //亮红灯 $scanner->sendRedLight($device); $scanner->readData(); continue; } //亮绿灯 $scanner->sendGreenLight($device); $scanner->readData(); //清空数据,继续执行 $station = ''; $code = ''; } //end if 2 } } catch (Executive $e) { system_out("StocksManager.confirmOutStationBK1 error:{$e}"); throw new Exception($e); } //返回值 return $confirmerror; }
/** * /表架开一位置灯,确认一表 * * @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 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; }