From f9e2d3130f7bc3bb5230515703b0342e094af374 Mon Sep 17 00:00:00 2001
From: LSH
Date: 星期三, 20 三月 2024 15:38:59 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/SiemensDevpThread.java | 141 ++++++++++++++++++++++++++++++++++++++--------
1 files changed, 116 insertions(+), 25 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index 0570905..4667bf6 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -125,6 +125,11 @@
write((StaProtocol)task.getData());
read();
break;
+ // 鍐欐暟鎹� ID+鐩爣绔�
+ case 4:
+ writeAgvOk((StaProtocol)task.getData());
+ read();
+ break;
/* case 3:
write2((StaProtocol)task.getData());
read();
@@ -229,14 +234,42 @@
}
}
+ OperateResultExOne<byte[]> resultAgvAndPlc = siemensS7Net.Read("DB102.0", (short) 30);
+ if (resultAgvAndPlc.IsSuccess) {
+ for (int i = 0; i < staNoSize; i++) {
+ int sign =(i+2)/2-1;
+ if ((i+2)%2!=0){
+ Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
+ StaProtocol staProtocol = station.get(siteId);
+ if (null == staProtocol) {
+ staProtocol = new StaProtocol();
+ staProtocol.setSiteId(siteId);
+ station.put(siteId, staProtocol);
+ }
+ staProtocol.setAgvStartPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6+4)); // 鍏佽鍙栬揣
+ staProtocol.setAgvStartPlace((short)0); // 鍏佽鏀捐揣
+ continue;
+ }
+ Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
+ StaProtocol staProtocol = station.get(siteId);
+ if (null == staProtocol) {
+ staProtocol = new StaProtocol();
+ staProtocol.setSiteId(siteId);
+ station.put(siteId, staProtocol);
+ }
+ staProtocol.setAgvStartPick(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6)); // 鍏佽鍙栬揣
+ staProtocol.setAgvStartPlace(siemensS7Net.getByteTransform().TransInt16(resultAgvAndPlc.Content, sign*6 + 2)); // 鍏佽鏀捐揣
+ }
+ }
+
if (slave.getId() == 1) {
//鏉$爜
//Thread.sleep(200);
- OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.840.0", (short) 60);
+ OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.840.0", (short) 32);
if (result2.IsSuccess) {
for (int i = 0; i < 4; i++) {
- String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, i * 10, 8, "UTF-8");
+ String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, i * 8, 8, "UTF-8");
BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
if (!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
barcodeThread.setBarcode(barcode);
@@ -324,6 +357,87 @@
/**
* 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏�
*/
+ private void writeAgvOk(StaProtocol staProtocol) throws InterruptedException {
+ if (null == staProtocol) {
+ return;
+ }
+ ArrayList<Integer> staNos = getStaNo();
+ int index = staNos.indexOf(staProtocol.getSiteId());
+ if (staProtocol.getAgvTypeSign()==0 || staProtocol.getAgvTypeSign()==2 ){ //0鍙栬揣
+ switch (staProtocol.getSiteId()){
+ case 100:
+ index=32;
+ break;
+ case 101:
+ index=34;
+ break;
+ case 102:
+ index=38;
+ break;
+ case 103:
+ index=40;
+ break;
+ case 104:
+ index=44;
+ break;
+ case 105:
+ index=46;
+ break;
+ case 106:
+ index=50;
+ break;
+ case 107:
+ index=52;
+ break;
+ default:
+ return;
+ }
+ }else {
+ switch (staProtocol.getSiteId()){
+ case 100:
+ index=30;
+ break;
+ case 102:
+ index=36;
+ break;
+ case 104:
+ index=42;
+ break;
+ case 106:
+ index=48;
+ break;
+ default:
+ return;
+ }
+ }
+
+ OperateResult write = null;
+ //浠诲姟涓嬪彂娆℃暟
+ int writeCount = 0;
+ do {
+ short textWrite = 1;// 浠诲姟瀹屾垚
+ if (staProtocol.getAgvTypeSign()>1){
+ textWrite = 0;// 浠诲姟澶嶄綅
+ }
+ write = siemensS7Net.Write("DB102." + index, textWrite);
+ if(write.IsSuccess){
+ writeCount=6;
+ }else {
+ writeCount++;
+ log.error("鍐欏叆杈撻�佺嚎鍙栨斁璐у畬鎴愬懡浠ゅ悗璇诲彇澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
+ }
+ }while (writeCount<5);
+
+ if (!write.IsSuccess) {
+ OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2}", slave.getId(), JSON.toJSON(staProtocol)));
+ log.error("鍐欏叆杈撻�佺嚎鍙栨斁璐у畬鎴愮珯鐐规暟鎹け璐ャ�傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={}", slave.getId(), JSON.toJSON(staProtocol));
+ } else {
+ OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆� 杈撻�佺嚎鍛戒护涓嬪彂 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol)));
+ log.info("杈撻�佺嚎鍙栨斁璐у畬鎴愬懡浠や笅鍙戠爜鍨涘畬鎴� 缁欒緭閫佺嚎鍐欎换鍔″畬鎴� [id:{}] >>>>> 鍛戒护涓嬪彂锛� {}", slave.getId(), JSON.toJSON(staProtocol));
+ }
+
+
+ }
private void write(StaProtocol staProtocol) throws InterruptedException {
if (null == staProtocol) {
return;
@@ -335,29 +449,6 @@
array[0] = staProtocol.getWorkNo();
array[1] = staProtocol.getStaNo();
// OperateResult write = siemensS7Net.Write("DB100." + index*4, array);
-
- //鏇存柊鍛戒护鏃ュ織
- CommandInfoLogService commandInfoLogService = SpringUtils.getBean(CommandInfoLogService.class);
- CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class);
- CommandInfo commandInfo = commandInfoService.selectById(staProtocol.getCommandId());
- CommandInfoLog commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class);
- commandInfoLog.setId(null);
-// CommandInfoLog commandInfoLog = new CommandInfoLog();
-// if (commandInfo != null) {
-// commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class);
-// commandInfoLog.setId(null);
-// }else {
-// Date now = new Date();
-// commandInfoLog.setCommand(JSON.toJSONString(staProtocol));
-// commandInfoLog.setCommandStatus(3);
-// commandInfoLog.setStartTime(now);
-// commandInfoLog.setExecuteTime(now);
-// commandInfoLog.setCompleteTime(now);
-// commandInfoLog.setDevice(SlaveType.Devp.toString());
-// commandInfoLog.setWrkNo(9999);
-// commandInfoLog.setTaskNo("9999");
-// commandInfoLog.setCommandDesc("鎵嬪姩鍛戒护");
-// }
OperateResult writeResult;
//浠诲姟涓嬪彂娆℃暟
--
Gitblit v1.9.1