From bc12b2f986a4b9b9c2a25cffb79dc8b7463124e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Mon, 24 Apr 2023 11:33:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/bpa/app/BusinessServer.java | 53 ++++++++++++++++ .../java/com/example/bpa/app/DeviceData.java | 1 + .../com/example/bpa/app/ModbusTcpServer.java | 36 +++++++++++ .../bpa/view/fragment/SystemSetFragment.java | 63 +++++++++---------- 4 files changed, 118 insertions(+), 35 deletions(-) create mode 100644 app/src/main/java/com/example/bpa/app/BusinessServer.java diff --git a/app/src/main/java/com/example/bpa/app/BusinessServer.java b/app/src/main/java/com/example/bpa/app/BusinessServer.java new file mode 100644 index 0000000..f901a83 --- /dev/null +++ b/app/src/main/java/com/example/bpa/app/BusinessServer.java @@ -0,0 +1,53 @@ +package com.example.bpa.app; + +import com.example.bpa.Model.IThread; +import com.example.bpa.db.QueryDB; +import com.example.bpa.helper.ThreadManager; +import com.example.bpa.view.mode.ResGoodsRecipe; + +import java.util.ArrayList; +import java.util.concurrent.ConcurrentLinkedQueue; + +public class BusinessServer { + private static volatile BusinessServer _instance; + + public static BusinessServer get() { + if (_instance == null) + _instance = new BusinessServer(); + return _instance; + } + + private BusinessServer() { + } + + ConcurrentLinkedQueue Commoditys = new ConcurrentLinkedQueue(); + + /** + * 添加配方 + * + * @param info 配方信息 + */ + public void AddCommodity(String info) { + Commoditys.offer(info); + } + + public void Start() { + ThreadManager.Get().StartLong("配方执行业务流程", true, new IThread() { + @Override + public void Run() throws InterruptedException { + while (Commoditys.size() > 0) { + Commoditys.poll(); + + ArrayList goods = QueryDB.GetGoodsSrecipeList(""); + } + Thread.sleep(1000); + } + + @Override + public void RunComplete() throws InterruptedException { + + } + }); + } + +} diff --git a/app/src/main/java/com/example/bpa/app/DeviceData.java b/app/src/main/java/com/example/bpa/app/DeviceData.java index df38ef7..dc34e4b 100644 --- a/app/src/main/java/com/example/bpa/app/DeviceData.java +++ b/app/src/main/java/com/example/bpa/app/DeviceData.java @@ -8,6 +8,7 @@ import com.example.bpa.helper.RTrig; import com.example.bpa.helper.ThreadManager; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; public class DeviceData { private static volatile DeviceData _instance; diff --git a/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java b/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java index bae8b59..145885a 100644 --- a/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java +++ b/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java @@ -230,6 +230,12 @@ public class ModbusTcpServer { public void onFailure(Throwable tr) { MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); callback.onFailure(tr.toString()); + try { + Thread.sleep(3000); + WriteShort(Address, Value, callback); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } @Override @@ -253,6 +259,12 @@ public class ModbusTcpServer { public void onFailure(Throwable tr) { MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); callback.onFailure(tr.toString()); + try { + Thread.sleep(3000); + WriteBool(Address, Value, callback); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } @Override @@ -278,6 +290,12 @@ public class ModbusTcpServer { public void onFailure(Throwable tr) { MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); callback.onFailure(tr.toString()); + try { + Thread.sleep(3000); + WriteFloat(Address, Value, callback); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } @Override @@ -301,6 +319,12 @@ public class ModbusTcpServer { @Override public void onFailure(Throwable tr) { MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); + try { + Thread.sleep(3000); + WriteShort(Address, Value); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } @Override @@ -322,6 +346,12 @@ public class ModbusTcpServer { @Override public void onFailure(Throwable tr) { MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); + try { + Thread.sleep(3000); + WriteBool(Address, Value); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } @Override @@ -345,6 +375,12 @@ public class ModbusTcpServer { @Override public void onFailure(Throwable tr) { MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",Value=" + Value + ",msg:" + tr.toString()); + try { + Thread.sleep(3000); + WriteFloat(Address, Value); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } @Override diff --git a/app/src/main/java/com/example/bpa/view/fragment/SystemSetFragment.java b/app/src/main/java/com/example/bpa/view/fragment/SystemSetFragment.java index 9aad13a..71acffb 100644 --- a/app/src/main/java/com/example/bpa/view/fragment/SystemSetFragment.java +++ b/app/src/main/java/com/example/bpa/view/fragment/SystemSetFragment.java @@ -12,6 +12,7 @@ import android.view.ViewGroup; import android.widget.Button; import com.example.bpa.Model.IMessageLogNotify; +import com.example.bpa.Model.IReadCallBack; import com.example.bpa.Model.IThread; import com.example.bpa.R; import com.example.bpa.app.ModbusTcpServer; @@ -63,7 +64,7 @@ public class SystemSetFragment extends Fragment { new Thread(new Runnable() { @Override public void run() { - ModbusTcpServer.get().Connect("192.168.1.14", 502); + ModbusTcpServer.get().Connect("192.168.1.9", 502); } }).start(); } @@ -76,41 +77,33 @@ public class SystemSetFragment extends Fragment { ThreadManager.Get().StartLong("数据读取监听", true, new IThread() { @Override public void Run() throws InterruptedException { -// ModbusTcpServer.get().ReadShort(0, 3, new IReadCallBack() { -// @Override -// public void onSuccess(short[] shorts) { -// for (int i = 0; i < shorts.length; i++) { -// MessageLog.ShowInfo("Shorts[" + i + "]=" + shorts[i]); -// } -// } -// }); -// -// ModbusTcpServer.get().ReadFloat(10, 3, new IReadCallBack() { -// @Override -// public void onSuccess(float[] floats) { -// for (int i = 0; i < floats.length; i++) { -// MessageLog.ShowInfo("Floats[" + i + "]=" + floats[i]); -// } -// } -// }); -// -// ModbusTcpServer.get().ReadBool(0, 3, new IReadCallBack() { -// @Override -// public void onSuccess(boolean[] booleans) { -// for (int i = 0; i < booleans.length; i++) { -// MessageLog.ShowInfo("Booleans[" + i + "]=" + booleans[i]); -// } -// } -// }); - - MessageLog.ShowInfo("开始执行"); - boolean[] bools = new boolean[10]; - for (int i = 0; i < 20; i++) { - bools[i] = true; - } - + ModbusTcpServer.get().ReadShort("0", 3, new IReadCallBack() { + @Override + public void onSuccess(short[] shorts) { + for (int i = 0; i < shorts.length; i++) { + MessageLog.ShowInfo("Shorts[" + i + "]=" + shorts[i]); + } + } + }); + + ModbusTcpServer.get().ReadFloat("10", 3, new IReadCallBack() { + @Override + public void onSuccess(float[] floats) { + for (int i = 0; i < floats.length; i++) { + MessageLog.ShowInfo("Floats[" + i + "]=" + floats[i]); + } + } + }); + + ModbusTcpServer.get().ReadBool("0", 3, new IReadCallBack() { + @Override + public void onSuccess(boolean[] booleans) { + for (int i = 0; i < booleans.length; i++) { + MessageLog.ShowInfo("Booleans[" + i + "]=" + booleans[i]); + } + } + }); Thread.sleep(3000); - } @Override