コード例 #1
0
ファイル: closelight.class.php プロジェクト: kenlong/example
 /**
  * 扫一位置,再扫一表置确认
  *
  * @param string $billdata
  * @return boolean
  */
 private function confirmInStationBK1($billdata)
 {
     try {
         $struct = new StructControlAction();
         //关闭状态
         //开表灯
         $station = '';
         $code = '';
         system_out("starting trunoff light");
         $result = $struct->trunOff(array("No" => "GN05"), array("GN05A0101"), 'put');
         if (!$result) {
             system_out("trun off false");
         } else {
             system_out("trun off succeed");
         }
     } catch (Executive $e) {
         system_out("StocksManager.ConfirmInStationBk1 error:{$e}");
         throw new Exception($e);
     }
     //返回值
     return $confirmerror;
 }
コード例 #2
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;
 }
コード例 #3
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;
 }