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

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

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

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

@ -1,6 +1,7 @@
package com.zhehekeji.web.service; package com.zhehekeji.web.service;
import codeDetector.BarcodeDetector; import codeDetector.BarcodeDetector;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhehekeji.common.util.PathUtil; import com.zhehekeji.common.util.PathUtil;
import com.zhehekeji.core.pojo.Result; import com.zhehekeji.core.pojo.Result;
@ -24,6 +25,7 @@ import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashSet; import java.util.HashSet;
@ -668,112 +670,169 @@ public class PlcService {
} }
String path = PathUtil.createFileNameByRowColumn("jpg",cameraId,plcCmdInfo.getRow1(),plcCmdInfo.getColumn1()); String path = PathUtil.createFileNameByRowColumn("jpg", cameraId, plcCmdInfo.getRow1(), plcCmdInfo.getColumn1());
//拍照暂停1s再拍
try { 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; String trayCode = null;
Boolean trayCheck = Boolean.TRUE; Boolean trayCheck = Boolean.TRUE;
//如果是用扫码枪 扫 托盘码,就直接扫 //扫托盘码
//if(configProperties.getScanCodeMode().getTray() == 2){ if(configProperties.getScanCodeMode().getTray() == 2) {
SensorGun sensorGun = sensorService.getSensorByPlc(street.getId(),plcCmdInfo.getLeftRight1()); log.info("扫码类型:" + configProperties.getScanCodeMode().getTray());
if(plcCmdInfo.getSeparation1() == 1 && configProperties.getScanCodeMode().getTray() == 2){
//托盘使用sick扫码枪 //托盘使用sick扫码枪
SensorGun sensorGun = sensorService.getSensorByPlc(street.getId(), plcCmdInfo.getLeftRight1());
if(sensorGun == null){ if (sensorGun == null) {
trayCode = "识别异常"; trayCode = "扫码枪未配置";
trayCheck = Boolean.FALSE; trayCheck = Boolean.FALSE;
log.error("no sensor gun config in database ,street id:{},direction:{}",street.getId(),plcCmdInfo.getLeftRight1()); log.error("no sensor gun config in database ,street id:{},direction:{}", street.getId(), plcCmdInfo.getLeftRight1());
}else { } else {
trayCode = SickSocket.readOCR(sensorGun.getIp(),sensorGun.getPort()); trayCode = SickSocket.readOCR(sensorGun.getIp(), sensorGun.getPort());
log.info("sensor tray code:{}",trayCode); log.info("sensor tray code:{}", trayCode);
if("".equals(wmsTrayCode)){ if ("".equals(wmsTrayCode)) {
//托盘码为空,无货物 //托盘码为空,无货物
//只要扫码枪未识别出条码,即认为盘点正确 //只要扫码枪未识别出条码,即认为盘点正确
if(StringUtils.isEmpty(trayCode) || trayCode.equals("NoRead")){ if (StringUtils.isEmpty(trayCode) || trayCode.equals("NoRead")) {
trayCode = ""; trayCode = "无货物";
trayCheck = Boolean.TRUE; trayCheck = Boolean.TRUE;
}else { } else {
trayCode = "识别异常"; trayCode = "扫码枪识别异常";
trayCheck = Boolean.FALSE; trayCheck = Boolean.FALSE;
log.warn("sick ocr error:{}",trayCode); log.warn("sick ocr error:{}", trayCode);
} }
}else { } else {
if(StringUtils.isEmpty(trayCode) || trayCode.equals("NoRead")){ if (StringUtils.isEmpty(trayCode) || trayCode.equals("NoRead")) {
trayCode = "识别异常"; trayCode = "扫码枪识别异常";
trayCheck = Boolean.FALSE; trayCheck = Boolean.FALSE;
log.warn("sick ocr error:{}",trayCode); log.warn("sick ocr error:{}", trayCode);
}else { } else {
trayCheck = wmsTrayCode.equals(trayCode); //扫到就认为正常
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); Boolean trayGoodCheck = Boolean.TRUE;
Stock stock = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(orderInfo.getStreetId(),orderInfo.getLeftRight(),orderInfo.getRow(),orderInfo.getColumn());
String scanCode = null;
Boolean codeCheck = Boolean.TRUE;
Boolean trayCodeCheck = Boolean.TRUE;
//货物使用球机扫码
if(configProperties.getScanCodeMode().getTray() == 2 && plcCmdInfo.getSeparation1() == 2){ //扫货物
//托盘使用球机扫码 if(configProperties.getScanCodeMode().getGoods() == 2) {
if("".equals(wmsTrayCode)){ log.info("扫码类型:" + configProperties.getScanCodeMode().getTray());
//空货物的处理 //托盘使用sick扫码枪
//如果系统货物为空,则只要扫码识别未出结果,就认为无货物 SensorGun sensorGun = sensorService.getSensorByPlc(street.getId(), plcCmdInfo.getLeftRight1());
trayCode = BarcodeDetector.detectBestCodeUntilOK(configProperties.getSavePath().getMediaPath()+path,configProperties.getScanCodeMode().getTrayCodeTypes()); if (sensorGun == null) {
log.info("tray code:{},sys trayCode:{}",trayCode,wmsTrayCode); trayCode = "扫码枪识别异常";
if(StringUtils.isEmpty(trayCode)|| trayCode.equals("Unrecognized")){ trayGoodCheck = Boolean.FALSE;
trayCheck = Boolean.TRUE; log.error("no sensor gun config in database ,street id:{},direction:{}", street.getId(), plcCmdInfo.getLeftRight1());
trayCode = ""; } else {
}else { trayCode = SickSocket.readOCR(sensorGun.getIp(), sensorGun.getPort());
trayCheck = wmsTrayCode.equals(trayCode); log.info("sensor tray code:{}", trayCode);
} if ("".equals(wmsTrayCode)) {
}else { //托盘码为空,无货物
trayCode = BarcodeDetector.detectBestCodeUntilOK(configProperties.getSavePath().getMediaPath()+path,configProperties.getScanCodeMode().getTrayCodeTypes()); //只要扫码枪未识别出条码,即认为盘点正确
if(StringUtils.isEmpty(trayCode)){ if (StringUtils.isEmpty(trayCode) || trayCode.equals("NoRead")) {
log.error("row:{},cloumn:{}",plcCmdInfo.getRow1(),plcCmdInfo.getColumn1()); trayCode = "";
log.error("detectBestBarCode:{}",trayCode); trayGoodCheck = Boolean.TRUE;
trayCode = "识别异常"; } else {
trayCheck = Boolean.FALSE; trayCode = "扫码枪识别异常";
}else { trayGoodCheck = Boolean.FALSE;
trayCheck = wmsTrayCode.equals(trayCode); 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; Integer status = 1;
//托盘和货物都正确 //托盘和货物都正确
if(trayCheck && codeCheck){ if (trayCheck && trayGoodCheck ) {
status = 2; status = 2;
} }
if(stock == null){ 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()); 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); stockMapper.insert(stock);
}else { } else {
stock.setStatus(status); stock.setStatus(status);
stock.setLotnum(plcCmdInfo.getLotnum()); stock.setLotnum(plcCmdInfo.getLotnum());
stock.setExportTime(LocalDateTime.now()); stock.setExportTime(LocalDateTime.now());
@ -788,10 +847,12 @@ public class PlcService {
checkLog(stock); checkLog(stock);
// StockCheckRunnable stockCheckRunnable = new StockCheckRunnable(street,plcCmdInfo,cmdCode,stockMapper,path,checkLogMapper,configProperties.getScanCodeMode().getGoods(),wmsCode,wmsTrayCode,trayCode,trayCheck,configProperties,sensorGun); // StockCheckRunnable stockCheckRunnable = new StockCheckRunnable(street,plcCmdInfo,cmdCode,stockMapper,path,checkLogMapper,configProperties.getScanCodeMode().getGoods(),wmsCode,wmsTrayCode,trayCode,trayCheck,configProperties,sensorGun);
// threadPoolExecutor.execute(stockCheckRunnable); // threadPoolExecutor.execute(stockCheckRunnable);
//还原相机
gyrateCameraByCode(cameraId, "C5");
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
long s = end - startTime; long s = end - startTime;
log.info("time:{}millisecond",s); log.info("time:{}millisecond", s);
return true; return true;
} }
public void checkLog(Stock stock){ 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) { public void RFIDStart(String ip, Integer port, Integer streetId, Integer direction) {
RFIDSocket rfidSocket = new RFIDSocket(ip, port); RFIDSocket rfidSocket = new RFIDSocket(ip, port);

@ -19,7 +19,7 @@ public class SickSocket {
private static final Logger tcpLogger = LoggerFactory.getLogger("sick"); private static final Logger tcpLogger = LoggerFactory.getLogger("sick");
public static void main(String[] args) { 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); System.out.println(code);
} }

Loading…
Cancel
Save