1.还原按照配置文件进行不同扫码的功能

漯河-上右
LAPTOP-S9HJSOEB\昊天 2 years ago
parent c8bbcfac4d
commit 2b0bf803f3

@ -36,6 +36,8 @@ public class ConfigProperties {
private LightSource lightSource;
private ScanCodeMode scanCodeMode;
private Rfid rfid;
@Data
@ -74,6 +76,12 @@ public class ConfigProperties {
private Integer videoStyleColumn;
}
@Data
public static class Rfid {
private Long scanTime = 5L;
}
@Data
public static class SavePath{
private String mediaPath;

@ -327,6 +327,7 @@ public class CameraService {
}
private void conver(CameraIO cameraIO,Integer type){
if(type == 0){
cameraIO.setPosition("OK");
}else if(type == 1){

@ -1,6 +1,7 @@
package com.zhehekeji.web.service;
import codeDetector.BarcodeDetector;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhehekeji.common.util.PathUtil;
import com.zhehekeji.core.pojo.Result;
@ -24,6 +25,7 @@ import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import javax.annotation.Resource;
import java.io.IOException;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.HashSet;
@ -668,112 +670,169 @@ public class PlcService {
}
String path = PathUtil.createFileNameByRowColumn("jpg",cameraId,plcCmdInfo.getRow1(),plcCmdInfo.getColumn1());
//拍照暂停1s再拍
String path = PathUtil.createFileNameByRowColumn("jpg", cameraId, plcCmdInfo.getRow1(), plcCmdInfo.getColumn1());
try {
Thread.sleep(configProperties.getCameraConfig().getEDelayCaptureTime());
} catch (InterruptedException e) {
e.printStackTrace();
}
cameraCapture(cameraIdTop,false,null,path);
//
String e2 = "E2-" + plcCmdInfo.getLeftRightStr(1) + "-IN";
log.info("camera ptz"+e2);
gyrateCameraByCode(cameraId, e2);
try {
Thread.sleep(configProperties.getCameraConfig().getEDelayCaptureTime());
} catch (InterruptedException e) {
e.printStackTrace();
}
cameraCapture(cameraId,false,null,path+".jpg");
cameraCapture(cameraId, false, null, path);
} catch (NullPointerException e) {
log.error("相机{}未连接无法拍照", cameraId);
}
//托盘码
String trayCode = null;
Boolean trayCheck = Boolean.TRUE;
//如果是用扫码枪 扫 托盘码,就直接扫
//if(configProperties.getScanCodeMode().getTray() == 2){
SensorGun sensorGun = sensorService.getSensorByPlc(street.getId(),plcCmdInfo.getLeftRight1());
if(plcCmdInfo.getSeparation1() == 1 && configProperties.getScanCodeMode().getTray() == 2){
//扫托盘码
if(configProperties.getScanCodeMode().getTray() == 2) {
log.info("扫码类型:" + configProperties.getScanCodeMode().getTray());
//托盘使用sick扫码枪
if(sensorGun == null){
trayCode = "识别异常";
SensorGun sensorGun = sensorService.getSensorByPlc(street.getId(), plcCmdInfo.getLeftRight1());
if (sensorGun == null) {
trayCode = "扫码枪未配置";
trayCheck = Boolean.FALSE;
log.error("no sensor gun config in database ,street id:{},direction:{}",street.getId(),plcCmdInfo.getLeftRight1());
}else {
trayCode = SickSocket.readOCR(sensorGun.getIp(),sensorGun.getPort());
log.info("sensor tray code:{}",trayCode);
if("".equals(wmsTrayCode)){
log.error("no sensor gun config in database ,street id:{},direction:{}", street.getId(), plcCmdInfo.getLeftRight1());
} else {
trayCode = SickSocket.readOCR(sensorGun.getIp(), sensorGun.getPort());
log.info("sensor tray code:{}", trayCode);
if ("".equals(wmsTrayCode)) {
//托盘码为空,无货物
//只要扫码枪未识别出条码,即认为盘点正确
if(StringUtils.isEmpty(trayCode) || trayCode.equals("NoRead")){
trayCode = "";
if (StringUtils.isEmpty(trayCode) || trayCode.equals("NoRead")) {
trayCode = "无货物";
trayCheck = Boolean.TRUE;
}else {
trayCode = "识别异常";
} else {
trayCode = "扫码枪识别异常";
trayCheck = Boolean.FALSE;
log.warn("sick ocr error:{}",trayCode);
log.warn("sick ocr error:{}", trayCode);
}
}else {
if(StringUtils.isEmpty(trayCode) || trayCode.equals("NoRead")){
trayCode = "识别异常";
} else {
if (StringUtils.isEmpty(trayCode) || trayCode.equals("NoRead")) {
trayCode = "扫码枪识别异常";
trayCheck = Boolean.FALSE;
log.warn("sick ocr error:{}",trayCode);
}else {
trayCheck = wmsTrayCode.equals(trayCode);
log.warn("sick ocr error:{}", trayCode);
} else {
//扫到就认为正常
trayCheck = Boolean.TRUE;
}
}
}
}else if(configProperties.getScanCodeMode().getTray() == 3){
//扫到的码
Set<String> tags = new HashSet<>();
try {
RFIDCheck(plcCmdInfo, true);
Thread.sleep(1000 * configProperties.getRfid().getScanTime());
} catch (Exception e) {
e.printStackTrace();
} finally {
tags = RFIDStop(plcCmdInfo);
log.info("盘点rfid扫描结果" + tags);
}
if (tags !=null && tags.contains(wmsTrayCode)) {
//托盘码为空,无货物
//只要扫码枪未识别出条码,即认为盘点正确
trayCode = wmsTrayCode;
trayCheck = Boolean.TRUE;
} else {
trayCode = trayCode+ "扫码枪识别异常";
trayCheck = Boolean.FALSE;
log.warn("rfid error:{}", trayCode);
}
}else if(configProperties.getScanCodeMode().getTray() == 3){
//RFID
RFID rfid = rfidService.getRFIDByPlc(street.getId());
}
OrderInfo orderInfo = new OrderInfo(street,plcCmdInfo,1,cmdCode);
Stock stock = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(orderInfo.getStreetId(),orderInfo.getLeftRight(),orderInfo.getRow(),orderInfo.getColumn());
String scanCode = null;
Boolean codeCheck = Boolean.TRUE;
Boolean trayCodeCheck = Boolean.TRUE;
//货物使用球机扫码
Boolean trayGoodCheck = Boolean.TRUE;
if(configProperties.getScanCodeMode().getTray() == 2 && plcCmdInfo.getSeparation1() == 2){
//托盘使用球机扫码
if("".equals(wmsTrayCode)){
//空货物的处理
//如果系统货物为空,则只要扫码识别未出结果,就认为无货物
trayCode = BarcodeDetector.detectBestCodeUntilOK(configProperties.getSavePath().getMediaPath()+path,configProperties.getScanCodeMode().getTrayCodeTypes());
log.info("tray code:{},sys trayCode:{}",trayCode,wmsTrayCode);
if(StringUtils.isEmpty(trayCode)|| trayCode.equals("Unrecognized")){
trayCheck = Boolean.TRUE;
trayCode = "";
}else {
trayCheck = wmsTrayCode.equals(trayCode);
}
}else {
trayCode = BarcodeDetector.detectBestCodeUntilOK(configProperties.getSavePath().getMediaPath()+path,configProperties.getScanCodeMode().getTrayCodeTypes());
if(StringUtils.isEmpty(trayCode)){
log.error("row:{},cloumn:{}",plcCmdInfo.getRow1(),plcCmdInfo.getColumn1());
log.error("detectBestBarCode:{}",trayCode);
trayCode = "识别异常";
trayCheck = Boolean.FALSE;
}else {
trayCheck = wmsTrayCode.equals(trayCode);
//扫货物
if(configProperties.getScanCodeMode().getGoods() == 2) {
log.info("扫码类型:" + configProperties.getScanCodeMode().getTray());
//托盘使用sick扫码枪
SensorGun sensorGun = sensorService.getSensorByPlc(street.getId(), plcCmdInfo.getLeftRight1());
if (sensorGun == null) {
trayCode = "扫码枪识别异常";
trayGoodCheck = Boolean.FALSE;
log.error("no sensor gun config in database ,street id:{},direction:{}", street.getId(), plcCmdInfo.getLeftRight1());
} else {
trayCode = SickSocket.readOCR(sensorGun.getIp(), sensorGun.getPort());
log.info("sensor tray code:{}", trayCode);
if ("".equals(wmsTrayCode)) {
//托盘码为空,无货物
//只要扫码枪未识别出条码,即认为盘点正确
if (StringUtils.isEmpty(trayCode) || trayCode.equals("NoRead")) {
trayCode = "";
trayGoodCheck = Boolean.TRUE;
} else {
trayCode = "扫码枪识别异常";
trayGoodCheck = Boolean.FALSE;
log.warn("sick ocr error:{}", trayCode);
}
} else {
if (StringUtils.isEmpty(trayCode) || trayCode.equals("NoRead")) {
trayCode = "扫码枪识别异常";
trayGoodCheck = Boolean.FALSE;
log.warn("sick ocr error:{}", trayCode);
} else {
//扫到就认为正常
trayGoodCheck = Boolean.TRUE;
}
}
}
}else if(configProperties.getScanCodeMode().getGoods() == 3){
Set<String> tags = new HashSet<>();
try {
RFIDCheck(plcCmdInfo, true);
Thread.sleep(1000 * configProperties.getRfid().getScanTime());
} catch (Exception e) {
e.printStackTrace();
} finally {
tags = RFIDStop(plcCmdInfo);
log.info("盘点rfid扫描结果" + tags);
}
if (tags !=null && tags.contains(wmsTrayCode)) {
//托盘码为空,无货物
//只要扫码枪未识别出条码,即认为盘点正确
trayCode = wmsTrayCode;
trayGoodCheck = Boolean.TRUE;
} else {
trayCode = trayCode+ "扫码枪识别异常";
trayGoodCheck = Boolean.FALSE;
log.warn("rfid error:{}", trayCode);
}
}
log.info("code:{}",scanCode);
OrderInfo orderInfo = new OrderInfo(street, plcCmdInfo, 1, cmdCode);
Stock stock = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(orderInfo.getStreetId(), plcCmdInfo.getLeftRight1(), orderInfo.getSeparation(), orderInfo.getRow(), orderInfo.getColumn());
String scanCode = null;
//货物使用球机扫码
log.info("code:{}", scanCode);
//核对异常
Integer status = 1;
//托盘和货物都正确
if(trayCheck && codeCheck){
if (trayCheck && trayGoodCheck ) {
status = 2;
}
if(stock == null){
stock = new Stock(null,null,plcCmdInfo.getOrderNum(),plcCmdInfo.getLotnum(),scanCode, null,null,wmsCode,null,null,wmsTrayCode,trayCode,orderInfo.getShelveId(),orderInfo.getRow(),orderInfo.getColumn(),status,null,null,path, LocalDateTime.now());
if (stock == null) {
stock = Stock.builder()
.checkNum(plcCmdInfo.getOrderNum())
.lotnum(plcCmdInfo.getLotnum())
.code(scanCode)
.wmsCode(wmsCode)
.wmsTrayCode(wmsTrayCode)
.trayCode(trayCode)
.streetId(orderInfo.getStreetId())
.direction(plcCmdInfo.getLeftRight1())
.side(orderInfo.getSeparation())
.row(orderInfo.getRow())
.column(orderInfo.getColumn())
.status(status)
.checkPic(path)
.exportTime(LocalDateTime.now()).build();
stockMapper.insert(stock);
}else {
} else {
stock.setStatus(status);
stock.setLotnum(plcCmdInfo.getLotnum());
stock.setExportTime(LocalDateTime.now());
@ -788,10 +847,12 @@ public class PlcService {
checkLog(stock);
// StockCheckRunnable stockCheckRunnable = new StockCheckRunnable(street,plcCmdInfo,cmdCode,stockMapper,path,checkLogMapper,configProperties.getScanCodeMode().getGoods(),wmsCode,wmsTrayCode,trayCode,trayCheck,configProperties,sensorGun);
// threadPoolExecutor.execute(stockCheckRunnable);
//还原相机
gyrateCameraByCode(cameraId, "C5");
long end = System.currentTimeMillis();
long s = end - startTime;
log.info("time:{}millisecond",s);
log.info("time:{}millisecond", s);
return true;
}
public void checkLog(Stock stock){
@ -827,6 +888,27 @@ public class PlcService {
}
}
}
/**
* rfid
*
* @param plcCmdInfo
* @param fromOrTo
*/
public void RFIDCheck(PlcCmdInfo plcCmdInfo, boolean fromOrTo) {
log.info("开启rfid");
Street street = streetService.getStreetByPlcId(plcCmdInfo.getPlcId());
if (street != null) {
//rfid不分左右rfid使用同一ip和端口依靠传递字符调整方向
RFID rfid = rfidService.getRFIDByPlc(street.getId());
if (rfid != null) {
if (fromOrTo) {
RFIDStart(rfid.getIp(), rfid.getPort(), street.getId(), plcCmdInfo.getLeftRight1());
} else
RFIDStart(rfid.getIp(), rfid.getPort(), street.getId(), plcCmdInfo.getLeftRight1());
}
}
}
public void RFIDStart(String ip, Integer port, Integer streetId, Integer direction) {
RFIDSocket rfidSocket = new RFIDSocket(ip, port);

@ -19,7 +19,7 @@ public class SickSocket {
private static final Logger tcpLogger = LoggerFactory.getLogger("sick");
public static void main(String[] args) {
String code = readOCR("192.168.5.10", 2002);
String code = readOCR("127.0.0.1", 2002);
System.out.println(code);
}

Loading…
Cancel
Save