From b604f2acfbb67c6d1c34c07abb390cf450c8aee6 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: Fri, 5 May 2023 11:31:07 +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 | 5 +- .../main/java/com/example/bpa/app/ICSApp.java | 4 +- .../com/example/bpa/app/ModbusTcpServer.java | 2 + .../example/bpa/view/from/yfpf_activity.java | 91 +++++++++---------- 4 files changed, 49 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/com/example/bpa/app/BusinessServer.java b/app/src/main/java/com/example/bpa/app/BusinessServer.java index 37b5720..6f25d9b 100644 --- a/app/src/main/java/com/example/bpa/app/BusinessServer.java +++ b/app/src/main/java/com/example/bpa/app/BusinessServer.java @@ -19,7 +19,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; public class BusinessServer { private static volatile BusinessServer _instance; - public static BusinessServer get() { + public static BusinessServer Get() { if (_instance == null) _instance = new BusinessServer(); return _instance; @@ -32,6 +32,7 @@ public class BusinessServer { * 商品制作队列 */ ConcurrentLinkedQueue Commoditys = new ConcurrentLinkedQueue(); + /** * 添加配方 * @@ -44,7 +45,7 @@ public class BusinessServer { /** * 订单制作线程 */ - public void Start() { + public void Init() { //DeviceData.Get().TestInit(); ThreadManager.Get().StartLong("配方执行业务流程", true, new IThread() { diff --git a/app/src/main/java/com/example/bpa/app/ICSApp.java b/app/src/main/java/com/example/bpa/app/ICSApp.java index bd079df..02eed59 100644 --- a/app/src/main/java/com/example/bpa/app/ICSApp.java +++ b/app/src/main/java/com/example/bpa/app/ICSApp.java @@ -36,10 +36,12 @@ public class ICSApp extends Application { Log.e("Error", msg); } + @Override public void InfoMsg(String msg, String datetime) { Log.i("Info", msg); } + @Override public void WarnMsg(String msg) { Log.w("Warn", msg); @@ -53,7 +55,7 @@ public class ICSApp extends Application { //2.初始化SD卡,数据库DB SdCart.getInstance().initSD(); - BusinessServer.get().Start(); + ModbusTcpServer.get().Connect("", 502); //3.初始化数据 InitDBdata(); //4.初始化Main 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 145885a..8ba6c01 100644 --- a/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java +++ b/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java @@ -116,6 +116,8 @@ public class ModbusTcpServer { @Override public void onSuccess(ModbusMaster modbusMaster) { MessageLog.ShowInfo("设备 " + host + " 连接成功"); + DeviceData.Get().Init(); + BusinessServer.Get().Init(); } @Override diff --git a/app/src/main/java/com/example/bpa/view/from/yfpf_activity.java b/app/src/main/java/com/example/bpa/view/from/yfpf_activity.java index 7ea7de5..4e93db6 100644 --- a/app/src/main/java/com/example/bpa/view/from/yfpf_activity.java +++ b/app/src/main/java/com/example/bpa/view/from/yfpf_activity.java @@ -54,7 +54,7 @@ public class yfpf_activity extends AppCompatActivity implements View.OnClickList /** * 商品数据 */ - ArrayList bpa_goods=new ArrayList<>(); + ArrayList bpa_goods = new ArrayList<>(); //endregion //region 私有函数 @@ -72,13 +72,13 @@ public class yfpf_activity extends AppCompatActivity implements View.OnClickList /** * 初始化 */ - private void Init(){ + private void Init() { gongneng_fanhui = this.findViewById(R.id.gongneng_fanhui); gongneng_title = this.findViewById(R.id.gongneng_title); - buttonaddpf=this.findViewById(R.id.buttonaddpf); - datatab= this.findViewById(R.id.datatab); + buttonaddpf = this.findViewById(R.id.buttonaddpf); + datatab = this.findViewById(R.id.datatab); //通过Activity.getIntent()获取当前页面接收到的Intent。 getXxxExtra方法获取Intent传递过来的数据 - String msg=getIntent().getStringExtra("data"); + String msg = getIntent().getStringExtra("data"); gongneng_title.setText(msg); Initdata();//初始化数据 RegisterMessage();//消息中心事件接收 @@ -95,19 +95,19 @@ public class yfpf_activity extends AppCompatActivity implements View.OnClickList /** * 初始化数据加载 */ - public void Initdata() - { - try{ - bpa_goods= QueryDB.GetGoodsALL(); - sp_adapter adapter = new sp_adapter(yfpf_activity.this, R.layout.sp_item, bpa_goods,this); + public void Initdata() { + try { + bpa_goods = QueryDB.GetGoodsALL(); + sp_adapter adapter = new sp_adapter(yfpf_activity.this, R.layout.sp_item, bpa_goods, this); datatab.setAdapter(adapter); - }catch(Exception e){ + } catch (Exception e) { } } //endregion //region 点击事件 + /** * 本页面点击事件监听22 * @@ -132,89 +132,82 @@ public class yfpf_activity extends AppCompatActivity implements View.OnClickList * 接口方法,响应ListView按钮点击事件 */ @Override - public void clickListener(View v,Object data) { - switch (v.getId()) - { + public void clickListener(View v, Object data) { + switch (v.getId()) { case R.id.button_item://删除按钮 - int sort=((BPA_GOODS)data).sort; - String id=((BPA_GOODS)data).id; - Log.i("日志",sort + "--- "+id); - QueryDB.DeleteGoods((BPA_GOODS)data); + int sort = ((BPA_GOODS) data).sort; + String id = ((BPA_GOODS) data).id; + Log.i("日志", sort + "--- " + id); + QueryDB.DeleteGoods((BPA_GOODS) data); Initdata(); - for (BPA_GOODS k:bpa_goods) { - if(k.sort>sort) - { - QueryDB.GetGoodsSort(k,1); + for (BPA_GOODS k : bpa_goods) { + if (k.sort > sort) { + QueryDB.GetGoodsSort(k, 1); } } Initdata(); break; case R.id.button_item_Up://上移动按钮 - BPA_GOODS good=(BPA_GOODS)data; - if(good.sort==1) - { + BPA_GOODS good = (BPA_GOODS) data; + if (good.sort == 1) { T.show(this, "已是最顶部!"); return; } - QueryDB.GetGoodsSort((BPA_GOODS)data,1); + QueryDB.GetGoodsSort((BPA_GOODS) data, 1); Initdata(); break; case R.id.button_item_Down://下移动按钮 - BPA_GOODS good2=(BPA_GOODS)data; - if(good2.sort==bpa_goods.size()) - { + BPA_GOODS good2 = (BPA_GOODS) data; + if (good2.sort == bpa_goods.size()) { T.show(this, "已是最底部!"); return; } - QueryDB.GetGoodsSort((BPA_GOODS)data,0); + QueryDB.GetGoodsSort((BPA_GOODS) data, 0); Initdata(); break; case R.id.button_item_update://修改按钮 Intent intent = new Intent(this, add_pf_activity.class); intent.putExtra("title", "修改配方"); - intent.putExtra("data",new Json().objectToJson(BPA_GOODS.class,data)); + intent.putExtra("data", new Json().objectToJson(BPA_GOODS.class, data)); startActivity(intent); break; case R.id.button_xf://下发按钮 - BusinessServer.get().AddCommodity(((BPA_GOODS)data).id); + BusinessServer.Get().AddCommodity(((BPA_GOODS) data).id); T.show(this, "下发成功!"); break; case R.id.button_qy://启用按钮 - BPA_GOODS good3=(BPA_GOODS)data; - good3.status=1; + BPA_GOODS good3 = (BPA_GOODS) data; + good3.status = 1; QueryDB.UpdateGoods(good3); Initdata(); - T.show(this, good3.name+"-启用成功!"); + T.show(this, good3.name + "-启用成功!"); break; case R.id.button_jy://下发按钮 - BPA_GOODS good4=(BPA_GOODS)data; - good4.status=0; + BPA_GOODS good4 = (BPA_GOODS) data; + good4.status = 0; QueryDB.UpdateGoods(good4); Initdata(); - T.show(this, good4.name+"-禁用成功!"); + T.show(this, good4.name + "-禁用成功!"); break; } } //endregion //region 接收事件 - public void RegisterMessage() - { + public void RegisterMessage() { //配方界面关闭事件 MessageManager.getInstance().registerMessageReceiver(this, MessageName.PF_From_Close.name(), new MessageLooper.OnMessageListener() { @Override public void onMessage(Object msg) { if (msg != null) { - if(msg.equals("Close")) - { + if (msg.equals("Close")) { Initdata(); } - }else - { + } else { runOnUiThread(new Runnable() { @Override public void run() { - T.show(yfpf_activity.this,"服务器异常,请稍后重试!"); + T.show(yfpf_activity.this, "服务器异常,请稍后重试!"); } }); } @@ -225,16 +218,14 @@ public class yfpf_activity extends AppCompatActivity implements View.OnClickList @Override public void onMessage(Object msg) { if (msg != null) { - if(msg.equals("Close")) - { + if (msg.equals("Close")) { Initdata(); } - }else - { + } else { runOnUiThread(new Runnable() { @Override public void run() { - T.show(yfpf_activity.this,"服务器异常,请稍后重试!"); + T.show(yfpf_activity.this, "服务器异常,请稍后重试!"); } }); }