From db1edf54ea55cf01f8794627b9e38a549afb951f Mon Sep 17 00:00:00 2001 From: wu <731351411@qq.com> Date: 星期一, 27 十一月 2023 09:15:22 +0800 Subject: [PATCH] 更新理片笼逻辑 --- springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java | 241 +++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 198 insertions(+), 43 deletions(-) diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java b/springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java index b8382f2..ec56e0c 100644 --- a/springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java +++ b/springboot-vue3/src/main/java/com/example/springboot/component/PlcHold.java @@ -1,66 +1,221 @@ package com.example.springboot.component; +import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; -import javax.websocket.Session; +import org.apache.ibatis.javassist.compiler.ast.Symbol; +import org.springframework.beans.factory.annotation.Autowired; -import cn.hutool.json.JSONArray; -import cn.hutool.json.JSONObject; +import com.example.springboot.service.JdbcConnections; +import com.example.springboot.service.SpianService; +import com.example.springboot.entity.Glass; +import com.example.springboot.entity.north_glass_buffer1; +import com.example.springboot.mapper.AlarmMapper; +import com.example.springboot.mapper.SpianMapper; public class PlcHold extends Thread { + + private AlarmMapper alarmMapper; + + @Autowired + private JdbcConnections jdbcConnections; + private SpianMapper spianMapper; + private SpianService spianService; + @Override public void run() { + boolean inglassbegin = false; + boolean outglassbegin = false; while (this != null) { try { - Thread.sleep(10000); + Thread.sleep(1000); } catch (InterruptedException e) { - // TODO Auto-generated catch block + // \\ TODO Auto-generated catch block e.printStackTrace(); } - List<Boolean> bitlist = S7control.getinstance().ReadBits("DB2.0.0", 100); + spianService = WebSocketServer.applicationContext.getBean(SpianService.class); + spianMapper = WebSocketServer.applicationContext.getBean(SpianMapper.class); + jdbcConnections = WebSocketServer.applicationContext.getBean(JdbcConnections.class); - List<Short> paramlist = S7control.getinstance().ReadWord("DB100.6", 1); + String str = "Hello"; + char[] charArray = new char[str.length()]; + for (int i = 0; i < str.length(); i++) { + charArray[i] = str.charAt(i); + } + System.out.println(charArray); + // spianService.selectout("1145"); + // spianService.selectAll("11"); + // spianService.selectAll2(); + // 澧炲姞闃熷垪琛ㄦ暟鎹� + // spianMapper.insertqueue("1",1,1500); + + // 鏍规嵁鐜荤拑id鑾峰彇璁㈠崟鍙�,鍗曠嫭鏁版嵁婧� + // try { + + // north_glass_buffer1 glass = jdbcConnections.selectGlass(112); + + // // System.out.println(glass.getOrderId()); + // } catch (SQLException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } + + // 鍒ゆ柇杩涚墖璇锋眰 + List<Short> datas1List = S7control.getinstance().ReadWord("DB106.24", 1);// 鑾峰彇prc杩涚墖璇锋眰鏁版嵁 + List<Short> datas1ListState = S7control.getinstance().ReadWord("DB106.8", 1);// 鑾峰彇杩涚墖杞︾姸鎬� + List<Short> datas1ListState2 = S7control.getinstance().ReadWord("DB105.12", 1);// 鑾峰彇杩涚墖杞︿换鍔℃槸鍚﹀惎鍔� + + if (datas1List != null && datas1ListState != null) { + + // 鑾峰彇prc杩涚墖璇锋眰鏁版嵁 + boolean exist = datas1List.contains((short) 1); + // 鑾峰彇杩涚墖杞︾姸鎬� + boolean exist1 = datas1ListState.contains((short) 0); + // 鍒ゆ柇杩涚墖杞︿换鍔℃槸鍚﹀惎鍔� + boolean exist2 = datas1ListState2.contains((short) 1); + + String glassid = ""; + StringBuilder strId = new StringBuilder(); + StringBuilder writedstrId = new StringBuilder(); + + if (!inglassbegin & !exist1)// 褰撹繘鐗囪溅涓嶇┖闂叉椂 + { + inglassbegin = true; + } + if (inglassbegin & exist1)// 褰撹繘鐗囪溅绌洪棽鏃� + { + inglassbegin = false; + spianMapper.Updatetask(1, 0);// 绔嬪嵆缁撴潫鏁版嵁搴撹〃涓殑涓婄墖浠诲姟 + spianMapper.UpdataAddCageState(1, 2); + } + // 杩涚墖璇锋眰涓�1鏃� + if (exist == true) { + // 褰撹繘鐗囪溅绌洪棽鏃� + if (exist1 == true) { + // 鑾峰彇宸蹭笅鍙戠殑杩涚墖id 涓巔lc璇锋眰鐨刬d浣滄瘮杈� + byte[] writedglassidbytes = S7control.getinstance().ReadByte("DB105.16", 13); + if (writedglassidbytes != null) { // + // 鑾峰彇鐜荤拑id + for (byte iditem : writedglassidbytes) { + writedstrId.append(iditem); + } + } + // 鑾峰彇杩涚墖id + byte[] datas1ListID = S7control.getinstance().ReadByte("DB106.26", 13); + if (datas1ListID != null) { + // 鑾峰彇鐜荤拑id + for (byte list1 : datas1ListID) { + strId.append(list1); + + } + if (!writedstrId.toString().equals(strId.toString())) // 宸茬粡涓嬪彂鐨刬d涓巔lc璇锋眰鐨刬d涓嶄竴鏍锋椂锛岃涓轰笉鏄噸澶嶇殑浠诲姟锛屾墠鎵ц涓嬪彂浠诲姟鎸囦护 + { + + int glasslimit = 1;// 鍒ゆ柇鏄惁鏄鐗囦笂鐗� + if (glasslimit == 1) { + spianService.selectAll(strId.toString()); + } else { + spianService.selectAll(strId.toString()); + } + S7control.getinstance().WriteByte("DB105.16", datas1ListID);// 娲惧彂杩涚墖id + + } + // spianService.selectAll(Short.parseShort(strId.toString())); + } + + } + // System.out.println(exist); + } + // 涓嬪彂浠诲姟鍚庡皢浠诲姟鍚姩鏀逛负0 + if (exist1 == false) { // 杩涚墖杞﹀繖纰屾椂 + if (exist2 == true) { // 浠诲姟宸插惎鍔ㄦ椂 + S7control.getinstance().WriteWord("DB105.12", (short) 0);// 杩涚墖浠诲姟鍚姩鏀逛负0 + } + } + } + + List<Short> outlist = S7control.getinstance().ReadWord("DB106.20", 1); // 鍑虹墖杞︾姸鎬� + List<Short> outlist1 = S7control.getinstance().ReadWord("DB105.14", 1); // 鍑虹墖浠诲姟鏄惁鍚姩 + StringBuilder writedstrIdOut = new StringBuilder(); + // 鑾峰彇宸蹭笅鍙戠殑鍑虹墖id + byte[] writedglassidbytesOut = S7control.getinstance().ReadByte("DB105.30", 13); + if (writedglassidbytesOut != null) { + // 鑾峰彇鐜荤拑id + for (byte iditem : writedglassidbytesOut) { + writedstrIdOut.append((char) iditem); + } + } + // 鑾峰彇BO1鏁版嵁 + StringBuilder queueid1 = spianService.queGlassid("DB103.DBB32"); + // 鑾峰彇BO2鏁版嵁 + StringBuilder queueid2 = spianService.queGlassid("DB103.DBB46"); + if (queueid1 != null) { + // 鍐欏叆B01鐨勬暟鎹埌涓婄墖闃熷垪琛� + spianMapper.insertqueue(queueid1.toString(), 1, 0); + } + if (queueid2 != null) { + // 鍐欏叆B02鐨勬暟鎹埌涓婄墖闃熷垪琛� + spianMapper.insertqueue(queueid2.toString(), 2, 0); + } + + // 鍑虹墖浠诲姟//////////////////////////////// + boolean outstate = false;// 鍑虹墖杞︾┖闂插垽鏂� + boolean outstate1 = false;// 鍑虹墖杞︿换鍔℃槸鍚﹀惎鍔� + if (outlist != null && outlist1 != null) { + // 鍒ゆ柇鎸夎鍗曞嚭鐗� + outstate = outlist.contains((short) 0);// 鍑虹墖杞︾┖闂插垽鏂� + outstate1 = outlist1.contains((short) 1);// 鍑虹墖杞︿换鍔℃槸鍚﹀惎鍔� + + north_glass_buffer1 glass = spianMapper.SelectDBOut();// 鍒ゆ柇鏄惁鏈夎皟鎷ㄥ悗鐨勫嚭鐗囦换鍔℃湭瀹屾垚 + + if (!outglassbegin & !outstate)// 褰撲换鍔¤繕鏈紑濮嬶紝涓斿嚭鐗囪溅涓嶇┖闂叉椂,浠诲姟鐘舵�佹敼涓哄紑濮� + { + outglassbegin = true; + } + if (outglassbegin & outstate)// 褰撲换鍔″紑濮嬩笖鍑虹墖杞︾┖闂叉椂 + { + outglassbegin = false; + spianMapper.UpdatetaskOut(); // 瀹屾垚涓婁竴娆″嚭鐗囨垨鑰呰皟搴︿换鍔� + spianMapper.UpdataAddCageState(0, 3);// 灏嗗嚭鐗囦腑鐨勬牸瀛愮姸鎬佹敼鎴�0 + } + + if (outstate == true & glass.getbarcode() != null) { // 褰撳嚭鐗囪溅绌洪棽涓旀湁鍑虹墖浠诲姟寰呭畬鎴愭椂 + // 鍒ゆ柇鏈変袱涓嚭鐗囨垨璋冩嫧浠诲姟鏃跺苟涓斿嚭鐗噄d鍜屾湭瀹屾垚鐨勫嚭鐗囦换鍔d涓嶄竴鏍锋椂鎵ц鍑虹墖 + if (glass.getId() == 2 & !writedstrIdOut.toString().equals(glass.getbarcode().toString())) { + spianService.selectout2(glass.getbarcode().toString()); + } + } + // 鍒ゆ柇褰撳墠鏄惁鏈夋湭鎵ц鐨勪换鍔� + int outnum = spianMapper.SelectOutSliceshu(); + if (outnum == 0) { + // 鍒ゆ柇閾濇鍑虹墖闃熷垪琛ㄦ槸鍚︽湁寰呭嚭鐗囩殑鐜荤拑 + String outglassid = spianMapper.SelectOutSlice(); + if (outglassid != null) { + spianService.selectout2(outglassid); + } + } + if (outstate == false) {// 涓嬪彂浠诲姟鍚庡皢浠诲姟鍚姩鏀逛负0//鍑虹墖杞︾┖闂插垽鏂� + if (outstate1 == true) { + S7control.getinstance().WriteWord("DB105.14", (short) 0);// 鍑虹墖浠诲姟鍚姩鏀逛负0 + } + } + } + + if (outstate == true) { // 鍑虹墖杞︾姸鎬佺┖闂叉椂 + Integer state = spianMapper.Selectoutstate(); + String orderid = spianMapper.SelectOrderout(); + + if (orderid != null && state == 0) { + spianService.selectout(orderid); + } + } // 鏌ヨ鏁版嵁搴� // 鎺ㄩ�佸埌鍓嶇 - // Parameter - JSONObject jsonObject = new JSONObject(); - jsonObject.append("params", new short[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, }); - WebSocketServer sendwServer = WebSocketServer.sessionMap.get("Parameter"); - if (sendwServer != null) { - sendwServer.sendMessage(jsonObject.toString()); - } - - // Action - // JSONObject jsonObject2 = new JSONObject(); - // jsonObject2.append("acion", - // new short[] { 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - // 1, 1, 1, 0, 0, }); - // WebSocketServer sendwServer2 = WebSocketServer.sessionMap.get("Action"); - // if (sendwServer2 != null) { - // sendwServer2.sendMessage(jsonObject2.toString()); - // } - - // Sign - JSONObject jsonObject3 = new JSONObject(); - jsonObject3.append("sig", - new short[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, - 1, }); - WebSocketServer sendwServer3 = WebSocketServer.sessionMap.get("Sign"); - if (sendwServer3 != null) { - sendwServer3.sendMessage(jsonObject3.toString()); - } - - // State - JSONObject jsonObject4 = new JSONObject(); - jsonObject4.append("sta", new short[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, }); - WebSocketServer sendwServer4 = WebSocketServer.sessionMap.get("State"); - if (sendwServer4 != null) { - sendwServer4.sendMessage(jsonObject4.toString()); - } - } } + } -- Gitblit v1.8.0