古井使用自身tcp服务

bozhou-古井贡酒
LAPTOP-S9HJSOEB\昊天 2 years ago
parent 8b8051fc35
commit 2234842c28

@ -1,6 +1,5 @@
package com.zhehekeji.web.config;
import io.lettuce.core.dynamic.annotation.Value;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@ -46,12 +45,13 @@ public class ConfigProperties {
private VisualSense visualSense;
private Integer orderTest = 0;
private String productDoc;
private List<SmokeBoxType> smokeBoxTypeList;
private List<SmokeBoxType> smokeBoxType;
@Data
public static class SmokeBoxType{
private Integer type= 1;
private String name= "古20";
private String type= "";
private String name= "";
private String code= "";
private Integer numOfLayers= 1;
private Integer numLayers= 6;
}

@ -233,8 +233,17 @@ public class PlcService {
Street street = streetMapper.selectById(order.getStreetId());
//关闭光源
streetController.closeStreetLightSource(street.getId());
Thread thread = new Thread(()->{
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
streetController.closeStreetLightSource(street.getId());
});
thread.start();
LocalDateTime endDownLoadTime = endTime.plusSeconds(5);
Duration duration = Duration.between(order.getStartTime(), endDownLoadTime);
@ -254,6 +263,8 @@ public class PlcService {
}
public void orderStopByWarn(String orderNum) {
Order order = orderMapper.getOneByOrderNum(orderNum);
if (order == null) {
@ -716,9 +727,7 @@ public class PlcService {
//核对异常
Integer status = 1;
//托盘和货物都正确
if (algorithmPojo != null && algorithmPojo.getResult() != null && algorithmPojo.getResult() == 1
&& algorithmPojo.getGoodsNumber() != null && algorithmPojo.getGoodsNumber().equals(algorithmPojo.getGoodsNumberResult())
&& algorithmPojo.getGoodsType() != null && algorithmPojo.getGoodsType().equals(algorithmPojo.getGoodsTypeResult())) {
if (algorithmPojo != null && algorithmPojo.getResult() != null && algorithmPojo.getResult() == 1) {
status = 2;
}
if (stock == null) {

@ -373,7 +373,8 @@ public class StockService {
Street street = streetService.getStreetByPlcId(stockCheckSearch.getSRMNumber());
Stock stock = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(street.getId(),stockCheckSearch.getDirection(),stockCheckSearch.getSeparation(),stockCheckSearch.getRow(),stockCheckSearch.getColumn());
if(stock != null){
String ip ="http://"+ street.getPlcIp()+":9009/pic/"+stock.getCode()+"/"+stock.getLotnum()+"/"+stock.getLotnum()+"/";
String ip ="http://"+ street.getPlcIp()+":9009/pic/"+stock.getCheckNum();
stock.setSidePic1(String.format("%s_1.JPEG",ip));
stock.setSidePic2(String.format("%s_5.JPEG",ip));
stock.setSidePic3(String.format("%s_6.JPEG",ip));
@ -394,7 +395,7 @@ public class StockService {
Stock stock = stockInfo(stockCheck);
Assert.isTrue(stock != null && stock.getId() != null, "该货位暂时没有记录");
Integer oldStatus = stock.getStatus();
Assert.isTrue( StockStatus.PENDING.getStatus().equals(oldStatus) || StockStatus.ERROR.getStatus().equals(oldStatus), "无需核对");
//Assert.isTrue( StockStatus.PENDING.getStatus().equals(oldStatus) || StockStatus.ERROR.getStatus().equals(oldStatus), "无需核对");
log.info("check stock correct, street_id:{},direction:{},side:{},row:{},column:{}", stockCheck.getStreetId(),stockCheck.getDirection(),stockCheck.getSide(), stockCheck.getRow(), stockCheck.getColumn());
stock.setStatus(StockStatus.MANUAL.getStatus());
@ -473,6 +474,15 @@ public class StockService {
}
}
Street street = streetMapper.selectById(stock.getStreetId());
String ip ="http://"+ street.getPlcIp()+":9009/pic/"+stock.getCheckNum();
stock.setSidePic1(String.format("%s_1.JPEG",ip));
stock.setSidePic2(String.format("%s_5.JPEG",ip));
stock.setSidePic3(String.format("%s_6.JPEG",ip));
stock.setSidePic4(String.format("%s_4.JPEG",ip));
stock.setTopPic1(String.format("%s_2.JPEG",ip));
stock.setTopPic2(String.format("%s_3.JPEG",ip));
return stock;
}

@ -0,0 +1,125 @@
package com.zhehekeji.web.service.algorithm;
import com.zhehekeji.web.config.ConfigProperties;
import com.zhehekeji.web.entity.AlgorithmPojo;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
import java.net.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
public class AlgorithmClint {
AlgorithmPojo clint(String ip, Integer port, AlgorithmPojo algorithmPojo, List<ConfigProperties.SmokeBoxType> list) {
try {
Socket socket = new Socket();
Map<String, ConfigProperties.SmokeBoxType> map = list.stream().collect(Collectors.toMap(ConfigProperties.SmokeBoxType::getType, k->k));
socket.connect(new InetSocketAddress(ip, port), 5000);
System.out.println("Connected to server");
socket.setSoTimeout(10000);
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
//修改全局变量
updateTaskId(reader,writer,algorithmPojo);
Thread.sleep(600);
//获取结果并拍照
String message = "trigger:1";
writer.write(message);
writer.flush();
System.out.println("Sent message to server: " + message);
StringBuilder response =new StringBuilder();
// 接收服务器的响应
while (true){
char[] lengthBytes = new char[1];
reader.read(lengthBytes);
if (lengthBytes[0] == ';') {
break;
}
response.append(lengthBytes[0]);
}
if (response != null) {
System.out.println("Server response: " + response);
log.info("respon:{}",response.toString());
} else {
System.out.println("No response from server. Closing connection.");
}
String respon = response.toString();
respon = respon.replace(";","");
String[] strings = respon.toString().split( ",");
Map<String, Integer> charCountMap = new HashMap<>();
// 统计每个字符的数量
for (String c : strings) {
charCountMap.put(c, charCountMap.getOrDefault(c, 0) + 1);
}
// 找出数量最多的字符及其次数
String mostFrequentChar = null;
int len = 0;
for (Map.Entry<String, Integer> entry : charCountMap.entrySet()) {
if (entry.getValue() > len) {
mostFrequentChar = entry.getKey();
len = entry.getValue();
}
}
len = len-1;
ConfigProperties.SmokeBoxType smokeBoxType = map.get(mostFrequentChar);
//计算个数
if (smokeBoxType != null && smokeBoxType.getNumOfLayers() != 0 && smokeBoxType.getNumLayers() != 0 ){
algorithmPojo.setGoodsTypeResult(smokeBoxType.getCode());
algorithmPojo.setGoodsNumberResult( len / smokeBoxType.getNumOfLayers() * smokeBoxType.getNumLayers());
}
if(algorithmPojo.getGoodsType().equals(algorithmPojo.getGoodsTypeResult())){
algorithmPojo.setResult(1);
}else {
algorithmPojo.setResult(0);
}
// 关闭连接
socket.close();
System.out.println("Connection closed");
} catch (IOException e) {
algorithmPojo.setResult(0);
log.error("连接失败:"+ip,e);
} catch (InterruptedException e) {
algorithmPojo.setResult(0);
}catch (Exception e){
algorithmPojo.setResult(0);
log.error("连接失败:"+ip,e);
}
return algorithmPojo;
}
public static void main(String[] args) {
System.out.println(4/1*13);
}
void updateTaskId(BufferedReader reader ,BufferedWriter writer ,AlgorithmPojo algorithmPojo){
try {
String message = "taskId:"+algorithmPojo.getTaskId();
writer.write(message);
writer.flush();
System.out.println("Sent message to server: " + message);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

@ -32,11 +32,15 @@ public class AlgorithmService {
public static void main(String[] args) {
AlgorithmPojo algorithmPojo= new AlgorithmPojo();
algorithmPojo.setGoodsTypeResult("qqq");
algorithmPojo.setIp("12");
algorithmPojo.setPort(8083);
algorithmPojo.setIp("127.0.0.1");
algorithmPojo.setPort(8001);
algorithmPojo.setTaskId("8001");
AlgorithmService algorithmService = new AlgorithmService();
algorithmService.getGoodResult(algorithmPojo);
//algorithmService.getGoodResultTcp(algorithmPojo);
AlgorithmClint clint = new AlgorithmClint();
clint.clint(algorithmPojo.getIp(),8001,algorithmPojo,new ArrayList<>());
System.out.println(algorithmPojo);
@ -45,6 +49,12 @@ public class AlgorithmService {
}
public AlgorithmPojo getGoodResultTcp(AlgorithmPojo algorithmPojo) {
AlgorithmClint clint = new AlgorithmClint();
clint.clint(algorithmPojo.getIp(),9040,algorithmPojo,configProperties.getSmokeBoxType());
return algorithmPojo;
}
public AlgorithmPojo getGoodResult(AlgorithmPojo algorithmPojo) {
String url = "http://"+algorithmPojo.getIp()+":"+algorithmPojo.getPort()+configProperties.getVisualSense().getUrl();
@ -63,9 +73,7 @@ public class AlgorithmService {
body = restTemplate.postForEntity(url, algorithmPojo, String.class);
algorithmPojo = JSONObject.parseObject(body.getBody(), AlgorithmPojo.class);
if( algorithmPojo.getGoodsTypeResult().equals(algorithmPojo.getGoodsType())){
algorithmPojo.setResult(1);
}
System.out.println(body);
}catch (RestClientException e){
log.error("未连接上堆垛机"+e);
@ -76,10 +84,11 @@ public class AlgorithmService {
}
return algorithmPojo;
}
public AlgorithmPojo getGoodResult(Street street, KsecDataInfo dataInfo ) {
AlgorithmPojo algorithmPojo = AlgorithmPojo.buildAlgorithmPojo(street, dataInfo);
if(configProperties.getVisualSense().getAble()) {
algorithmPojo = getGoodResult(algorithmPojo);
algorithmPojo = getGoodResultTcp(algorithmPojo);
}else {
algorithmPojo.setResult(1);
algorithmPojo.setGoodsNumberResult(algorithmPojo.getGoodsNumber());

@ -110,11 +110,12 @@ asyncExecutorThread:
#订单测试
orderTest: 1
#品规文档
productDoc: "C:/Users/昊天/Desktop/新建 文本文档 (3).txt"
productDoc: "C:/Users/昊天/Desktop/新建文本文档 (3).txt"
smokeBoxType:
- type: 1
name: 古20
code: "125425"
#用于视觉的一层个数
numOfLayers: 1
#用于计算总数的个数

Loading…
Cancel
Save