Browse Source

兼容一拖二功能

炒锅机器人_一拖多
liup 4 months ago
parent
commit
0ab21d8bec
34 changed files with 3717 additions and 3157 deletions
  1. +2
    -0
      app/src/main/java/com/bonait/bnframework/HBL/Thread/ThreadManager.java
  2. +1
    -3
      app/src/main/java/com/bonait/bnframework/business/ConfigData.java
  3. +149
    -964
      app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java
  4. +1530
    -0
      app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe2.java
  5. +62
    -101
      app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java
  6. +317
    -190
      app/src/main/java/com/bonait/bnframework/modbus/ModbusCenter.java
  7. +0
    -265
      app/src/main/java/com/bonait/bnframework/modbus/OvenModbusTcpServer.java
  8. +7
    -7
      app/src/main/java/com/bonait/bnframework/modbus/RackModbusTcpHelper.java
  9. +660
    -0
      app/src/main/java/com/bonait/bnframework/modbus/RackModbusTcpServer.java
  10. +2
    -0
      app/src/main/java/com/bonait/bnframework/modbus/RobotModbusTcpServer.java
  11. +44
    -0
      app/src/main/java/com/bonait/bnframework/modbus/Wok2ModbusTcpHelper.java
  12. +488
    -0
      app/src/main/java/com/bonait/bnframework/modbus/Wok2ModbusTcpServer.java
  13. +47
    -0
      app/src/main/java/com/bonait/bnframework/modbus/WokModbusTcpServer.java
  14. +0
    -1
      app/src/main/java/com/bonait/bnframework/newui/activity/CookingHActivity.java
  15. +0
    -1
      app/src/main/java/com/bonait/bnframework/newui/activity/MainHActivity.java
  16. +0
    -1
      app/src/main/java/com/bonait/bnframework/newui/dialog/check/RootTipDialog.java
  17. +0
    -1
      app/src/main/java/com/bonait/bnframework/newui/dialog/control/ChuCanCheckDialog.java
  18. +0
    -506
      app/src/main/java/com/bonait/bnframework/newui/dialog/control/OvenControlDialog.java
  19. +2
    -146
      app/src/main/java/com/bonait/bnframework/newui/dialog/control/RobotControlDialog.java
  20. +4
    -0
      app/src/main/java/com/bonait/bnframework/newui/dialog/control/WokControlDialog.java
  21. +0
    -362
      app/src/main/java/com/bonait/bnframework/newui/fragment/cooking/Cooking2Fragment.java
  22. +17
    -75
      app/src/main/java/com/bonait/bnframework/newui/fragment/main/HomeDevicesFragment.java
  23. +1
    -48
      app/src/main/java/com/bonait/bnframework/newui/fragment/main/HomeGoodsFragment.java
  24. +0
    -1
      app/src/main/java/com/bonait/bnframework/newui/fragment/main/HomeOrderFragment.java
  25. +164
    -153
      app/src/main/java/com/bonait/bnframework/newui/fragment/main/HomeWarnFragment.java
  26. +43
    -0
      app/src/main/java/com/bonait/bnframework/newui/widget/DeviceStatusView.java
  27. +2
    -2
      app/src/main/java/com/bonait/bnframework/newui/widget/imagebuttom.java
  28. +45
    -54
      app/src/main/res/layout/new/layout/dialog_food_control.xml
  29. +39
    -184
      app/src/main/res/layout/new/layout/fragment_home_device_debug.xml
  30. +8
    -72
      app/src/main/res/layout/new/layout/fragment_home_goods.xml
  31. +13
    -15
      app/src/main/res/layout/new/layout/fragment_home_order.xml
  32. +5
    -5
      app/src/main/res/layout/new/layout/fragment_home_warn_info.xml
  33. +65
    -0
      app/src/main/res/layout/new/layout/view_device_status.xml
  34. BIN
     

+ 2
- 0
app/src/main/java/com/bonait/bnframework/HBL/Thread/ThreadManager.java View File

@@ -1,5 +1,6 @@
package com.bonait.bnframework.HBL.Thread;

import com.apkfuns.logutils.LogUtils;
import com.bonait.bnframework.HBL.Logs.MessageLog;

import java.util.HashMap;
@@ -89,6 +90,7 @@ public class ThreadManager {
tm.get(Key).Task.Run();
} catch (Exception ex) {
MessageLog.ShowError("多线程:[" + Key + "] 运行发生异常,已重启,错误信息:" + ex.toString());
LogUtils.d("多线程:[" + Key + "] 运行发生异常,已重启,错误信息:" + ex.toString());
Sleep(RestartInterval);
}
} else {


+ 1
- 3
app/src/main/java/com/bonait/bnframework/business/ConfigData.java View File

@@ -52,10 +52,8 @@ import com.bonait.bnframework.common.model.mode.UpdateBomInfo;
import com.bonait.bnframework.common.model.mode.UpdateCloudGood;
import com.bonait.bnframework.common.oss.OssHelper;
import com.bonait.bnframework.common.utils.NetworkUtils;
import com.bonait.bnframework.common.utils.PreferenceUtils;
import com.bonait.bnframework.common.utils.ToastUtils;
import com.bonait.bnframework.common.view.GoodEditDialog;
import com.bonait.bnframework.newui.http.UpdateAllDataService;
import com.bonait.bnframework.newui.http.UpdateDataService;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
@@ -1050,7 +1048,7 @@ public class ConfigData {
List<Res_PLCADDRESS> plcaddresses = new ArrayList<>();
List<BPA_PLCADDRESS> newPlCAddress = new ArrayList<>();
plcaddresses.addAll(ConfigName.getInstance().PlcAddress_Wok);
plcaddresses.addAll(ConfigName.getInstance().PlcAddress_Oven);
plcaddresses.addAll(ConfigName.getInstance().PlcAddress_Rack);
plcaddresses.addAll(ConfigName.getInstance().PlcAddress_Robot);
List<ProcessT> processTS = ConfigName.getInstance().Process_800炒锅;
List<ProcessT> processTS2 = ConfigName.getInstance().Process_烤箱;


+ 149
- 964
app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java
File diff suppressed because it is too large
View File


+ 1530
- 0
app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe2.java
File diff suppressed because it is too large
View File


+ 62
- 101
app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java View File

@@ -52,6 +52,16 @@ public class ConfigName {
}
return mInstance;
}

public String wok1Address = "";
public String wok1Port = "";
public String wok2Address = "";
public String wok2Port = "";
public String wok3Address = "";
public String wok3Port = "";
public String wok4Address = "";
public String wok4Port = "";

/**
* 平台授权码
*/
@@ -265,122 +275,71 @@ public class ConfigName {
/**
* 货架+烤箱plc模型
*/
public List<Res_PLCADDRESS> PlcAddress_Oven= new ArrayList<Res_PLCADDRESS>() {{
add(new Res_PLCADDRESS("控制烤箱、输送线、补盆", "-------------", 0, 0,3));
// add(new Res_PLCADDRESS("输送线启动", "M0.0", 0, 1,3));
// add(new Res_PLCADDRESS("输送线停止", "M0.1", 0, 1,3));
add(new Res_PLCADDRESS("烤箱门打开控制", "M0.2", 0, 1,3));
add(new Res_PLCADDRESS("烤箱门关闭控制", "M0.3", 0, 1,3));
add(new Res_PLCADDRESS("单次补盆流程触发", "M0.4", 0, 1,3));
add(new Res_PLCADDRESS("烤箱模式", "-------------", 0, 0,3));
add(new Res_PLCADDRESS("档位选择", "VW40", 0, 1,3));//0-4
add(new Res_PLCADDRESS("档位选择触发", "M20.2", 0, 1,3));
add(new Res_PLCADDRESS("挡盆位置校准", "M42.0", 0, 1,3));
add(new Res_PLCADDRESS("点动正转", "M20.5", 0, 1,3));
add(new Res_PLCADDRESS("点动反转", "M20.6", 0, 1,3));
add(new Res_PLCADDRESS("关位置设定", "M20.0", 0, 1,3));
add(new Res_PLCADDRESS("蒸位置设定", "M20.1", 0, 1,3));
add(new Res_PLCADDRESS("烤位置设定", "M20.2", 0, 1,3));
add(new Res_PLCADDRESS("蒸烤位置设定", "M20.3", 0, 1,3));
add(new Res_PLCADDRESS("其他位置设定", "M20.4", 0, 1,3));
add(new Res_PLCADDRESS("档位轴急停复位", "M23.1", 0, 1,3));
add(new Res_PLCADDRESS("烤箱温度", "-------------", 0, 0,3));
add(new Res_PLCADDRESS("温度选择", "VW140", 0, 1,3));//0-4
add(new Res_PLCADDRESS("温度选择触发", "M30.2", 0, 1,3));
add(new Res_PLCADDRESS("温度点动正转", "M30.5", 0, 1,3));
add(new Res_PLCADDRESS("温度点动反转", "M30.6", 0, 1,3));
add(new Res_PLCADDRESS("下限位置设定", "M32.0", 0, 1,3));
add(new Res_PLCADDRESS("上限位置设定", "M32.1", 0, 1,3));
add(new Res_PLCADDRESS("温度轴急停复位", "M33.1", 0, 1,3));
add(new Res_PLCADDRESS("原料库位状态反馈", "-------------", 0, 0,3));
add(new Res_PLCADDRESS("急停状态反馈", "M10.0", 1, 0,3));
add(new Res_PLCADDRESS("档位原点", "M10.1", 1, 0,3));
add(new Res_PLCADDRESS("温度原点", "M10.2", 1, 0,3));
add(new Res_PLCADDRESS("补盆原点", "M10.3", 1, 0));
add(new Res_PLCADDRESS("1#调料检测有无", "M10.4", 1, 0,3));
add(new Res_PLCADDRESS("2#调料检测有无", "M10.5", 1, 0,3));
add(new Res_PLCADDRESS("3#调料检测有无", "M10.6", 1, 0,3));
add(new Res_PLCADDRESS("4#调料检测有无", "M10.7", 1, 0,3));
add(new Res_PLCADDRESS("1#料仓检测有无", "M11.0", 1, 0,3));
add(new Res_PLCADDRESS("2#料仓检测有无", "M11.1", 1, 0,3));
add(new Res_PLCADDRESS("3#料仓检测有无", "M11.2", 1, 0,3));
add(new Res_PLCADDRESS("4#料仓检测有无", "M11.3", 1, 0,3));
add(new Res_PLCADDRESS("5#料仓检测有无", "M11.4", 1, 0,3));
add(new Res_PLCADDRESS("6#料仓检测有无", "M11.5", 1, 0,3));
add(new Res_PLCADDRESS("1#烤盘检测有无", "M11.6", 1, 0,3));
add(new Res_PLCADDRESS("2#烤盘检测有无", "M11.7", 1, 0,3));
add(new Res_PLCADDRESS("烤箱、空盆检测反馈", "-------------", 0, 0,3));
add(new Res_PLCADDRESS("烤箱门开到位检测", "M12.0", 1, 0,3));
add(new Res_PLCADDRESS("烤箱门关到位检测", "M12.1", 1, 0,3));
add(new Res_PLCADDRESS("烤箱门中间位检测", "M12.4", 1, 0,3));
add(new Res_PLCADDRESS("烤箱开门动作超时", "M1100.5", 1, 0,3));
add(new Res_PLCADDRESS("烤箱关门动作超时", "M1100.6", 1, 0,3));

add(new Res_PLCADDRESS("出料空盆检测有无", "M12.2", 1, 0,3));
// add(new Res_PLCADDRESS("补盆工位检测有无", "M12.2", 1, 0,3));
add(new Res_PLCADDRESS("出餐工位检测有无", "M12.3", 1, 0,3));
add(new Res_PLCADDRESS("电柜门关到位检测", "M12.5", 1, 0,3));
add(new Res_PLCADDRESS("补盆动作完成", "M41.0", 1, 0,3));
add(new Res_PLCADDRESS("档位温度反馈", "-------------", 0, 0,3));
add(new Res_PLCADDRESS("当前档位_关", "M21.0", 1, 0,3));
add(new Res_PLCADDRESS("当前档位_蒸", "M21.1", 1, 0,3));
add(new Res_PLCADDRESS("当前档位_烤", "M21.2", 1, 0,3));
add(new Res_PLCADDRESS("当前档位_蒸烤", "M21.3", 1, 0,3));
add(new Res_PLCADDRESS("当前档位_其他", "M21.4", 1, 0,3));
add(new Res_PLCADDRESS("温度设置完成", "M31.0", 1, 0,3));
add(new Res_PLCADDRESS("档位正限位提示", "M1000.3", 1, 0,3));
add(new Res_PLCADDRESS("档位负限位提示", "M1000.4", 1, 0,3));
add(new Res_PLCADDRESS("温度正限位提示", "M1001.3", 1, 0,3));
add(new Res_PLCADDRESS("温度负限位提示", "M1001.4", 1, 0,3));
add(new Res_PLCADDRESS("档位回原点超时", "M1100.0", 1, 0,3));
add(new Res_PLCADDRESS("档位定位超时", "M1100.1", 1, 0,3));
add(new Res_PLCADDRESS("温度回原点超时", "M1100.2", 1, 0,3));
add(new Res_PLCADDRESS("温度定位超时", "M1100.3", 1, 0,3));
add(new Res_PLCADDRESS("补盆动作超时", "M1100.4", 1, 0,3));
add(new Res_PLCADDRESS("机器人允许关门", "M13.0", 1, 0,3));




// add(new Res_PLCADDRESS("温度旋钮在档位0", "M31.0", 1, 0,3));
// add(new Res_PLCADDRESS("温度旋钮在档位1", "M31.1", 1, 0,3));
// add(new Res_PLCADDRESS("温度旋钮在档位2", "M31.2", 1, 0,3));
// add(new Res_PLCADDRESS("温度旋钮在档位3", "M31.3", 1, 0,3));
// add(new Res_PLCADDRESS("温度旋钮在档位4", "M31.4", 1, 0,3));
// add(new Res_PLCADDRESS("烤箱功率判断是否工作", "VD324", 1, 0,3));
public List<Res_PLCADDRESS> PlcAddress_Rack = new ArrayList<Res_PLCADDRESS>() {{
add(new Res_PLCADDRESS("库位状态反馈", "-------------", 0, 0,3));
add(new Res_PLCADDRESS("1#料仓检测有无", "M10.0", 1, 0,3));
add(new Res_PLCADDRESS("2#料仓检测有无", "M10.1", 1, 0,3));
add(new Res_PLCADDRESS("3#料仓检测有无", "M10.2", 1, 0,3));
add(new Res_PLCADDRESS("4#料仓检测有无", "M10.3", 1, 0,3));
add(new Res_PLCADDRESS("5#料仓检测有无", "M10.4", 1, 0,3));
add(new Res_PLCADDRESS("6#料仓检测有无", "M10.5", 1, 0,3));
add(new Res_PLCADDRESS("1#调料检测有无", "M10.6", 1, 0,3));
add(new Res_PLCADDRESS("2#调料检测有无", "M10.7", 1, 0,3));
add(new Res_PLCADDRESS("3#调料检测有无", "M11.0", 1, 0,3));
add(new Res_PLCADDRESS("4#调料检测有无", "M11.1", 1, 0,3));
add(new Res_PLCADDRESS("5#调料检测有无", "M11.2", 1, 0,3));
add(new Res_PLCADDRESS("6#调料检测有无", "M11.3", 1, 0,3));
add(new Res_PLCADDRESS("1#空盆库位检测有无", "M11.4", 1, 0,3));
add(new Res_PLCADDRESS("2#空盆库位检测有无", "M11.5", 1, 0,3));
add(new Res_PLCADDRESS("3#空盆库位检测有无", "M12.0", 1, 0,3));
// add(new Res_PLCADDRESS("4#空盆库位检测有无", "M12.1", 1, 0,3));
add(new Res_PLCADDRESS("输送线状态反馈", "-------------", 0, 0,3));
add(new Res_PLCADDRESS("输送线出料菜盆检测", "M12.2", 1, 0,3));
add(new Res_PLCADDRESS("输送线进料菜盆检测", "M12.3", 1, 0,3));
add(new Res_PLCADDRESS("输送线运行中", "M15.0", 1, 0,3));
add(new Res_PLCADDRESS("输送电机过载", "M16.0", 1, 0,3));
add(new Res_PLCADDRESS("输送电机通讯异常", "M16.1", 1, 0,3));
add(new Res_PLCADDRESS("货架写入信号", "-------------", 0, 0,3));
add(new Res_PLCADDRESS("输送线启动", "M0.0", 1, 1,3));
add(new Res_PLCADDRESS("输送线停止", "M0.1", 1, 1,3));
add(new Res_PLCADDRESS("状态灯黄", "M2.0", 1, 1,3));
add(new Res_PLCADDRESS("状态灯绿", "M2.1", 1, 1,3));
add(new Res_PLCADDRESS("状态灯红", "M2.2", 1, 1,3));
add(new Res_PLCADDRESS("蜂鸣器", "M2.3", 1, 1,3));
}};

public boolean isPutFinish = false;//放盆完成

/**
* 机器人plc模型
*/
public List<Res_PLCADDRESS> PlcAddress_Robot= new ArrayList<Res_PLCADDRESS>() {{
add(new Res_PLCADDRESS("机器人完成反馈(烤箱)", "-------------", 0, 0,2));
add(new Res_PLCADDRESS("烤盘架放料至烤箱完成", "M610", 1, 1,2));
add(new Res_PLCADDRESS("烤盘出餐完成", "M611", 1, 1,2));
add(new Res_PLCADDRESS("机器人烤箱开门完成", "M612", 1, 1,2));
add(new Res_PLCADDRESS("机器人烤箱关门完成", "M613", 1, 1,2));
add(new Res_PLCADDRESS("机器人状态反馈", "-------------", 0, 0,2));
add(new Res_PLCADDRESS("机器人到达维护位", "M640", 1, 1,2));
add(new Res_PLCADDRESS("机器人在原点", "M650", 1, 1,2));
add(new Res_PLCADDRESS("机器人准备就绪", "M651", 1, 1,2));
add(new Res_PLCADDRESS("机器人急停", "M652", 1, 1,2));
add(new Res_PLCADDRESS("机器人光栅", "M653", 1, 1,2));
add(new Res_PLCADDRESS("机器人任务反馈", "-------------", 0, 0,2));
add(new Res_PLCADDRESS("机器人任务反馈", "GI5", 1, 1,2));
add(new Res_PLCADDRESS("机器人完成反馈(炒锅)", "-------------", 0, 0,2));
add(new Res_PLCADDRESS("炒锅倒原料完成", "M600", 1, 1,2));
add(new Res_PLCADDRESS("炒锅倒调料完成", "M601", 1, 1,2));
add(new Res_PLCADDRESS("机器人到位请求炒锅出餐倒菜", "M602", 0, 1,2));
add(new Res_PLCADDRESS("炒锅出餐完成", "M603", 1, 1,2));
add(new Res_PLCADDRESS("1炒锅倒原料完成", "M600", 1, 1,2));
add(new Res_PLCADDRESS("1炒锅倒调料完成", "M601", 1, 1,2));
add(new Res_PLCADDRESS("1机器人到位请求炒锅出餐倒菜", "M602", 0, 1,2));
add(new Res_PLCADDRESS("1炒锅出餐完成", "M603", 1, 1,2));
add(new Res_PLCADDRESS("2炒锅倒原料完成", "M610", 1, 1,2));
add(new Res_PLCADDRESS("2炒锅倒调料完成", "M611", 1, 1,2));
add(new Res_PLCADDRESS("2机器人到位请求炒锅出餐倒菜", "M612", 0, 1,2));
add(new Res_PLCADDRESS("2炒锅出餐完成", "M613", 1, 1,2));
add(new Res_PLCADDRESS("控制机器人", "-------------", 0, 0,2));
add(new Res_PLCADDRESS("主任务", "GI0", 0, 1,2));
add(new Res_PLCADDRESS("炒锅允许倒料", "M500", 0, 1,2));
add(new Res_PLCADDRESS("炒锅出餐减速到位", "M501", 0, 1,2));
add(new Res_PLCADDRESS("炒锅出餐倒菜完成", "M502", 0, 1,2));
add(new Res_PLCADDRESS("烤箱允许放料", "M510", 0, 1,2));
add(new Res_PLCADDRESS("子任务", "GI1", 0, 1,2));
add(new Res_PLCADDRESS("主任务读取", "GI5", 1, 1,2));
add(new Res_PLCADDRESS("1号炒锅允许倒料", "M500", 0, 1,2));
add(new Res_PLCADDRESS("2号炒锅允许倒料", "M510", 0, 1,2));
add(new Res_PLCADDRESS("1号炒锅出餐减速到位", "M501", 0, 1,2));
add(new Res_PLCADDRESS("2号炒锅出餐减速到位", "M511", 0, 1,2));
add(new Res_PLCADDRESS("1号炒锅出餐倒菜完成", "M502", 0, 1,2));
add(new Res_PLCADDRESS("2号炒锅出餐倒菜完成", "M512", 0, 1,2));
add(new Res_PLCADDRESS("维护完成确认允许机器人回原位", "M520", 0, 1,2));
add(new Res_PLCADDRESS("允许机器人出餐放盆", "M530", 0, 1,2));
add(new Res_PLCADDRESS("主任务读取", "GI5", 0, 1,2));
}};

/**
@@ -404,6 +363,8 @@ public class ConfigName {
put("2#库取调料倒至炒锅", 12);
put("3#库取调料倒至炒锅", 13);
put("4#库取调料倒至炒锅", 14);
put("5#库取调料倒至炒锅", 15);
put("6#库取调料倒至炒锅", 16);
put("1#库取调料倒至炒锅反馈", 11);
put("2#库取调料倒至炒锅反馈", 12);
put("3#库取调料倒至炒锅反馈", 13);
@@ -421,7 +382,7 @@ public class ConfigName {
put("机器人取烤箱烤盘出餐", 32);
put("机器人取烤箱烤盘出餐反馈", 32);

put("机器人去维护位置", 41);
put("机器人去维护位置", 31);
put("机器人去维护位置反馈", 41);

put("将输送线前段餐盘烤盘推出", 51);


+ 317
- 190
app/src/main/java/com/bonait/bnframework/modbus/ModbusCenter.java View File

@@ -3,8 +3,6 @@ package com.bonait.bnframework.modbus;
import com.apkfuns.logutils.LogUtils;
import com.bonait.bnframework.HBL.Logs.MessageLog;
import com.bonait.bnframework.HBL.Thread.ThreadManager;
import com.bonait.bnframework.Service.ModbusTcpServer;
import com.bonait.bnframework.business.ExecuteTheRecipe;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.db.QueryDB;
import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS;
@@ -24,12 +22,14 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class ModbusCenter {
//modbus 连接
public static String wokAddress = "192.168.6.100";//炒锅地址
public static int wokPost = 504;//炒锅端口
public static String robotAddress = "192.168.6.101";//机器人地址
public static String wokAddress = "192.168.1.101";//炒锅地址
public static int wokPost = 502;//炒锅端口
public static String wok2Address = "192.168.1.102";//炒锅地址
public static int wok2Post = 502;//炒锅端口
public static String robotAddress = "192.168.1.100";//机器人地址
public static int robotPost = 502;
public static String ovenAddress = "192.168.6.102";//烤箱地址
public static int ovenPost = 502;
public static String rackAddress = "192.168.1.103";//货架地址
public static int rackPost = 502;
/**
* PLC地址
*/
@@ -45,6 +45,7 @@ public class ModbusCenter {
}
}


/**
* 监听变量值
*/
@@ -56,13 +57,14 @@ public class ModbusCenter {
public static void connectPlc(){
if(ConfigName.TEST){
RobotModbusTcpServer.get().plcIsConnect = true;
OvenModbusTcpServer.get().plcIsConnect = true;
RackModbusTcpServer.get().plcIsConnect = true;
WokModbusTcpServer.get().plcIsConnect = true;
Wok2ModbusTcpServer.get().plcIsConnect = true;
}else {
RobotModbusTcpServer.ConnectPLC();
OvenModbusTcpServer.ConnectPLC();
RackModbusTcpServer.ConnectPLC();
WokModbusTcpServer.ConnectPLC();
Wok2ModbusTcpServer.ConnectPLC();
}
}

@@ -72,69 +74,34 @@ public class ModbusCenter {
public static void closePLC(){
WokModbusTcpServer.get().DisConnect();
RobotModbusTcpServer.get().DisConnect();
OvenModbusTcpServer.get().DisConnect();
RackModbusTcpServer.get().DisConnect();
}

public static void Listening() {
new Thread(new Runnable() {
@Override
public void run() {
try {
if(WokModbusTcpServer.get().plcIsConnect){
WritePlc("初始化", true, null);
Thread.sleep(500);
WritePlc("初始化", false, null);

WritePlc("温控开关", false, null);//开关闭合
WritePlc("暂停开关", false, null);//开关闭合

WritePlc("校准时间", 50, null);//默认校准时间5秒
WritePlc("料仓1校准开关", false, null);//默认校准时间5秒
WritePlc("料仓2校准开关", false, null);//默认校准时间5秒
WritePlc("料仓3校准开关", false, null);//默认校准时间5秒

WokModbusTcpServer.get().WriteBool("M52.1", (boolean) false, null);
//读取版本号
WokModbusTcpServer.get().ReadInt("VD1100", 1, val -> {

});

WritePlc("温度选择",0,null);
WritePlc("温度选择触发",true,null);

WritePlc("档位选择",0,null);
WritePlc("档位选择触发",true,null);
}
} catch (InterruptedException e) {
NewToastUtil.getInstance().showToast("异常信息:" + e.getMessage());
}
}
}).start();

ThreadManager.get().StartLong("炒锅PLC设备数据监听", true, () -> {
try {
try{
// LogUtils.d("炒锅*******************++");
if(WokModbusTcpServer.get().plcIsConnect){
for (Res_PLCADDRESS item : ConfigName.getInstance().PlcAddress_Wok) {
if(item!=null){
if (item.isread == 1) {
if(WokModbusTcpServer.get().plcIsConnect){
Object val = wokReadPlc(item.name);
Object val = wokReadPlc(1,item.name);
if(ConfigName.LOG_TEST){
LogUtils.d("机炒锅PLC设备数据监听 ovenReadPlc item="+item.name+" val="+val+" plcaddress.address="+item.address);
}
if(item.name.equals("原点位反馈")||item.name.equals("投料位反馈")){
if(RobotModbusTcpServer.get().plcIsConnect){
if((boolean)val){
ModbusCenter.robotWritePlc(false,"炒锅允许倒料",true,null);
ModbusCenter.robotWritePlc(false,"1号炒锅允许倒料",true,null);
}
}
}
if(ConfigName.LOG_TEST){
LogUtils.d("炒锅PLC设备数据监听 name="+item.name+" plcaddress.address="+item.address +" ;val="+val);
}
listeningValue.put(item.name, val);
WokModbusTcpServer.get().listeningValue.put(item.name, val);
}
}
}
@@ -143,82 +110,111 @@ public class ModbusCenter {
WokModbusTcpServer.get().ReConnect("Connection refused");
}

if(Wok2ModbusTcpServer.get().plcIsConnect){
for (Res_PLCADDRESS item : ConfigName.getInstance().PlcAddress_Wok) {
if(item!=null){
if (item.isread == 1) {
if(Wok2ModbusTcpServer.get().plcIsConnect){
Object val = wokReadPlc(2,item.name);
if(ConfigName.LOG_TEST){
LogUtils.d("机炒锅PLC设备数据监听 ovenReadPlc item="+item.name+" val="+val+" plcaddress.address="+item.address);
}
if(item.name.equals("原点位反馈")||item.name.equals("投料位反馈")){
if(RobotModbusTcpServer.get().plcIsConnect){
if((boolean)val){
ModbusCenter.robotWritePlc(false,"2号炒锅允许倒料",true,null);
}
}
}
if(ConfigName.LOG_TEST){
LogUtils.d("炒锅PLC设备数据监听 name="+item.name+" plcaddress.address="+item.address +" ;val="+val);
}
Wok2ModbusTcpServer.get().listeningValue.put(item.name, val);
}
}
}
}
}else {
Wok2ModbusTcpServer.get().ReConnect("Connection refused");
}


}catch (Exception ex){
LogUtils.d("异常信息:" + ex.getMessage());
}

if (WokModbusTcpServer.get().plcIsConnect) {
WritePlc("心跳位", 0, null);
TempControl();
ReadPLCStatus();

WritePlc(1,"心跳位", 0, null);
TempControl(1);
ReadPLCStatus(1);
}
if (Wok2ModbusTcpServer.get().plcIsConnect) {
WritePlc(2,"心跳位", 0, null);
TempControl(2);
ReadPLCStatus(2);
}
//
// if (RobotModbusTcpServer.get().plcIsConnect) {
// //todo
// }
// if (OvenModbusTcpServer.get().plcIsConnect) {
// ConfigName.getInstance().checkPositionList();
//// WritePlc("烤箱心跳位", 0, null);
// }
LogUtils.d("OvenModbusTcpServer.get().plcIsConnect ="+OvenModbusTcpServer.get().plcIsConnect);
// LogUtils.d("炒锅*******************++222");
} catch (Exception ex) {
// NewToastUtil.getInstance().showToastError("异常信息:" + ex.getMessage());
LogUtils.d("异常信息:" + ex.getMessage());
}
Thread.sleep(50);

});
ThreadManager.get().StartLong("烤箱PLC设备数据监听", true, () -> {
ThreadManager.get().StartLong("货架PLC设备数据监听", true, () -> {
try {
try{
// LogUtils.d("烤箱*******************++");

if(OvenModbusTcpServer.get().plcIsConnect){
for (Res_PLCADDRESS item : ConfigName.getInstance().PlcAddress_Oven) {
if(RackModbusTcpServer.get().plcIsConnect){
for (Res_PLCADDRESS item : ConfigName.getInstance().PlcAddress_Rack) {
if(item!=null){
if (item.isread == 1) {
if(OvenModbusTcpServer.get().plcIsConnect){
Object val = ovenReadPlc(item.name);
if(RackModbusTcpServer.get().plcIsConnect){
Object val = rackReadPlc(item.name);
if(ConfigName.LOG_TEST){
LogUtils.d("烤箱货架PLC设备数据监听 ovenReadPlc item="+item.name+" val="+val+" plcaddress.address="+item.address);
}
if(item.name.equals("出餐工位检测有无")){
if(RobotModbusTcpServer.get().plcIsConnect){
ModbusCenter.robotWritePlc(false,"允许机器人出餐放盆",!(boolean)val,null);
}
LogUtils.d("货架PLC设备数据监听 ovenReadPlc item="+item.name+" val="+val+" plcaddress.address="+item.address);
}

if(item.name.contains("超时")){
if((Boolean) val){
NewToastUtil.getInstance().showToastError(item.name+",请前往设备报警信息栏目,手动复位");
}
}
if(item.name.equals("烤箱门开到位检测")){
if(RobotModbusTcpServer.get().plcIsConnect){
ModbusCenter.robotWritePlc(false,"烤箱允许放料",(boolean)val,null);
if(item.name.contains("输送线出料菜盆检测")){
if((Boolean) val){
if( ConfigName.getInstance().isPutFinish){
ConfigName.getInstance().isPutFinish = false;
ThreadManager.get().execute(new Runnable() {
@Override
public void run() {
try{
Thread.sleep(4000);
if(RackModbusTcpServer.get().plcIsConnect){
RackModbusTcpServer.get().WriteBool("输送线停止",true,null);
Thread.sleep(500);
ModbusCenter.rackWritePlc("输送线停止",false,null);
}
}catch (Exception e){

}
}
});

}
}
}
if(ConfigName.LOG_TEST){
LogUtils.d("烤箱PLC设备数据监听 name="+item.name +" plcaddress.address="+item.address+" ;val="+val);
}


listeningValue.put(item.name, val);
}
}
}

}
ConfigName.getInstance().checkPositionList();
}else {
OvenModbusTcpServer.get().ReConnect("Connection refused");
RackModbusTcpServer.get().ReConnect("Connection refused");
}
// LogUtils.d("烤箱*******************++222");
}catch (Exception ex){
LogUtils.d("异常信息:" + ex.getMessage());
}
// LogUtils.d("OvenModbusTcpServer.get().plcIsConnect ="+OvenModbusTcpServer.get().plcIsConnect);
} catch (Exception ex) {
// NewToastUtil.getInstance().showToastError("异常信息:" + ex.getMessage());
LogUtils.d("异常信息:" + ex.getMessage());
}
Thread.sleep(50);
@@ -226,8 +222,6 @@ public class ModbusCenter {
ThreadManager.get().StartLong("机器人PLC设备数据监听", true, () -> {
try {
try{
// LogUtils.d("机器人*******************++");

if(RobotModbusTcpServer.get().plcIsConnect){
for (Res_PLCADDRESS item : ConfigName.getInstance().PlcAddress_Robot) {
if(item!=null){
@@ -237,12 +231,33 @@ public class ModbusCenter {
if(ConfigName.LOG_TEST){
LogUtils.d("机器人PLC设备数据监听 ovenReadPlc item="+item.name+" plcaddress.address="+item.address+" val="+val);
}

listeningValue.put(item.name, val);
}
}
}

}
if((Boolean) listeningValue.get("机器人急停")){
setLantern(2);
}else if((Boolean) listeningValue.get("机器人光栅")){
setLantern(2);
}else{
if(WokModbusTcpServer.get().plcIsConnect && Wok2ModbusTcpServer.get().plcIsConnect){
final boolean[] wok1 = {false};
final boolean[] wok2 = {false};
WokModbusTcpServer.get().ReadBool("M52.0", 1, val -> {
wok1[0] = val[0];
});
Wok2ModbusTcpServer.get().ReadBool("M52.0", 1, val -> {
wok2[0] = val[0];
});
if(wok1[0]||wok2[0]){
setLantern(0);
}else {
setLantern(1);
}
}else {
setLantern(1);
}
}
}else {
RobotModbusTcpServer.get().ReConnect("Connection refused");
@@ -251,10 +266,7 @@ public class ModbusCenter {
}catch (Exception ex){
LogUtils.d("异常信息:" + ex.getMessage());
}
LogUtils.d("OvenModbusTcpServer.get().plcIsConnect ="+OvenModbusTcpServer.get().plcIsConnect);
LogUtils.d("机器人*******************++222");
} catch (Exception ex) {
// NewToastUtil.getInstance().showToastError("异常信息:" + ex.getMessage());
LogUtils.d("异常信息:" + ex.getMessage());
}
Thread.sleep(50);
@@ -263,43 +275,64 @@ public class ModbusCenter {

}

public static Object ReadPlc(String name){
public static void setLantern(int type){
switch (type){
case 0://黄
rackWritePlc("状态灯黄",true,null);
rackWritePlc("状态灯绿",false,null);
rackWritePlc("状态灯红",false,null);
rackWritePlc("蜂鸣器",false,null);
break;
case 1://绿
rackWritePlc("状态灯黄",false,null);
rackWritePlc("状态灯绿",true,null);
rackWritePlc("状态灯红",false,null);
rackWritePlc("蜂鸣器",false,null);
break;
case 2://红
rackWritePlc("状态灯黄",false,null);
rackWritePlc("状态灯绿",false,null);
rackWritePlc("状态灯红",true,null);
rackWritePlc("蜂鸣器",true,null);
break;
}
}

public static Object ReadPlc(int deviceNum,String name){
if(ConfigName.TEST){
return true;
}
if (plcAddress.get(name)!=null) {
if (plcAddress.containsKey(name)) {
BPA_PLCADDRESS plcaddress = plcAddress.get(name);
assert plcaddress != null;
LogUtils.d("modbuscenter ReadPlc name="+name+" plcaddress.address="+plcaddress.address);
if(plcaddress.type == 1){
return wokReadPlc(name);
return wokReadPlc(deviceNum,name);
}else if(plcaddress.type == 2){
return robotReadPlc(name);
}else if(plcaddress.type == 3){
return ovenReadPlc(name);
return rackReadPlc(name);
}
}
LogUtils.d("modbuscenter ReadPlc 未匹配到地址");
return false;
return wokReadPlc(deviceNum,name);
}

public static void WritePlc(String name, Object value, IWriteCallBack callback){
if (plcAddress.get(name)!=null) {
public static void WritePlc(int deviceNum,String name, Object value, IWriteCallBack callback){
if (plcAddress.containsKey(name)) {
BPA_PLCADDRESS plcaddress = plcAddress.get(name);
assert plcaddress != null;
if(plcaddress.type == 1){
wokWritePlc(name,value,callback);
wokWritePlc(deviceNum,name,value,callback);
}else if(plcaddress.type == 2){
robotWritePlc(false,name,value,callback);
}else if(plcaddress.type == 3){
ovenWritePlc(name,value,callback);
rackWritePlc(name,value,callback);
}
}
}

/*
* 《-------------炒锅相关
* */
* 《-------------炒锅相关
* */

/**
* 获取监听变量
@@ -313,9 +346,9 @@ public class ModbusCenter {
/**
* 温控
*/
public static void TempControl() {
public static void TempControl(int deviceNum) {
boolean TempBool = false;
Object val_wd = ReadPlc("当前锅底温度");
Object val_wd = ReadPlc(deviceNum,"当前锅底温度");
int dq_wd = val_wd == null ? 0 : (int) val_wd;//当前锅底温度
if (dq_wd >= (ConfigName.getInstance().MaxTemp - 5)) //如果当前温度大于最大温度限制 断开
{
@@ -325,85 +358,145 @@ public class ModbusCenter {
TempBool = false;//闭合
}

Object tempkg = ReadPlc("温控开关");
Object tempkg = ReadPlc(deviceNum,"温控开关");
if (tempkg != null) {
boolean kg = (boolean) tempkg;
if (TempBool) //设置断开
{
if (kg == false) {
wokWritePlc("温控开关", true, null);//断开
wokWritePlc(deviceNum,"温控开关", true, null);//断开
}
} else //设置闭合
{
if (kg) {
wokWritePlc("温控开关", false, null);//闭合
wokWritePlc(deviceNum,"温控开关", false, null);//闭合
}
}
}
}

public static Object wokReadPlc(String name){
public static Object wokReadPlc(int deviceNum,String name){
if(ConfigName.TEST){
return true;
}
final Object[] ReturnsVariable = {null};
try {
if (plcAddress.get(name)!=null) {
if (plcAddress.containsKey(name)) {
BPA_PLCADDRESS plcaddress = plcAddress.get(name);
if (!plcaddress.address.isEmpty() && WokModbusTcpServer.get().plcIsConnect) {
if (plcaddress.address.toUpperCase().startsWith("VD"))//int
{
WokModbusTcpServer.get().ReadInt(plcaddress.address, 1, ints -> {
ReturnsVariable[0] = ints[0];
});
} else if (plcaddress.address.toUpperCase().startsWith("M"))//bool
{
WokModbusTcpServer.get().ReadBool(plcaddress.address, 1, val -> {
ReturnsVariable[0] = val[0];
});
} else if (plcaddress.address.toUpperCase().startsWith("VW"))//short
{
WokModbusTcpServer.get().ReadShort(plcaddress.address, 1, val -> {
ReturnsVariable[0] = val[0];
});
} else if (plcaddress.address.toUpperCase().startsWith("VR"))//float
{
WokModbusTcpServer.get().ReadFloat(plcaddress.address, 1, val -> {
ReturnsVariable[0] = val[0];
});
}
switch (deviceNum){
case 1:
if (plcaddress!=null && !plcaddress.address.isEmpty() && WokModbusTcpServer.get().plcIsConnect) {
if (!plcaddress.address.isEmpty() && WokModbusTcpServer.get().plcIsConnect) {
if (plcaddress.address.toUpperCase().startsWith("VD"))//int
{
WokModbusTcpServer.get().ReadInt(plcaddress.address, 1, ints -> {
ReturnsVariable[0] = ints[0];
});
} else if (plcaddress.address.toUpperCase().startsWith("M"))//bool
{
WokModbusTcpServer.get().ReadBool(plcaddress.address, 1, val -> {
ReturnsVariable[0] = val[0];
});
} else if (plcaddress.address.toUpperCase().startsWith("VW"))//short
{
WokModbusTcpServer.get().ReadShort(plcaddress.address, 1, val -> {
ReturnsVariable[0] = val[0];
});
} else if (plcaddress.address.toUpperCase().startsWith("VR"))//float
{
WokModbusTcpServer.get().ReadFloat(plcaddress.address, 1, val -> {
ReturnsVariable[0] = val[0];
});
}
}
}
break;
case 2:
if (plcaddress!=null &&!plcaddress.address.isEmpty() && Wok2ModbusTcpServer.get().plcIsConnect) {
if (!plcaddress.address.isEmpty() && Wok2ModbusTcpServer.get().plcIsConnect) {
if (plcaddress.address.toUpperCase().startsWith("VD"))//int
{
Wok2ModbusTcpServer.get().ReadInt(plcaddress.address, 1, ints -> {
ReturnsVariable[0] = ints[0];
});
} else if (plcaddress.address.toUpperCase().startsWith("M"))//bool
{
Wok2ModbusTcpServer.get().ReadBool(plcaddress.address, 1, val -> {
ReturnsVariable[0] = val[0];
});
} else if (plcaddress.address.toUpperCase().startsWith("VW"))//short
{
Wok2ModbusTcpServer.get().ReadShort(plcaddress.address, 1, val -> {
ReturnsVariable[0] = val[0];
});
} else if (plcaddress.address.toUpperCase().startsWith("VR"))//float
{
Wok2ModbusTcpServer.get().ReadFloat(plcaddress.address, 1, val -> {
ReturnsVariable[0] = val[0];
});
}
}
}
break;
case 3:
break;
case 4:
break;
}
}
} catch (Exception ex) {
LogUtils.d("异常信息:" + ex.getMessage());
NewToastUtil.getInstance().showToastError("异常信息:" + ex.getMessage());
} finally {
return ReturnsVariable[0];
}
}
public static void wokWritePlc(String name, Object value, IWriteCallBack callback){
public static void wokWritePlc(int deviceNum,String name, Object value, IWriteCallBack callback){
try {
LogUtils.d(" wokWritePlc name="+name+";value="+value);
if (plcAddress.get(name)!=null) {
if (plcAddress.containsKey(name)) {
BPA_PLCADDRESS plcaddress = plcAddress.get(name);
if (!plcaddress.address.isEmpty() && WokModbusTcpServer.get().plcIsConnect) {
if (plcaddress.address.toUpperCase().startsWith("VD"))//int
{
WokModbusTcpServer.get().WriteInt(plcaddress.address, (int) value, callback);
} else if (plcaddress.address.toUpperCase().startsWith("M"))//bool
{
WokModbusTcpServer.get().WriteBool(plcaddress.address, (boolean) value, callback);
} else if (plcaddress.address.toUpperCase().startsWith("VW"))//short
{
WokModbusTcpServer.get().WriteShort(plcaddress.address, Short.parseShort(value.toString()), callback);
} else if (plcaddress.address.toUpperCase().startsWith("VR"))//float
{
WokModbusTcpServer.get().WriteFloat(plcaddress.address, Float.parseFloat(value.toString()), callback);
}

switch (deviceNum) {
case 1:
if (plcaddress!=null &&!plcaddress.address.isEmpty() && WokModbusTcpServer.get().plcIsConnect) {
if (plcaddress.address.toUpperCase().startsWith("VD"))//int
{
WokModbusTcpServer.get().WriteInt(plcaddress.address, (int) value, callback);
} else if (plcaddress.address.toUpperCase().startsWith("M"))//bool
{
WokModbusTcpServer.get().WriteBool(plcaddress.address, (boolean) value, callback);
} else if (plcaddress.address.toUpperCase().startsWith("VW"))//short
{
WokModbusTcpServer.get().WriteShort(plcaddress.address, Short.parseShort(value.toString()), callback);
} else if (plcaddress.address.toUpperCase().startsWith("VR"))//float
{
WokModbusTcpServer.get().WriteFloat(plcaddress.address, Float.parseFloat(value.toString()), callback);
}
}
break;
case 2:
if (plcaddress!=null &&!plcaddress.address.isEmpty() && Wok2ModbusTcpServer.get().plcIsConnect) {
if (plcaddress.address.toUpperCase().startsWith("VD"))//int
{
Wok2ModbusTcpServer.get().WriteInt(plcaddress.address, (int) value, callback);
} else if (plcaddress.address.toUpperCase().startsWith("M"))//bool
{
Wok2ModbusTcpServer.get().WriteBool(plcaddress.address, (boolean) value, callback);
} else if (plcaddress.address.toUpperCase().startsWith("VW"))//short
{
Wok2ModbusTcpServer.get().WriteShort(plcaddress.address, Short.parseShort(value.toString()), callback);
} else if (plcaddress.address.toUpperCase().startsWith("VR"))//float
{
Wok2ModbusTcpServer.get().WriteFloat(plcaddress.address, Float.parseFloat(value.toString()), callback);
}
}
break;
case 3:
break;
case 4:
break;
}
}
} catch (Exception ex) {
LogUtils.d("异常信息:" + ex.getMessage());
NewToastUtil.getInstance().showToastError("异常信息:" + ex.getMessage());
} finally {

@@ -413,25 +506,50 @@ public class ModbusCenter {
/**
* 读取状态
*/
public static void ReadPLCStatus() {
public static void ReadPLCStatus(int deviceNum) {
try {
if (WokModbusTcpServer.get().plcIsConnect) {
WokModbusTcpServer.get().ReadStatus("VW354", 1, data -> {
for (int i = 0; i < data.length; i++) {
byte status = data[i];//0x92
IoStatus.put(i * 8 + 0, ByteHelper.getBit(status, 0) == 1);
IoStatus.put(i * 8 + 1, ByteHelper.getBit(status, 1) == 1);
IoStatus.put(i * 8 + 2, ByteHelper.getBit(status, 2) == 1);
IoStatus.put(i * 8 + 3, ByteHelper.getBit(status, 3) == 1);
IoStatus.put(i * 8 + 4, ByteHelper.getBit(status, 4) == 1);
IoStatus.put(i * 8 + 5, ByteHelper.getBit(status, 5) == 1);
IoStatus.put(i * 8 + 6, ByteHelper.getBit(status, 6) == 1);
IoStatus.put(i * 8 + 7, ByteHelper.getBit(status, 7) == 1);
switch (deviceNum){
case 1:
if (WokModbusTcpServer.get().plcIsConnect) {
WokModbusTcpServer.get().ReadStatus("VW354", 1, data -> {
for (int i = 0; i < data.length; i++) {
byte status = data[i];//0x92
IoStatus.put(i * 8 + 0, ByteHelper.getBit(status, 0) == 1);
IoStatus.put(i * 8 + 1, ByteHelper.getBit(status, 1) == 1);
IoStatus.put(i * 8 + 2, ByteHelper.getBit(status, 2) == 1);
IoStatus.put(i * 8 + 3, ByteHelper.getBit(status, 3) == 1);
IoStatus.put(i * 8 + 4, ByteHelper.getBit(status, 4) == 1);
IoStatus.put(i * 8 + 5, ByteHelper.getBit(status, 5) == 1);
IoStatus.put(i * 8 + 6, ByteHelper.getBit(status, 6) == 1);
IoStatus.put(i * 8 + 7, ByteHelper.getBit(status, 7) == 1);
}
});
}
});
break;
case 2:
if (Wok2ModbusTcpServer.get().plcIsConnect) {
Wok2ModbusTcpServer.get().ReadStatus("VW354", 1, data -> {
for (int i = 0; i < data.length; i++) {
byte status = data[i];//0x92
IoStatus2.put(i * 8 + 0, ByteHelper.getBit(status, 0) == 1);
IoStatus2.put(i * 8 + 1, ByteHelper.getBit(status, 1) == 1);
IoStatus2.put(i * 8 + 2, ByteHelper.getBit(status, 2) == 1);
IoStatus2.put(i * 8 + 3, ByteHelper.getBit(status, 3) == 1);
IoStatus2.put(i * 8 + 4, ByteHelper.getBit(status, 4) == 1);
IoStatus2.put(i * 8 + 5, ByteHelper.getBit(status, 5) == 1);
IoStatus2.put(i * 8 + 6, ByteHelper.getBit(status, 6) == 1);
IoStatus2.put(i * 8 + 7, ByteHelper.getBit(status, 7) == 1);
}
});
}
break;
case 3:
break;
case 4:
break;
}

} catch (Exception ex) {
LogUtils.d("异常信息:" + ex.getMessage());
NewToastUtil.getInstance().showToastError("异常信息:" + ex.getMessage());
} finally {
}
@@ -441,6 +559,7 @@ public class ModbusCenter {
* 实时状态
*/
public static ConcurrentHashMap<Integer, Boolean> IoStatus = new ConcurrentHashMap<Integer, Boolean>();
public static ConcurrentHashMap<Integer, Boolean> IoStatus2 = new ConcurrentHashMap<Integer, Boolean>();

/**
* 获取实时状态
@@ -448,7 +567,23 @@ public class ModbusCenter {
* @param ch
* @return
*/
public static boolean getConcurrentHash(int ch) {
public static boolean getConcurrentHash(int deviceNum,int ch) {
switch (deviceNum){
case 1:
if (!IoStatus.containsKey(ch)) {
return false;
}
return IoStatus.get(ch);
case 2:
if (!IoStatus2.containsKey(ch)) {
return false;
}
return IoStatus2.get(ch);
case 3:
break;
case 4:
break;
}
if (!IoStatus.containsKey(ch)) {
return false;
}
@@ -465,7 +600,6 @@ public class ModbusCenter {
if(ConfigName.TEST){
return true;
}
LogUtils.d("robotWritePlc name1="+name);
final Object[] ReturnsVariable = {null};
try {
if (plcAddress.get(name)!=null) {
@@ -495,7 +629,6 @@ public class ModbusCenter {
}
}
} catch (Exception ex) {
LogUtils.d("异常信息:" + ex.getMessage());
NewToastUtil.getInstance().showToastError("异常信息:" + ex.getMessage());
} finally {
return ReturnsVariable[0];
@@ -537,10 +670,9 @@ public class ModbusCenter {
* */

/*
* 《-------------烤箱相关
* -------------货架相关
* */

public static Object ovenReadPlc(String name){
public static Object rackReadPlc(String name){
if(ConfigName.TEST){
return true;
}
@@ -548,16 +680,16 @@ public class ModbusCenter {
try {
if (plcAddress.get(name)!=null) {
BPA_PLCADDRESS plcaddress = plcAddress.get(name);
if (!plcaddress.address.isEmpty() && OvenModbusTcpServer.get().plcIsConnect) {
if (!plcaddress.address.isEmpty() && RackModbusTcpServer.get().plcIsConnect) {
if (plcaddress.address.toUpperCase().startsWith("M"))//bool
{
OvenModbusTcpServer.get().ReadBool(plcaddress.address, 1, val -> {
RackModbusTcpServer.get().ReadBool(plcaddress.address, 1, val -> {
ReturnsVariable[0] = val[0];
MessageLog.ShowInfo(" ovenReadPlc name="+name+";plcaddress.address="+plcaddress.address+";result="+val[0]);
});
} else if (plcaddress.address.toUpperCase().startsWith("VW"))//short
{
OvenModbusTcpServer.get().ReadShort(plcaddress.address, 1, val -> {
RackModbusTcpServer.get().ReadShort(plcaddress.address, 1, val -> {
ReturnsVariable[0] = val[0];
MessageLog.ShowInfo(" ovenReadPlc name="+name+";plcaddress.address="+plcaddress.address+";result="+val[0]);
});
@@ -567,35 +699,30 @@ public class ModbusCenter {
}
}
} catch (Exception ex) {
LogUtils.d("异常信息:" + ex.getMessage());
NewToastUtil.getInstance().showToastError("异常信息:" + ex.getMessage());
} finally {
return ReturnsVariable[0];
}
}
public static void ovenWritePlc(String name, Object value, IWriteCallBack callback){
public static void rackWritePlc(String name, Object value, IWriteCallBack callback){
try {
if (plcAddress.get(name)!=null) {
BPA_PLCADDRESS plcaddress = plcAddress.get(name);
if (!plcaddress.address.isEmpty() && OvenModbusTcpServer.get().plcIsConnect) {
if (!plcaddress.address.isEmpty() && RackModbusTcpServer.get().plcIsConnect) {
if (plcaddress.address.toUpperCase().startsWith("M"))//bool
{
OvenModbusTcpServer.get().WriteBool(plcaddress.address, (boolean) value, callback);
RackModbusTcpServer.get().WriteBool(plcaddress.address, (boolean) value, callback);
} else if (plcaddress.address.toUpperCase().startsWith("VW"))//short
{
OvenModbusTcpServer.get().WriteShort(plcaddress.address, Short.parseShort(value.toString()), callback);
RackModbusTcpServer.get().WriteShort(plcaddress.address, Short.parseShort(value.toString()), callback);
}
}
}
} catch (Exception ex) {
LogUtils.d("异常信息:ovenWritePlc name=" +name+ " "+ ex.getMessage());
NewToastUtil.getInstance().showToastError("异常信息: name=" +name+ " "+ ex.getMessage());
NewToastUtil.getInstance().showToastError("异常信息:" + ex.getMessage());
} finally {

}
}

/**
* 烤箱相关--------------》
* */
}

+ 0
- 265
app/src/main/java/com/bonait/bnframework/modbus/OvenModbusTcpServer.java View File

@@ -1,265 +0,0 @@
package com.bonait.bnframework.modbus;


import android.util.Log;

import com.apkfuns.logutils.LogUtils;
import com.bonait.bnframework.HBL.Logs.MessageLog;
import com.bonait.bnframework.HBL.Thread.IThread;
import com.bonait.bnframework.HBL.Thread.ThreadManager;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.helper.DataFormat;
import com.bonait.bnframework.common.helper.I.IReadCallBack;
import com.bonait.bnframework.common.helper.I.IWriteCallBack;
import com.bonait.bnframework.newui.widget.NewToastUtil;
import com.licheedev.modbus4android.ModbusCallback;
import com.licheedev.modbus4android.ModbusParam;
import com.licheedev.modbus4android.ModbusRespException;
import com.licheedev.modbus4android.param.TcpParam;
import com.serotonin.modbus4j.ModbusMaster;
import com.serotonin.modbus4j.exception.ModbusInitException;
import com.serotonin.modbus4j.exception.ModbusTransportException;
import com.serotonin.modbus4j.msg.ReadCoilsResponse;
import com.serotonin.modbus4j.msg.ReadHoldingRegistersResponse;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;


public class OvenModbusTcpServer {
private static String TAG = "OvenModbusTcpServer";
private static volatile OvenModbusTcpServer instance = null;
public boolean plcIsConnect = false;
public static OvenModbusTcpServer get() {
OvenModbusTcpServer manager = instance;
if (manager == null) {
synchronized (OvenModbusTcpServer.class) {
manager = instance;
if (manager == null) {
manager = new OvenModbusTcpServer();
instance = manager;
}
}
}
return manager;
}

private OvenModbusTcpServer() {
}

public boolean checkConnect(){
if(!plcIsConnect){
NewToastUtil.getInstance().showToast("烤箱/货架设备未连接!");
return false;
}
return true;
}

static ModbusParam param;


public void DisConnect(){
plcIsConnect = false;
OvenModbusTcpHelper.get().release();
}

/**
* 重连
* @param error
*/
public void ReConnect(String error){
if(ConfigName.TEST){
plcIsConnect = true;
return;
}
plcIsConnect = false;
if(error.contains("Connection refused")||error.contains("SocketException")){
ConnectPLC();
}
}

/**
* 连接PLC
*/
public static void ConnectPLC()
{
ThreadManager.get().StartLong("烤箱PLC重连", false, new IThread() {
@Override
public void Run() throws InterruptedException {
while (!OvenModbusTcpServer.get().plcIsConnect){
String host=ModbusCenter.ovenAddress;
int port=ModbusCenter.ovenPost;
param = TcpParam.create(host, port)
.setTimeout(1000)
.setRetries(0)
.setEncapsulated(false)
.setKeepAlive(true);
OvenModbusTcpHelper.get().init(param, new ModbusCallback<ModbusMaster>() {
@Override
public void onSuccess(ModbusMaster modbusMaster) {
MessageLog.ShowInfo("烤箱设备 " + ModbusCenter.ovenAddress + " 连接成功");
OvenModbusTcpServer.get().plcIsConnect = true;
Log.e("设备PLC", "烤箱设备PLC: 连接成功");
ThreadManager.get().Stop("烤箱设备重连");
ModbusCenter.Listening();
}

@Override
public void onFailure(Throwable tr) {
OvenModbusTcpServer.get().plcIsConnect = false;
MessageLog.ShowError("烤箱PLC设备 " + ModbusCenter.ovenAddress + " 连接失败:" + tr.getMessage());
Log.e("设备PLC", "烤箱设备PLC: 连接断开");
}

@Override
public void onFinally() {

}
});
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
ThreadManager.get().Stop("烤箱PLC重连");
}
});

}

private int GetAddress(String address) {
if (address == null) return -1;
if (address.length() > 0) {
address = address.trim();
if (address.toUpperCase().contains("M") && address.length() >= 4) {
String[] res = address.substring(1).split("[.]");
if (res != null && res.length == 2) {
try {
int firstAdd = Integer.parseInt(res[0]);
int endAdd = Integer.parseInt(res[1]);
if (endAdd >= 0 && endAdd <= 7) {
return (firstAdd * 8) + 320 + endAdd;
}
} catch (NumberFormatException e) {
return -1;
}
}
} else if (address.toUpperCase().contains("I") && address.length() >= 4) {
String[] res = address.substring(1).split("[.]");
if (res != null && res.length == 2) {
try {
int firstAdd = Integer.parseInt(res[0]);
int endAdd = Integer.parseInt(res[1]);
if (endAdd >= 0 && endAdd <= 7) {
return (firstAdd * 8) + endAdd;
}
} catch (NumberFormatException e) {
return -1;
}
}
} else if ((address.toUpperCase().contains("VW") || address.toUpperCase().contains("VD")) && address.length() >= 3) {
String res = address.substring(2);
if (res != null) {
try {
int tempAdd = Integer.parseInt(res);
return (tempAdd / 2) + 100;
} catch (NumberFormatException e) {
return -1;
}
}
} else if ((address.toUpperCase().contains("VR")) && address.length() >= 3) {
String res = address.substring(2);
if (res != null) {
try {
//todo
int tempAdd = Integer.parseInt(res);
return (tempAdd / 2) + 100;
} catch (NumberFormatException e) {
return -1;
}
}
} else {
try {
return Integer.parseInt(address);
} catch (NumberFormatException e) {
return -1;
}
}
}
return -1;
}


public void ReadShort(String Address, int length, IReadCallBack<short[]> callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
ReadHoldingRegistersResponse res = OvenModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length);
short[] data = res.getShortData();
if (data.length == length) {
if (callback != null) callback.onSuccess(data);
}
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
}
}

public void ReadBool(String Address, int length, IReadCallBack<boolean[]> callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
ReadCoilsResponse res = OvenModbusTcpHelper.get().syncReadCoil(1, add, length);
boolean[] data = res.getBooleanData();
boolean[] result = Arrays.copyOfRange(data, 0, length);

if (result.length == length) {
if (callback != null) callback.onSuccess(result);
}
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
}
}

public void WriteShort(String Address, short Value, IWriteCallBack callback) {
int add = GetAddress(Address);
if (add < 0) return;
short[] send = new short[1];
send[0] = Value;
try {
OvenModbusTcpHelper.get().syncWriteRegisters(1, add, send);
if (callback != null)
callback.onSuccess();
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
if (callback != null) callback.onFailure(e.toString());
}
}

public void WriteBool(String Address, boolean Value, IWriteCallBack callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
OvenModbusTcpHelper.get().syncWriteCoil(1, add, Value);
if (callback != null)
callback.onSuccess();
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
if (callback != null) callback.onFailure(e.toString());
}
}

}

app/src/main/java/com/bonait/bnframework/modbus/OvenModbusTcpHelper.java → app/src/main/java/com/bonait/bnframework/modbus/RackModbusTcpHelper.java View File

@@ -4,16 +4,16 @@ import com.licheedev.modbus4android.ModbusWorker;
import com.serotonin.modbus4j.ModbusMaster;


public class OvenModbusTcpHelper extends ModbusWorker {
private static volatile OvenModbusTcpHelper instance = null;
public class RackModbusTcpHelper extends ModbusWorker {
private static volatile RackModbusTcpHelper instance = null;

public static OvenModbusTcpHelper get() {
OvenModbusTcpHelper manager = instance;
public static RackModbusTcpHelper get() {
RackModbusTcpHelper manager = instance;
if (manager == null) {
synchronized (OvenModbusTcpHelper.class) {
synchronized (RackModbusTcpHelper.class) {
manager = instance;
if (manager == null) {
manager = new OvenModbusTcpHelper();
manager = new RackModbusTcpHelper();
instance = manager;
}
}
@@ -21,7 +21,7 @@ public class OvenModbusTcpHelper extends ModbusWorker {
return manager;
}

private OvenModbusTcpHelper() {
private RackModbusTcpHelper() {
}

/**

+ 660
- 0
app/src/main/java/com/bonait/bnframework/modbus/RackModbusTcpServer.java View File

@@ -0,0 +1,660 @@
package com.bonait.bnframework.modbus;


import android.util.Log;

import com.bonait.bnframework.HBL.Logs.MessageLog;
import com.bonait.bnframework.HBL.Thread.ThreadManager;
import com.bonait.bnframework.Service.ModbusTcpHelper;
import com.bonait.bnframework.common.helper.DataFormat;
import com.bonait.bnframework.common.helper.I.IReadCallBack;
import com.bonait.bnframework.common.helper.I.IWriteCallBack;
import com.bonait.bnframework.newui.widget.NewToastUtil;
import com.licheedev.modbus4android.ModbusCallback;
import com.licheedev.modbus4android.ModbusParam;
import com.licheedev.modbus4android.ModbusRespException;
import com.licheedev.modbus4android.param.TcpParam;
import com.serotonin.modbus4j.ModbusMaster;
import com.serotonin.modbus4j.exception.ModbusInitException;
import com.serotonin.modbus4j.exception.ModbusTransportException;
import com.serotonin.modbus4j.msg.ReadCoilsResponse;
import com.serotonin.modbus4j.msg.ReadHoldingRegistersResponse;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;


public class RackModbusTcpServer {
private static volatile RackModbusTcpServer instance = null;
public boolean plcIsConnect = false;
public static RackModbusTcpServer get() {
RackModbusTcpServer manager = instance;
if (manager == null) {
synchronized (RackModbusTcpServer.class) {
manager = instance;
if (manager == null) {
manager = new RackModbusTcpServer();
instance = manager;
}
}
}
return manager;
}

private RackModbusTcpServer() {
}

public boolean checkConnect(){
if(!plcIsConnect){
NewToastUtil.getInstance().showToast("烤箱/货架设备未连接!");
return false;
}
return true;
}

static ModbusParam param;

private int GetAddress(String address) {
if (address == null) return -1;
if (address.length() > 0) {
address = address.trim();
if (address.toUpperCase().contains("M") && address.length() >= 4) {
String[] res = address.substring(1).split("[.]");
if (res != null && res.length == 2) {
try {
int firstAdd = Integer.parseInt(res[0]);
int endAdd = Integer.parseInt(res[1]);
if (endAdd >= 0 && endAdd <= 7) {
return (firstAdd * 8) + 320 + endAdd;
}
} catch (NumberFormatException e) {
return -1;
}
}
} else if (address.toUpperCase().contains("I") && address.length() >= 4) {
String[] res = address.substring(1).split("[.]");
if (res != null && res.length == 2) {
try {
int firstAdd = Integer.parseInt(res[0]);
int endAdd = Integer.parseInt(res[1]);
if (endAdd >= 0 && endAdd <= 7) {
return (firstAdd * 8) + endAdd;
}
} catch (NumberFormatException e) {
return -1;
}
}
} else if ((address.toUpperCase().contains("VW") || address.toUpperCase().contains("VD")) && address.length() >= 3) {
String res = address.substring(2);
if (res != null) {
try {
int tempAdd = Integer.parseInt(res);
return (tempAdd / 2) + 100;
} catch (NumberFormatException e) {
return -1;
}
}
} else if ((address.toUpperCase().contains("VR")) && address.length() >= 3) {
String res = address.substring(2);
if (res != null) {
try {
//todo
int tempAdd = Integer.parseInt(res);
return (tempAdd / 2) + 100;
} catch (NumberFormatException e) {
return -1;
}
}
} else {
try {
return Integer.parseInt(address);
} catch (NumberFormatException e) {
return -1;
}
}
}
return -1;
}

/**
* 获取布尔位地址信息
* 列:M2.5 = getBitSingleAdd("M",2,5);
*
* @param Prefix 地址标头
* @param startAdd 起始地址编号
* @param num 要获取的第几位数量
* @return
*/
public String getBitSingleAdd(String Prefix, int startAdd, int num) {
if (num > 0) {
int FirstAdd = num / 8;
int EndAdd = num % 8;
if (EndAdd == 0) {
FirstAdd--;
EndAdd = 7;
} else {
EndAdd--;
}
return Prefix + FirstAdd + startAdd + "." + EndAdd;
}
return "";
}

/**
* Ping PLC地址是否通畅
* @param address
* @param pingTimes ping的次数
* @param timeOut 超时时间 10
* @return
*/
public static boolean ping2(String address, int pingTimes, int timeOut) {
Process process = null;
try {
process = Runtime.getRuntime().exec( "ping " + "-c " + pingTimes + " -w " + timeOut+ " "+address);
InputStreamReader r = new InputStreamReader(process.getInputStream());

LineNumberReader returnData = new LineNumberReader(r);

String returnMsg="";

String line = "";

while ((line = returnData.readLine()) != null) {

System.out.println(line);

returnMsg += line;

}

if(returnMsg.indexOf("100% packet loss")!=-1){
System.out.println("与 " +address +" 连接不畅通.");
//ToastUtils.info("与 " +address +" 连接不畅通.");
return false;
} else{
System.out.println("与 " +address +" 连接畅通.");
//ToastUtils.info("与 " +address +" 连接不畅通.");
return true;
}
} catch (IOException e) {
// e.printStackTrace();
}
return false;

}

public void DisConnect(){
plcIsConnect = false;
RackModbusTcpHelper.get().release();
}

/**
* 重连
* @param error
*/
public void ReConnect(String error){
if(error.contains("Connection refused")||error.contains("SocketException")){
plcIsConnect = false;
ConnectPLC();
}
}

/**
* 连接PLC
*/
public static void ConnectPLC()
{
ThreadManager.get().StartLong("烤箱设备重连",true, () -> {
while (!RackModbusTcpServer.get().plcIsConnect){
String host=ModbusCenter.rackAddress;
int port=ModbusCenter.rackPost;
param = TcpParam.create(host, port)
.setTimeout(1000)
.setRetries(0)
.setEncapsulated(false)
.setKeepAlive(true);
ModbusTcpHelper.get().init(param, new ModbusCallback<ModbusMaster>() {
@Override
public void onSuccess(ModbusMaster modbusMaster) {
// NewToastUtil.getInstance().showToastError("设备 " + ModbusCenter.Address + " 连接成功");
MessageLog.ShowInfo("设备 " + ModbusCenter.rackAddress + " 连接成功");
RackModbusTcpServer.get().plcIsConnect = true;
Log.e("设备PLC", "设备PLC: 连接成功");
}

@Override
public void onFailure(Throwable tr) {
RackModbusTcpServer.get().plcIsConnect = false;
// NewToastUtil.getInstance().showToastError("设备 " + ModbusCenter.Address + " 连接失败:" + tr.getMessage());
MessageLog.ShowError("PLC设备 " + ModbusCenter.rackAddress + " 连接失败:" + tr.getMessage());
Log.e("设备PLC", "设备PLC: 连接断开");
}

@Override
public void onFinally() {

}
});
Thread.sleep(3000);
}
});

}


private Float BytesToFloat(byte[] buffers, DataFormat df) {
if (buffers.length == 4) {
byte[] bytes = new byte[4];
if (df == DataFormat.ABCD) {
bytes[0] = buffers[3];
bytes[1] = buffers[2];
bytes[2] = buffers[1];
bytes[3] = buffers[0];
} else if (df == DataFormat.CDAB) {
bytes[0] = buffers[1];
bytes[1] = buffers[0];
bytes[2] = buffers[3];
bytes[3] = buffers[2];
} else if (df == DataFormat.BADC) {
bytes[0] = buffers[2];
bytes[1] = buffers[3];
bytes[2] = buffers[0];
bytes[3] = buffers[1];
} else if (df == DataFormat.DCBA) {
bytes[0] = buffers[0];
bytes[1] = buffers[1];
bytes[2] = buffers[2];
bytes[3] = buffers[3];
}
return ByteBuffer.wrap(bytes).getFloat();
}
return 0.0f;
}

private Integer BytesToInt(byte[] buffers, DataFormat df) {
if (buffers.length == 4) {
byte[] bytes = new byte[4];
if (df == DataFormat.ABCD) {
bytes[0] = buffers[3];
bytes[1] = buffers[2];
bytes[2] = buffers[1];
bytes[3] = buffers[0];
} else if (df == DataFormat.CDAB) {
bytes[0] = buffers[1];
bytes[1] = buffers[0];
bytes[2] = buffers[3];
bytes[3] = buffers[2];
} else if (df == DataFormat.BADC) {
bytes[0] = buffers[2];
bytes[1] = buffers[3];
bytes[2] = buffers[0];
bytes[3] = buffers[1];
} else if (df == DataFormat.DCBA) {
bytes[0] = buffers[0];
bytes[1] = buffers[1];
bytes[2] = buffers[2];
bytes[3] = buffers[3];
}
return ByteBuffer.wrap(bytes).getInt();
}
return 0;
}

private byte[] IntToByte(int number) {
int temp = number;
byte[] b = new byte[4];
for (int i = 0; i < b.length; i++) {
b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位
temp = temp >> 8; // 向右移8位
}
return b;
}

private short[] IntToShorts(int value) {
short[] res = new short[2];
int temp = value;
byte[] b = new byte[4];
for (int i = 0; i < b.length; i++) {
b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位
temp = temp >> 8; // 向右移8位
}
for (int i = 0; i < res.length; i++) {
short s0 = (short) (b[i * 2] & 0xff);// 最低位
short s1 = (short) (b[i * 2 + 1] & 0xff);
s1 <<= 8;
res[i] = (short) (s0 | s1);
}
return res;
}

public static String GetString(short[] src, int start, int len) throws UnsupportedEncodingException {
short[] temp = new short[len];
for (int i = 0; i < len; i++) {
temp[i] = src[i + start];
}
byte[] bytesTemp = shorts2Bytes(temp);
for (int i = 0; i < bytesTemp.length; i++) {
byte b = bytesTemp[i];
}
String str = new String(bytesTemp, "UTF-8");
return str;
}

public static byte[] shorts2Bytes(short[] data) {
byte[] byteValue = new byte[data.length * 2];
for (int i = 0; i < data.length; i++) {
byteValue[i * 2] = (byte) (data[i] & 0xff);
byteValue[i * 2 + 1] = (byte) ((data[i] & 0xff00) >> 8);
}
return byteValue;
}

/***
*读取实时状态
* @param Address the address
* @param length 读取的长度 3
* @param callback 读取成功的回调
*/
public void ReadStatus(String Address, int length, IReadCallBack<byte[]> callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length);
byte[] data = res.getData();
byte[] tempData = new byte[6];
tempData[0] = data[1];
tempData[1] = data[0];
if (callback != null) callback.onSuccess(tempData);
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
}
}

/***
*读取扫码数据
* @param Address the address
* @param length 读取的长度
* @param callback 读取成功的回调
*/
public void ReadString(String Address, int length, IReadCallBack<String> callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length);
byte[] data = res.getData();
byte[] data1 = Arrays.copyOfRange(data, 0, 18);
//36 GUID 18 Number
String id = "";
try {
byte[] tempdata = new byte[18];
for (int i = 0; i < data1.length; i++) {
if (i % 2 == 0) {

tempdata[i + 1] = data1[i];
} else {
tempdata[i - 1] = data1[i];
}
}
id = new String(tempdata, "UTF-8").trim();
} catch (UnsupportedEncodingException ex) {
}
if (callback != null) callback.onSuccess(id);
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
}
}

public void WriteString(String Address, int length, IWriteCallBack callback) {
int add = GetAddress(Address);
if (add < 0) return;
short[] send = new short[length];
for (short item : send) {
item = 0;
}
try {
ModbusTcpHelper.get().syncWriteRegisters(1, add, send);
if (callback != null)
callback.onSuccess();
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
if (callback != null) callback.onFailure(e.toString());
}
}

public void ReadShort(String Address, int length, IReadCallBack<short[]> callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length);
short[] data = res.getShortData();
if (data.length == length) {
if (callback != null) callback.onSuccess(data);
}
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
}
}

public void ReadBool(String Address, int length, IReadCallBack<boolean[]> callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
ReadCoilsResponse res = ModbusTcpHelper.get().syncReadCoil(1, add, length);
boolean[] data = res.getBooleanData();
boolean[] result = Arrays.copyOfRange(data, 0, length);
if (result.length == length) {
if (callback != null) callback.onSuccess(result);
}
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
}
}

public void ReadFloat(String Address, int length, IReadCallBack<float[]> callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length*2);
byte[] data = res.getData();
float[] tempValues = new float[length];
for (int i = 0; i < length; i++) {
byte[] tempData = new byte[4];
for (int m = 0; m < 4; m++) {
tempData[m] = data[i * 4 + m];
}
tempValues[i] = BytesToFloat(tempData, DataFormat.BADC);
}
if (tempValues.length == length) {
if (callback != null) callback.onSuccess(tempValues);
}
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
}
}

public void ReadInt(String Address, int length, IReadCallBack<int[]> callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length * 2);
byte[] data = res.getData();
int[] tempValues = new int[length];
if(data.length>=4)
{
for (int i = 0; i < length; i++) {
byte[] tempData = new byte[4];
for (int m = 0; m < 4; m++) {
tempData[m] = data[i * 4 + m];
}
// Integer a1 = tempValues[i] = BytesToInt(tempData, DataFormat.ABCD);
// Integer a2 = tempValues[i] = BytesToInt(tempData, DataFormat.BADC);
// Integer a3 = tempValues[i] = BytesToInt(tempData, DataFormat.CDAB);
// Integer a4 = tempValues[i] = BytesToInt(tempData, DataFormat.DCBA);
tempValues[i] = BytesToInt(tempData, DataFormat.BADC);
}
}else
{
MessageLog.ShowError("ReadInt onFailure,Address=" );

}
if (callback != null) callback.onSuccess(tempValues);
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
}
}

public void WriteShort(String Address, short Value, IWriteCallBack callback) {
int add = GetAddress(Address);
if (add < 0) return;
short[] send = new short[1];
send[0] = Value;
try {
ModbusTcpHelper.get().syncWriteRegisters(1, add, send);
if (callback != null)
callback.onSuccess();
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
if (callback != null) callback.onFailure(e.toString());
}
}

public void WriteBool(String Address, boolean Value, IWriteCallBack callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
ModbusTcpHelper.get().syncWriteCoil(1, add, Value);
if (callback != null)
callback.onSuccess();
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
if (callback != null) callback.onFailure(e.toString());
}
}

public void WriteFloat(String Address, float Value, IWriteCallBack callback) {
int add = GetAddress(Address);
if (add < 0) return;
int intBits = Float.floatToRawIntBits(Value);

short[] send = IntToShorts(intBits);
// short[] send = new short[]{(short) ((intBits >> 16) & 0xffff), (short) (intBits & 0xffff)};
try {
ModbusTcpHelper.get().syncWriteRegisters(1, add, send);

if (callback != null) callback.onSuccess();
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
if (callback != null) callback.onFailure(e.toString());
}
}

public void WriteInt(String Address, int Value, IWriteCallBack callback) {
int add = GetAddress(Address);
if (add < 0) return;
short[] send = IntToShorts(Value);
try {
ModbusTcpHelper.get().syncWriteRegisters(1, add, send);
if (callback != null) callback.onSuccess();
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
if (callback != null) callback.onFailure(e.toString());
}
}

public void WriteShort(String Address, short Value) {
int add = GetAddress(Address);
if (add < 0) return;
short[] send = new short[1];
send[0] = Value;
try {
ModbusTcpHelper.get().syncWriteRegisters(1, add, send);
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
}
}

public void WriteBool(String Address, boolean Value) {
int add = GetAddress(Address);
if (add < 0) return;

try {
ModbusTcpHelper.get().syncWriteCoil(1, add, Value);
plcIsConnect = true;
}catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
}
}

public void WriteFloat(String Address, float Value) {
int add = GetAddress(Address);
if (add < 0) return;
int intBits = Float.floatToRawIntBits(Value);
short[] send = new short[]{(short) ((intBits >> 16) & 0xffff), (short) (intBits & 0xffff)};
try {
ModbusTcpHelper.get().syncWriteRegisters(1, add, send);
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
}
}

public void WriteInt(String Address, int Value) {
int add = GetAddress(Address);
if (add < 0) return;
short[] send = IntToShorts(Value);
try {
ModbusTcpHelper.get().syncWriteRegisters(1, add, send);
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
}
}

}

+ 2
- 0
app/src/main/java/com/bonait/bnframework/modbus/RobotModbusTcpServer.java View File

@@ -69,6 +69,8 @@ public class RobotModbusTcpServer {
}
} else if (address.toUpperCase().contains("GI0")){
return 0;
} else if (address.toUpperCase().contains("GI1")){
return 1;
} else if (address.toUpperCase().contains("GI5")){
return 5;
}else {


+ 44
- 0
app/src/main/java/com/bonait/bnframework/modbus/Wok2ModbusTcpHelper.java View File

@@ -0,0 +1,44 @@
package com.bonait.bnframework.modbus;

import com.licheedev.modbus4android.ModbusWorker;
import com.serotonin.modbus4j.ModbusMaster;


public class Wok2ModbusTcpHelper extends ModbusWorker {
private static volatile Wok2ModbusTcpHelper instance = null;

public static Wok2ModbusTcpHelper get() {
Wok2ModbusTcpHelper manager = instance;
if (manager == null) {
synchronized (Wok2ModbusTcpHelper.class) {
manager = instance;
if (manager == null) {
manager = new Wok2ModbusTcpHelper();
instance = manager;
}
}
}
return manager;
}

private Wok2ModbusTcpHelper() {
}

/**
* 释放整个ModbusManager,单例会被置null
*/
public synchronized void release() {
super.release();
instance = null;
}

/**
* 获取
* @return
*/
public synchronized ModbusMaster getModbusMaster()
{
return super.getModbusMaster();
}

}

+ 488
- 0
app/src/main/java/com/bonait/bnframework/modbus/Wok2ModbusTcpServer.java View File

@@ -0,0 +1,488 @@
package com.bonait.bnframework.modbus;


import android.util.Log;

import com.bonait.bnframework.HBL.Logs.MessageLog;
import com.bonait.bnframework.HBL.Thread.IThread;
import com.bonait.bnframework.HBL.Thread.ThreadManager;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.helper.DataFormat;
import com.bonait.bnframework.common.helper.I.IReadCallBack;
import com.bonait.bnframework.common.helper.I.IWriteCallBack;
import com.bonait.bnframework.newui.widget.NewToastUtil;
import com.licheedev.modbus4android.ModbusCallback;
import com.licheedev.modbus4android.ModbusParam;
import com.licheedev.modbus4android.ModbusRespException;
import com.licheedev.modbus4android.param.TcpParam;
import com.serotonin.modbus4j.ModbusMaster;
import com.serotonin.modbus4j.exception.ModbusInitException;
import com.serotonin.modbus4j.exception.ModbusTransportException;
import com.serotonin.modbus4j.msg.ReadCoilsResponse;
import com.serotonin.modbus4j.msg.ReadHoldingRegistersResponse;

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.concurrent.ExecutionException;


public class Wok2ModbusTcpServer {
private static volatile Wok2ModbusTcpServer instance = null;
public boolean plcIsConnect = false;
/**
* 监听变量值
*/
public static HashMap<String, Object> listeningValue = new HashMap<String, Object>();
public static Wok2ModbusTcpServer get() {
Wok2ModbusTcpServer manager = instance;
if (manager == null) {
synchronized (Wok2ModbusTcpServer.class) {
manager = instance;
if (manager == null) {
manager = new Wok2ModbusTcpServer();
instance = manager;
}
}
}
return manager;
}

private Wok2ModbusTcpServer() {
}

static ModbusParam param;

public void DisConnect(){
plcIsConnect = false;
WokModbusTcpHelper.get().release();
}

/**
* 重连
* @param error
*/
public void ReConnect(String error){
if(ConfigName.TEST){
plcIsConnect = true;
return;
}
plcIsConnect = false;
if(error.contains("Connection refused")||error.contains("SocketException")){
ConnectPLC();
}
}

public boolean checkConnect(){
if(!plcIsConnect){
NewToastUtil.getInstance().showToast("炒锅设备未连接!");
return false;
}
return true;
}

/**
* 获取监听变量
*/
public static Object getListingValue(String name) {
if (!listeningValue.containsKey(name)) {
return null;
}
return listeningValue.get(name);
}

/**
* 连接PLC
*/
public static void ConnectPLC()
{
ThreadManager.get().StartLong("炒锅PLC重连", false, new IThread() {
@Override
public void Run() throws InterruptedException {
while (!Wok2ModbusTcpServer.get().plcIsConnect){
String host=ModbusCenter.wok2Address;
int port=ModbusCenter.wok2Post;
param = TcpParam.create(host, port)
.setTimeout(1000)
.setRetries(0)
.setEncapsulated(false)
.setKeepAlive(true);
WokModbusTcpHelper.get().init(param, new ModbusCallback<ModbusMaster>() {
@Override
public void onSuccess(ModbusMaster modbusMaster) {
MessageLog.ShowInfo("炒锅设备 " + ModbusCenter.wokAddress + " 连接成功");
Wok2ModbusTcpServer.get().plcIsConnect = true;
Log.e("炒锅设备PLC", "炒锅设备PLC: 连接成功");
ThreadManager.get().Stop("炒锅设备重连");
ModbusCenter.Listening();
init();
}

@Override
public void onFailure(Throwable tr) {
Wok2ModbusTcpServer.get().plcIsConnect = false;
MessageLog.ShowError("炒锅PLC设备 " + ModbusCenter.wokAddress + " 连接失败:" + tr.getMessage());
Log.e("炒锅设备PLC", "炒锅设备PLC: 连接断开");
}

@Override
public void onFinally() {

}
});
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
ThreadManager.get().Stop("炒锅PLC重连");
}});
}

public static void init(){
new Thread(new Runnable() {
@Override
public void run() {
try {
if(Wok2ModbusTcpServer.get().plcIsConnect){
ModbusCenter.WritePlc(1,"初始化", true, null);
Thread.sleep(500);
ModbusCenter.WritePlc(1,"初始化", false, null);

ModbusCenter.WritePlc(1,"温控开关", false, null);//开关闭合
ModbusCenter.WritePlc(1,"暂停开关", false, null);//开关闭合

ModbusCenter.WritePlc(1,"校准时间", 50, null);//默认校准时间5秒
ModbusCenter.WritePlc(1,"料仓1校准开关", false, null);//默认校准时间5秒
ModbusCenter.WritePlc(1,"料仓2校准开关", false, null);//默认校准时间5秒
ModbusCenter.WritePlc(1,"料仓3校准开关", false, null);//默认校准时间5秒

Wok2ModbusTcpServer.get().WriteBool("M52.1", (boolean) false, null);
//读取版本号
Wok2ModbusTcpServer.get().ReadInt("VD1100", 1, val -> {

});
}
} catch (InterruptedException e) {
NewToastUtil.getInstance().showToast("异常信息:" + e.getMessage());
}
}
}).start();
}

private int GetAddress(String address) {
if (address == null) return -1;
if (address.length() > 0) {
address = address.trim();
if (address.toUpperCase().contains("M") && address.length() >= 4) {
String[] res = address.substring(1).split("[.]");
if (res != null && res.length == 2) {
try {
int firstAdd = Integer.parseInt(res[0]);
int endAdd = Integer.parseInt(res[1]);
if (endAdd >= 0 && endAdd <= 7) {
return (firstAdd * 8) + 320 + endAdd;
}
} catch (NumberFormatException e) {
return -1;
}
}
} else if (address.toUpperCase().contains("I") && address.length() >= 4) {
String[] res = address.substring(1).split("[.]");
if (res != null && res.length == 2) {
try {
int firstAdd = Integer.parseInt(res[0]);
int endAdd = Integer.parseInt(res[1]);
if (endAdd >= 0 && endAdd <= 7) {
return (firstAdd * 8) + endAdd;
}
} catch (NumberFormatException e) {
return -1;
}
}
} else if ((address.toUpperCase().contains("VW") || address.toUpperCase().contains("VD")) && address.length() >= 3) {
String res = address.substring(2);
if (res != null) {
try {
int tempAdd = Integer.parseInt(res);
return (tempAdd / 2) + 100;
} catch (NumberFormatException e) {
return -1;
}
}
}else if (address.toUpperCase().contains("GI") &&address.length() >=3){
String res = address.substring(2);
if (res != null) {
try {
return Integer.parseInt(res);
} catch (NumberFormatException e) {
return -1;
}
}
} else {
try {
return Integer.parseInt(address);
} catch (NumberFormatException e) {
return -1;
}
}
}
return -1;
}

private Float BytesToFloat(byte[] buffers, DataFormat df) {
if (buffers.length == 4) {
byte[] bytes = new byte[4];
if (df == DataFormat.ABCD) {
bytes[0] = buffers[3];
bytes[1] = buffers[2];
bytes[2] = buffers[1];
bytes[3] = buffers[0];
} else if (df == DataFormat.CDAB) {
bytes[0] = buffers[1];
bytes[1] = buffers[0];
bytes[2] = buffers[3];
bytes[3] = buffers[2];
} else if (df == DataFormat.BADC) {
bytes[0] = buffers[2];
bytes[1] = buffers[3];
bytes[2] = buffers[0];
bytes[3] = buffers[1];
} else if (df == DataFormat.DCBA) {
bytes[0] = buffers[0];
bytes[1] = buffers[1];
bytes[2] = buffers[2];
bytes[3] = buffers[3];
}
return ByteBuffer.wrap(bytes).getFloat();
}
return 0.0f;
}

private Integer BytesToInt(byte[] buffers, DataFormat df) {
if (buffers.length == 4) {
byte[] bytes = new byte[4];
if (df == DataFormat.ABCD) {
bytes[0] = buffers[3];
bytes[1] = buffers[2];
bytes[2] = buffers[1];
bytes[3] = buffers[0];
} else if (df == DataFormat.CDAB) {
bytes[0] = buffers[1];
bytes[1] = buffers[0];
bytes[2] = buffers[3];
bytes[3] = buffers[2];
} else if (df == DataFormat.BADC) {
bytes[0] = buffers[2];
bytes[1] = buffers[3];
bytes[2] = buffers[0];
bytes[3] = buffers[1];
} else if (df == DataFormat.DCBA) {
bytes[0] = buffers[0];
bytes[1] = buffers[1];
bytes[2] = buffers[2];
bytes[3] = buffers[3];
}
return ByteBuffer.wrap(bytes).getInt();
}
return 0;
}

private short[] IntToShorts(int value) {
short[] res = new short[2];
int temp = value;
byte[] b = new byte[4];
for (int i = 0; i < b.length; i++) {
b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位
temp = temp >> 8; // 向右移8位
}
for (int i = 0; i < res.length; i++) {
short s0 = (short) (b[i * 2] & 0xff);// 最低位
short s1 = (short) (b[i * 2 + 1] & 0xff);
s1 <<= 8;
res[i] = (short) (s0 | s1);
}
return res;
}

/***
*读取实时状态
* @param Address the address
* @param length 读取的长度 3
* @param callback 读取成功的回调
*/
public void ReadStatus(String Address, int length, IReadCallBack<byte[]> callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
ReadHoldingRegistersResponse res = WokModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length);
byte[] data = res.getData();
byte[] tempData = new byte[6];
tempData[0] = data[1];
tempData[1] = data[0];
if (callback != null) callback.onSuccess(tempData);
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
}
}

public void ReadShort(String Address, int length, IReadCallBack<short[]> callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
ReadHoldingRegistersResponse res = WokModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length);
short[] data = res.getShortData();
if (data.length == length) {
if (callback != null) callback.onSuccess(data);
}
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
}
}

public void ReadBool(String Address, int length, IReadCallBack<boolean[]> callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
ReadCoilsResponse res = WokModbusTcpHelper.get().syncReadCoil(1, add, length);
boolean[] data = res.getBooleanData();
boolean[] result = Arrays.copyOfRange(data, 0, length);
if (result.length == length) {
if (callback != null) callback.onSuccess(result);
}
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
}
}

public void ReadFloat(String Address, int length, IReadCallBack<float[]> callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
ReadHoldingRegistersResponse res = WokModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length*2);
byte[] data = res.getData();
float[] tempValues = new float[length];
for (int i = 0; i < length; i++) {
byte[] tempData = new byte[4];
for (int m = 0; m < 4; m++) {
tempData[m] = data[i * 4 + m];
}
tempValues[i] = BytesToFloat(tempData, DataFormat.BADC);
}
if (tempValues.length == length) {
if (callback != null) callback.onSuccess(tempValues);
}
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
}
}

public void ReadInt(String Address, int length, IReadCallBack<int[]> callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
ReadHoldingRegistersResponse res = WokModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length * 2);
byte[] data = res.getData();
int[] tempValues = new int[length];
if(data.length>=4)
{
for (int i = 0; i < length; i++) {
byte[] tempData = new byte[4];
for (int m = 0; m < 4; m++) {
tempData[m] = data[i * 4 + m];
}
// Integer a1 = tempValues[i] = BytesToInt(tempData, DataFormat.ABCD);
// Integer a2 = tempValues[i] = BytesToInt(tempData, DataFormat.BADC);
// Integer a3 = tempValues[i] = BytesToInt(tempData, DataFormat.CDAB);
// Integer a4 = tempValues[i] = BytesToInt(tempData, DataFormat.DCBA);
tempValues[i] = BytesToInt(tempData, DataFormat.BADC);
}
}else
{
MessageLog.ShowError("ReadInt onFailure,Address=" );

}
if (callback != null) callback.onSuccess(tempValues);
plcIsConnect = true;
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
ReConnect(e.toString());
MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
}
}

public void WriteShort(String Address, short Value, IWriteCallBack callback) {
int add = GetAddress(Address);
if (add < 0) return;
short[] send = new short[1];
send[0] = Value;
try {
WokModbusTcpHelper.get().syncWriteRegisters(1, add, send);
if (callback != null)
callback.onSuccess();
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
if (callback != null) callback.onFailure(e.toString());
}
}

public void WriteBool(String Address, boolean Value, IWriteCallBack callback) {
int add = GetAddress(Address);
if (add < 0) return;
try {
WokModbusTcpHelper.get().syncWriteCoil(1, add, Value);
if (callback != null)
callback.onSuccess();
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
if (callback != null) callback.onFailure(e.toString());
}
}

public void WriteFloat(String Address, float Value, IWriteCallBack callback) {
int add = GetAddress(Address);
if (add < 0) return;
int intBits = Float.floatToRawIntBits(Value);

short[] send = IntToShorts(intBits);
// short[] send = new short[]{(short) ((intBits >> 16) & 0xffff), (short) (intBits & 0xffff)};
try {
WokModbusTcpHelper.get().syncWriteRegisters(1, add, send);

if (callback != null) callback.onSuccess();
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
if (callback != null) callback.onFailure(e.toString());
}
}

public void WriteInt(String Address, int Value, IWriteCallBack callback) {
int add = GetAddress(Address);
if (add < 0) return;
short[] send = IntToShorts(Value);
try {
WokModbusTcpHelper.get().syncWriteRegisters(1, add, send);
if (callback != null) callback.onSuccess();
} catch (InterruptedException | ExecutionException | ModbusTransportException |
ModbusInitException | ModbusRespException e) {
MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
if (callback != null) callback.onFailure(e.toString());
}
}
}

+ 47
- 0
app/src/main/java/com/bonait/bnframework/modbus/WokModbusTcpServer.java View File

@@ -27,12 +27,17 @@ import java.io.LineNumberReader;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.concurrent.ExecutionException;


public class WokModbusTcpServer {
private static volatile WokModbusTcpServer instance = null;
public boolean plcIsConnect = false;
/**
* 监听变量值
*/
public static HashMap<String, Object> listeningValue = new HashMap<String, Object>();
public static WokModbusTcpServer get() {
WokModbusTcpServer manager = instance;
if (manager == null) {
@@ -80,6 +85,16 @@ public class WokModbusTcpServer {
return true;
}

/**
* 获取监听变量
*/
public static Object getListingValue(String name) {
if (!listeningValue.containsKey(name)) {
return null;
}
return listeningValue.get(name);
}

/**
* 连接PLC
*/
@@ -104,6 +119,7 @@ public class WokModbusTcpServer {
Log.e("炒锅设备PLC", "炒锅设备PLC: 连接成功");
ThreadManager.get().Stop("炒锅设备重连");
ModbusCenter.Listening();
init();
}

@Override
@@ -128,6 +144,37 @@ public class WokModbusTcpServer {
}});
}

public static void init(){
new Thread(new Runnable() {
@Override
public void run() {
try {
if(WokModbusTcpServer.get().plcIsConnect){
ModbusCenter.WritePlc(1,"初始化", true, null);
Thread.sleep(500);
ModbusCenter.WritePlc(1,"初始化", false, null);

ModbusCenter.WritePlc(1,"温控开关", false, null);//开关闭合
ModbusCenter.WritePlc(1,"暂停开关", false, null);//开关闭合

ModbusCenter.WritePlc(1,"校准时间", 50, null);//默认校准时间5秒
ModbusCenter.WritePlc(1,"料仓1校准开关", false, null);//默认校准时间5秒
ModbusCenter.WritePlc(1,"料仓2校准开关", false, null);//默认校准时间5秒
ModbusCenter.WritePlc(1,"料仓3校准开关", false, null);//默认校准时间5秒

WokModbusTcpServer.get().WriteBool("M52.1", (boolean) false, null);
//读取版本号
WokModbusTcpServer.get().ReadInt("VD1100", 1, val -> {

});
}
} catch (InterruptedException e) {
NewToastUtil.getInstance().showToast("异常信息:" + e.getMessage());
}
}
}).start();
}

private int GetAddress(String address) {
if (address == null) return -1;
if (address.length() > 0) {


+ 0
- 1
app/src/main/java/com/bonait/bnframework/newui/activity/CookingHActivity.java View File

@@ -16,7 +16,6 @@ import com.bonait.bnframework.common.db.mode.BPA_ORDER_DETAIL;
import com.bonait.bnframework.common.db.util.OrderDetailUtil;
import com.bonait.bnframework.common.utils.DisplayManager;
import com.bonait.bnframework.databinding.ActivityCookHBinding;
import com.bonait.bnframework.newui.fragment.cooking.Cooking2Fragment;
import com.bonait.bnframework.newui.fragment.cooking.CookingFragment;
import com.bumptech.glide.Glide;



+ 0
- 1
app/src/main/java/com/bonait/bnframework/newui/activity/MainHActivity.java View File

@@ -35,7 +35,6 @@ import com.bonait.bnframework.common.utils.NetworkUtils;
import com.bonait.bnframework.common.utils.PreferenceUtils;
import com.bonait.bnframework.databinding.ActivityMainHBinding;
import com.bonait.bnframework.modbus.ModbusCenter;
import com.bonait.bnframework.modbus.OvenModbusTcpServer;
import com.bonait.bnframework.modbus.RobotModbusTcpServer;
import com.bonait.bnframework.modbus.WokModbusTcpServer;
import com.bonait.bnframework.newui.adapter.base.GuidePageAdapter;


+ 0
- 1
app/src/main/java/com/bonait/bnframework/newui/dialog/check/RootTipDialog.java View File

@@ -29,7 +29,6 @@ import com.bonait.bnframework.common.utils.AdbCommandUtil;
import com.bonait.bnframework.common.utils.DisplayManager;
import com.bonait.bnframework.databinding.DialogRootTipBinding;
import com.bonait.bnframework.modbus.ModbusCenter;
import com.bonait.bnframework.modbus.OvenModbusTcpServer;
import com.bonait.bnframework.modbus.RobotModbusTcpServer;
import com.bonait.bnframework.modbus.WokModbusTcpServer;



+ 0
- 1
app/src/main/java/com/bonait/bnframework/newui/dialog/control/ChuCanCheckDialog.java View File

@@ -25,7 +25,6 @@ import com.bonait.bnframework.common.utils.AdbCommandUtil;
import com.bonait.bnframework.common.utils.DisplayManager;
import com.bonait.bnframework.databinding.DialogChucanCheckBinding;
import com.bonait.bnframework.modbus.ModbusCenter;
import com.bonait.bnframework.modbus.OvenModbusTcpServer;
import com.bonait.bnframework.newui.widget.NewToastUtil;

import butterknife.ButterKnife;


+ 0
- 506
app/src/main/java/com/bonait/bnframework/newui/dialog/control/OvenControlDialog.java View File

@@ -1,506 +0,0 @@
package com.bonait.bnframework.newui.dialog.control;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import com.apkfuns.logutils.LogUtils;
import com.bonait.bnframework.HBL.Thread.ThreadManager;
import com.bonait.bnframework.R;
import com.bonait.bnframework.business.ExecuteTheRecipe;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.helper.I.IWriteCallBack;
import com.bonait.bnframework.common.utils.AdbCommandUtil;
import com.bonait.bnframework.common.utils.AlertDialogUtils;
import com.bonait.bnframework.common.utils.DisplayManager;
import com.bonait.bnframework.common.utils.PreferenceUtils;
import com.bonait.bnframework.databinding.DialogOvenControlBinding;
import com.bonait.bnframework.databinding.DialogTipBinding;
import com.bonait.bnframework.modbus.ModbusCenter;
import com.bonait.bnframework.modbus.OvenModbusTcpServer;
import com.bonait.bnframework.modbus.RobotModbusTcpServer;
import com.bonait.bnframework.newui.widget.NewToastUtil;
import com.bonait.bnframework.newui.widget.WaitProcessUtil;

import butterknife.ButterKnife;

/**
* @author: liup
* @description: 烤箱控制
* @date: 2024/6/3 17:59.
*/
public class OvenControlDialog extends DialogFragment {
private String TAG = " OvenControlDialog =>";
private DialogOvenControlBinding viewBinding;

private Handler handler = new Handler(Looper.getMainLooper()){
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
if(msg.what==1){
// Object object = ModbusCenter.getListingValue("烤箱功率判断是否工作");
// if(object!=null && (boolean)object){
// viewBinding.tvGonglv.setText("烤箱功率:开启");
// }else {
// viewBinding.tvGonglv.setText("烤箱功率:停止");
// }
Object object2 = ModbusCenter.getListingValue("烤箱门关到位检测");
if(object2!=null && (boolean)object2){
viewBinding.tvOpen.setText("烤箱门:已关闭");
}else {
viewBinding.tvOpen.setText("烤箱门:未关闭");
}
viewBinding.tvKaoxiang.setText(ConfigName.getInstance().oven_has_food?"烤箱有盆":"烤箱空");
viewBinding.tvKaoxiang.setText(PreferenceUtils.getBoolean(ConfigName.ovenHasPen,false)?"烤箱有盆":"烤箱空");
// Object object3 = ModbusCenter.getListingValue("烤箱门中间位检测");
// if(object3!=null && (boolean)object3){
// viewBinding.tvOpen.setText("烤箱门:中间位");
// }
if(handler.hasMessages(1)){
handler.removeMessages(1);
}
handler.sendEmptyMessageDelayed(1,200);
}
}
};

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NORMAL, R.style.DialogScale);
handler.sendEmptyMessage(1);
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
viewBinding = DialogOvenControlBinding.inflate(inflater, container, false);
DisplayManager.scaleViewGroup(viewBinding.getRoot());
ButterKnife.bind(this, viewBinding.getRoot());
return viewBinding.getRoot();
}
private void fullScreen(Window window){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// 全屏显示,隐藏状态栏和导航栏,拉出状态栏和导航栏显示一会儿后消失。
// 启动游戏模式,设置状态栏和导航栏中的图标变小,变模糊或者弱化其效果
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
} else {
// 全屏显示,隐藏状态栏
window.getDecorView().setSystemUiVisibility(View.INVISIBLE);
}
}
}
@Override
public void onStart() {
super.onStart();
if (getDialog() != null) {
Window window = getDialog().getWindow();
assert window != null;
fullScreen(window);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
WindowManager.LayoutParams params = window.getAttributes();
params.gravity = Gravity.CENTER;
params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
window.setAttributes(params);
}
AdbCommandUtil.hideStatusBar(true);

initView();
}

private void initView(){
viewBinding.btnKaoxiangClear.setOnClickListener(v->{
ConfigName.getInstance().oven_has_food = false;
PreferenceUtils.setBoolean(ConfigName.ovenHasPen,false);
viewBinding.tvKaoxiang.setText("烤箱空");
});
viewBinding.btnOpenWithRobot.setOnClickListener(v->{
if(!OvenModbusTcpServer.get().checkConnect()){
return;
}
if(ConfigName.getInstance().isFastClick()){
NewToastUtil.getInstance().showToast("请勿快速点击");
return;
}
boolean isOpen = (boolean) ModbusCenter.ReadPlc("烤箱门开到位检测");
if(isOpen){
NewToastUtil.getInstance().showToast("检测到烤箱门已打开");
return;
}
AlertDialogUtils.showCancelAndConfirmDialog(getActivity(), R.layout.dialog_tip, (layoutView, xCom) -> {
DialogTipBinding binding = DialogTipBinding.bind(layoutView);
DisplayManager.scaleViewGroup(binding.getRoot());
binding.title.setText("确认指令");
binding.message.setText("确保烤箱和机器人周围无人,是否控制机器人辅助打开烤箱门?");
binding.close.setOnClickListener(view1->{
xCom.dismissX();
});
binding.submit.setOnClickListener(view1 -> {
xCom.dismissX();
WaitProcessUtil.getInstance().show(getContext(),"提示","烤箱门正在打开,请等待完成,不要进行其他操作!");
ThreadManager.get().execute(new Thread(new Runnable() {
@Override
public void run() {
try {
//<<开门流程
ExecuteTheRecipe.WritePLC("档位选择", 0, null);
ExecuteTheRecipe.WritePLC("档位选择触发", true, null);
// ExecuteTheRecipe.ThreadWhile2("当前档位_关");
Thread.sleep(100);
ConfigName.getInstance().oven_wendu = 0+"";
ExecuteTheRecipe.WritePLC("温度选择", 0, null);
Thread.sleep(10);
ExecuteTheRecipe.WritePLC("温度选择触发", true, null);
// ExecuteTheRecipe.ThreadWhile2("温度设置完成");
Thread.sleep(100);
NewToastUtil.getInstance().showToast("烤箱档位和温度已关闭");
boolean isOpen = (boolean)ExecuteTheRecipe.ReadPLC("烤箱门开到位检测");
boolean isClose = (boolean)ExecuteTheRecipe.ReadPLC("烤箱门关到位检测");
if(!isOpen && isClose){
if(RobotModbusTcpServer.get().plcIsConnect){
ExecuteTheRecipe.Wait_Robot2_No_Working();//等待机器人空闲
ModbusCenter.robotWritePlc(true,"机器人烤箱开门",true,null);
ExecuteTheRecipe.ThreadWhile2("机器人烤箱开门完成");
}
Thread.sleep(100);
ExecuteTheRecipe.WritePLC("烤箱门打开控制", true, null);
Thread.sleep(100);
}else if(!isOpen && !isClose){
ExecuteTheRecipe.WritePLC("烤箱门打开控制", true, null);
Thread.sleep(100);
}
ExecuteTheRecipe.ThreadWhileWithTime("烤箱门开到位检测",10);
WaitProcessUtil.getInstance().dismiss();
//>>
}catch (Exception e){
LogUtils.d("异常信息:"+e.getMessage());
}
}
}));
});
});
});
viewBinding.btnOpen.setOnClickListener(v->{
if(!OvenModbusTcpServer.get().checkConnect()){
return;
}
if(ConfigName.getInstance().isFastClick()){
NewToastUtil.getInstance().showToast("请勿快速点击");
return;
}
boolean isOpen = (boolean) ModbusCenter.ReadPlc("烤箱门开到位检测");
if(isOpen){
NewToastUtil.getInstance().showToast("检测到烤箱门已打开");
return;
}
AlertDialogUtils.showCancelAndConfirmDialog(getActivity(), R.layout.dialog_tip, (layoutView, xCom) -> {
DialogTipBinding binding = DialogTipBinding.bind(layoutView);
DisplayManager.scaleViewGroup(binding.getRoot());
binding.title.setText("确认指令");
binding.message.setText("请先打开把手,确保烤箱周围无人,是否直接打开烤箱门?");
binding.close.setOnClickListener(view1->{
xCom.dismissX();
});
binding.submit.setOnClickListener(view1 -> {
xCom.dismissX();
WaitProcessUtil.getInstance().show(getContext(),"提示","烤箱门正在打开,请等待完成,不要进行其他操作!");
ThreadManager.get().execute(new Thread(new Runnable() {
@Override
public void run() {
try {
//<<开门流程
ExecuteTheRecipe.WritePLC("档位选择", 0, null);
ExecuteTheRecipe.WritePLC("档位选择触发", true, null);
// ExecuteTheRecipe.ThreadWhile2("当前档位_关");
Thread.sleep(100);
ConfigName.getInstance().oven_wendu = 0+"";
ExecuteTheRecipe.WritePLC("温度选择", 0, null);
Thread.sleep(10);
ExecuteTheRecipe.WritePLC("温度选择触发", true, null);
// ExecuteTheRecipe.ThreadWhile2("温度设置完成");
NewToastUtil.getInstance().showToast("烤箱档位和温度已关闭");
boolean isOpen = (boolean)ExecuteTheRecipe.ReadPLC("烤箱门开到位检测");
if(!isOpen){
ExecuteTheRecipe.WritePLC("烤箱门打开控制", true, null);
}
ExecuteTheRecipe.ThreadWhileWithTime("烤箱门开到位检测",10);
WaitProcessUtil.getInstance().dismiss();
//>>
}catch (Exception e){
LogUtils.d("异常信息:"+e.getMessage());
}
}
}));
});
});
});
viewBinding.btnCloseRobot.setOnClickListener(v->{
if(!OvenModbusTcpServer.get().checkConnect()){
return;
}
if(ConfigName.getInstance().isFastClick()){
NewToastUtil.getInstance().showToast("请勿快速点击");
return;
}
boolean isClose = (boolean) ModbusCenter.ReadPlc("烤箱门关到位检测");
if(isClose){
NewToastUtil.getInstance().showToast("检测到烤箱门已关闭");
return;
}
AlertDialogUtils.showCancelAndConfirmDialog(getActivity(), R.layout.dialog_tip, (layoutView, xCom) -> {
DialogTipBinding binding = DialogTipBinding.bind(layoutView);
DisplayManager.scaleViewGroup(binding.getRoot());
binding.title.setText("确认指令");
binding.message.setText("是否关闭烤箱门");
binding.close.setOnClickListener(view1->{
xCom.dismissX();
});
binding.submit.setOnClickListener(view1 -> {
xCom.dismissX();
WaitProcessUtil.getInstance().show(getContext(),"提示","烤箱门正在关闭,请等待完成,不要进行其他操作!");
ThreadManager.get().execute(new Thread(new Runnable() {
@Override
public void run() {
try {
//<<关门流程
Thread.sleep(100);
ExecuteTheRecipe.WritePLC("烤箱门关闭控制", true, null);
ExecuteTheRecipe.ThreadWhileWithTime("烤箱门关到位检测",10);
boolean isClose2 = (boolean) ModbusCenter.ReadPlc("烤箱门关到位检测");
boolean checkClose = (boolean) ModbusCenter.ReadPlc("机器人允许关门");
if(!isClose2 && checkClose){
ExecuteTheRecipe.Wait_Robot2_No_Working();//等待机器人空闲
ModbusCenter.robotWritePlc(true,"机器人烤箱关门",true,null);
ExecuteTheRecipe.ThreadWhile2("机器人烤箱关门完成");
Thread.sleep(100);
ExecuteTheRecipe.ThreadWhileWithTime("烤箱门关到位检测",120);
}
isClose2 = (boolean) ModbusCenter.ReadPlc("烤箱门关到位检测");
if(!isClose2){
NewToastUtil.getInstance().showToastError("烤箱未关门");
}
WaitProcessUtil.getInstance().dismiss();
//>>
}catch (Exception e){
LogUtils.d("异常信息:"+e.getMessage());
}
}
}));
});
});
});
viewBinding.btnCloseShoudong.setOnClickListener(v->{
if(!OvenModbusTcpServer.get().checkConnect()){
return;
}
if(ConfigName.getInstance().isFastClick()){
NewToastUtil.getInstance().showToast("请勿快速点击");
return;
}
boolean isClose = (boolean) ModbusCenter.ReadPlc("烤箱门关到位检测");
if(isClose){
NewToastUtil.getInstance().showToast("检测到烤箱门已关闭");
return;
}
AlertDialogUtils.showCancelAndConfirmDialog(getActivity(), R.layout.dialog_tip, (layoutView, xCom) -> {
DialogTipBinding binding = DialogTipBinding.bind(layoutView);
DisplayManager.scaleViewGroup(binding.getRoot());
binding.title.setText("确认指令");
binding.message.setText("是否关闭烤箱门");
binding.close.setOnClickListener(view1->{
xCom.dismissX();
});
binding.submit.setOnClickListener(view1 -> {
xCom.dismissX();
WaitProcessUtil.getInstance().show(getContext(),"提示","烤箱门正在关闭,请等待完成,不要进行其他操作!");
ThreadManager.get().execute(new Thread(new Runnable() {
@Override
public void run() {
try {
//<<关门流程
Thread.sleep(100);
ExecuteTheRecipe.WritePLC("烤箱门关闭控制", true, null);
ExecuteTheRecipe.ThreadWhileWithTime("烤箱门关到位检测",20);
WaitProcessUtil.getInstance().dismiss();
//>>
}catch (Exception e){
LogUtils.d("异常信息:"+e.getMessage());
}
}
}));
});
});
});
viewBinding.btnDimiss.setOnClickListener(v->{
dismiss();
});
viewBinding.model0.setOnClickListener(v->{
setModel(0);
});
viewBinding.model1.setOnClickListener(v->{
setModel(1);
});
viewBinding.model2.setOnClickListener(v->{
setModel(2);
});
viewBinding.model3.setOnClickListener(v->{
setModel(3);
});
viewBinding.model4.setOnClickListener(v->{
setModel(4);
});
viewBinding.btnWenduOpen.setOnClickListener(v->{
setWendu();
});
try {
ThreadManager.get().execute(new Runnable() {
@Override
public void run() {
boolean model0 = (boolean) ModbusCenter.ReadPlc("当前档位_关");
boolean model1 = (boolean) ModbusCenter.ReadPlc("当前档位_蒸");
boolean model2 = (boolean) ModbusCenter.ReadPlc("当前档位_烤");
boolean model3 = (boolean) ModbusCenter.ReadPlc("当前档位_蒸烤");
boolean model4 = (boolean) ModbusCenter.ReadPlc("当前档位_其他");


handler.post(new Runnable() {
@Override
public void run() {
String tv1 = "烤箱档位:";
if(model0){
tv1 = tv1+"\n关闭";
}else if(model1){
tv1 = tv1+"\n蒸";
}else if(model2){
tv1 = tv1+"\n烤";
}else if(model3){
tv1 = tv1+"\n蒸烤";
}else if(model4){
tv1 = tv1+"\n其他";
}
viewBinding.tvModel.setText(tv1);
viewBinding.tvWendu.setText("当前温度:\n"+ConfigName.getInstance().oven_wendu+"°C");
}
});
}
});



}catch (Exception e){

}

}


private void setModel(int num){
if(!OvenModbusTcpServer.get().checkConnect()){
return;
}
if(ConfigName.getInstance().isFastClick()){
NewToastUtil.getInstance().showToast("请勿快速点击");
return;
}
boolean status = (boolean) ModbusCenter.ReadPlc("烤箱门关到位检测");
if(!status){
NewToastUtil.getInstance().showToast("请先关闭烤箱门");
return;
}
ModbusCenter.WritePlc("档位选择", num, new IWriteCallBack() {
@Override
public void onSuccess() {
NewToastUtil.getInstance().showToast("档位选择"+num+":成功");
ExecuteTheRecipe.WritePLC("档位选择触发", true, null);
handler.post(new Runnable() {
@Override
public void run() {
viewBinding.tvModel.setText("当前档位:\n"+num);
}
});
}

@Override
public void onFailure(String ErrorMsg) {
NewToastUtil.getInstance().showToast("档位选择"+num+":失败");
}
});
}

private void setWendu(){
if(!OvenModbusTcpServer.get().checkConnect()){
return;
}
if(ConfigName.getInstance().isFastClick()){
NewToastUtil.getInstance().showToast("请勿快速点击");
return;
}
boolean status = (boolean) ModbusCenter.ReadPlc("烤箱门关到位检测");
if(!status){
NewToastUtil.getInstance().showToast("请先关闭烤箱门");
return;
}
int num = Integer.parseInt(viewBinding.editWendu.getText().toString());
ModbusCenter.WritePlc("温度选择", num, new IWriteCallBack() {
@Override
public void onSuccess() {
ConfigName.getInstance().oven_wendu = num+"";
ExecuteTheRecipe.WritePLC("温度选择触发", true, null);
NewToastUtil.getInstance().showToast("温度选择"+num+":成功");
handler.post(new Runnable() {
@Override
public void run() {
viewBinding.tvWendu.setText("当前温度:\n"+num+"°C");
}
});
}

@Override
public void onFailure(String ErrorMsg) {
NewToastUtil.getInstance().showToast("温度选择"+num+":失败");
}
});
}

@Override
public void dismiss() {
super.dismiss();
LogUtils.d(TAG+" dismiss");
if(handler!=null){
handler.removeCallbacksAndMessages(null);
handler = null;
}
}

@Override
public void onDestroy() {
super.onDestroy();
if(handler!=null){
handler.removeCallbacksAndMessages(null);
handler = null;
}
}
}

+ 2
- 146
app/src/main/java/com/bonait/bnframework/newui/dialog/control/RobotControlDialog.java View File

@@ -353,7 +353,7 @@ public class RobotControlDialog extends DialogFragment {
}
LogUtils.d("去维护位 空闲中");
ModbusCenter.robotWritePlc(true,"机器人去维护位置",true,null);
ExecuteTheRecipe.ThreadWhile2("机器人到达维护位");
ExecuteTheRecipe.ThreadWhile("机器人到达维护位");
WaitProcessUtil.getInstance().dismiss();
}
}));
@@ -434,107 +434,8 @@ public class RobotControlDialog extends DialogFragment {
robotPutFood();
break;
//左侧
case R.id.left1:
boolean isOpen = (boolean) ModbusCenter.ReadPlc("烤箱门开到位检测");
if(PreferenceUtils.getBoolean("烤箱内有盆",false)){
NewToastUtil.getInstance().showToastError("烤箱内有盆!若确定没有,请在烤箱调试里,点击【烤箱重置】");
return;
}
if(isOpen){
tipDialog("控制机器人取K2放入烤箱", new MyClickListener() {
@Override
public void clickListener(View v, Object s) {
WaitProcessUtil.getInstance().show(getContext(),"提示","机器人正在取K1向烤箱投料,请等待完成,不要进行其他操作!");
ThreadManager.get().execute(new Thread(new Runnable() {
@Override
public void run() {
try {
// ExecuteTheRecipe.Wait_Robot_No_Working();//等待机器人空闲
Object object1 = ModbusCenter.robotReadPlc("主任务读取");
Object object2 = ModbusCenter.robotReadPlc("机器人在原点");
Object object3 = ModbusCenter.robotReadPlc("机器人准备就绪");
boolean robotNoWorking = false;
if (object1 != null && object2!=null && object3!=null) {
robotNoWorking = ((short) object1)==0 && (boolean) object2 &&(boolean) object3;
}
if(!robotNoWorking){
WaitProcessUtil.getInstance().dismiss();
NewToastUtil.getInstance().showToastError("机器人正在工作!");
return;
}
ModbusCenter.robotWritePlc(false,"烤箱允许放料",true,null);
ModbusCenter.robotWritePlc(true,"1#库取烤架放至烤箱",true,null);
ConfigName.getInstance().oven_has_food = true;
PreferenceUtils.setBoolean(ConfigName.ovenHasPen,true);
ExecuteTheRecipe.ThreadWhile2("烤盘架放料至烤箱完成");
WaitProcessUtil.getInstance().dismiss();
}catch (Exception e){
LogUtils.d("异常信息:"+e.getMessage());
}
}
}));
}

@Override
public void clickListenerNew(View v, int k, Object data) {
}
});
}else {
NewToastUtil.getInstance().showToast("请先打开烤箱门");
}

break;
case R.id.left2:
boolean isOpen2 = (boolean) ModbusCenter.ReadPlc("烤箱门开到位检测");
if(PreferenceUtils.getBoolean("烤箱内有盆",false)){
NewToastUtil.getInstance().showToastError("烤箱内有盆!若确定没有,请在烤箱调试里,点击【烤箱重置】");
return;
}
if(isOpen2){
tipDialog("控制机器人取K2放入烤箱", new MyClickListener() {
@Override
public void clickListener(View v, Object s) {
WaitProcessUtil.getInstance().show(getContext(),"提示","机器人正在取K2向烤箱投料,请等待完成,不要进行其他操作!");
ThreadManager.get().execute(new Thread(new Runnable() {
@Override
public void run() {
try {
// ExecuteTheRecipe.Wait_Robot_No_Working();//等待机器人空闲
Object object1 = ModbusCenter.robotReadPlc("主任务读取");
Object object2 = ModbusCenter.robotReadPlc("机器人在原点");
Object object3 = ModbusCenter.robotReadPlc("机器人准备就绪");
boolean robotNoWorking = false;
if (object1 != null && object2!=null && object3!=null) {
robotNoWorking = ((short) object1)==0 && (boolean) object2 &&(boolean) object3;
}
if(!robotNoWorking){
WaitProcessUtil.getInstance().dismiss();
NewToastUtil.getInstance().showToastError("机器人正在工作!");
return;
}
ModbusCenter.robotWritePlc(false,"烤箱允许放料",true,null);
ModbusCenter.robotWritePlc(true,"2#库取烤架放至烤箱",true,null);
ConfigName.getInstance().oven_has_food = true;
PreferenceUtils.setBoolean(ConfigName.ovenHasPen,true);
ExecuteTheRecipe.ThreadWhile2("烤盘架放料至烤箱完成");
WaitProcessUtil.getInstance().dismiss();
}catch (Exception e){
LogUtils.d("异常信息:"+e.getMessage());
}
}
}));
}

@Override
public void clickListenerNew(View v, int k, Object data) {
}
});
}else {
NewToastUtil.getInstance().showToast("请先打开烤箱门");
}
break;
case R.id.btn_wok_chucai:
data.put("烹饪(秒)","0");
data.put("延迟(秒)","0");
tipDialog("控制机器人给炒锅出菜", new MyClickListener() {
@Override
public void clickListener(View v, Object s) {
@@ -557,51 +458,6 @@ public class RobotControlDialog extends DialogFragment {
public void clickListenerNew(View v, int k, Object data) {
}
});
break;
case R.id.btn_oven_chucai:
data.put("等待时间","0");
boolean isOpen3 = (boolean) ModbusCenter.ReadPlc("烤箱门开到位检测");
if(isOpen3){
tipDialog("控制机器人给烤箱出菜", new MyClickListener() {
@Override
public void clickListener(View v, Object s) {
WaitProcessUtil.getInstance().show(getContext(),"提示","机器人正在给烤箱出菜,请等待完成,不要进行其他操作!");
ThreadManager.get().execute(new Thread(new Runnable() {
@Override
public void run() {
try {
ExecuteTheRecipe.ThreadWhileFalse("出餐工位检测有无");
// ExecuteTheRecipe.Wait_Robot_No_Working();//等待机器人空闲
Object object1 = ModbusCenter.robotReadPlc("主任务读取");
Object object2 = ModbusCenter.robotReadPlc("机器人在原点");
Object object3 = ModbusCenter.robotReadPlc("机器人准备就绪");
boolean robotNoWorking = false;
if (object1 != null && object2!=null && object3!=null) {
robotNoWorking = ((short) object1)==0 && (boolean) object2 &&(boolean) object3;
}
if(!robotNoWorking){
WaitProcessUtil.getInstance().dismiss();
NewToastUtil.getInstance().showToastError("机器人正在工作!");
return;
}
ModbusCenter.robotWritePlc(true,"机器人取烤箱烤盘出餐",true,null);
ConfigName.getInstance().oven_has_food = false;
ExecuteTheRecipe.ThreadWhile2("烤盘出餐完成");
WaitProcessUtil.getInstance().dismiss();
}catch (Exception e){
LogUtils.d("异常信息:"+e.getMessage());
}
}
}));
}
@Override
public void clickListenerNew(View v, int k, Object data) {
}
});
}else {
NewToastUtil.getInstance().showToastError("请先打开烤箱门");
}

break;
}
}


+ 4
- 0
app/src/main/java/com/bonait/bnframework/newui/dialog/control/WokControlDialog.java View File

@@ -56,6 +56,7 @@ import butterknife.OnClick;
public class WokControlDialog extends DialogFragment {
private String TAG = " WokControlDialog =>";
private DialogChaoguoControlBinding viewBinding;
private int deviceNum = 1;

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -129,6 +130,9 @@ public class WokControlDialog extends DialogFragment {
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
window.setAttributes(params);
}
if(getArguments()!=null){
deviceNum = getArguments().getInt("deviceNum");
}
AdbCommandUtil.hideStatusBar(true);
handler.sendEmptyMessage(1);
initView();


+ 0
- 362
app/src/main/java/com/bonait/bnframework/newui/fragment/cooking/Cooking2Fragment.java View File

@@ -1,362 +0,0 @@
package com.bonait.bnframework.newui.fragment.cooking;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.apkfuns.logutils.LogUtils;
import com.bonait.bnframework.R;
import com.bonait.bnframework.Service.ModbusHelper;
import com.bonait.bnframework.business.ExecuteTheRecipe;
import com.bonait.bnframework.common.base.BaseFragment;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.db.mode.BPA_GOODS;
import com.bonait.bnframework.common.db.mode.BPA_GOODS_SUBATTRIBUTE_GROUP;
import com.bonait.bnframework.common.db.mode.BPA_ORDER_DETAIL;
import com.bonait.bnframework.common.db.util.GoodsDBUtil;
import com.bonait.bnframework.common.db.util.OrderDetailUtil;
import com.bonait.bnframework.common.db.util.SubAttributeGroupDBUtil;
import com.bonait.bnframework.common.utils.AlertDialogUtils;
import com.bonait.bnframework.common.utils.DisplayManager;
import com.bonait.bnframework.databinding.FragmentCooking2Binding;
import com.bonait.bnframework.event.MakingStepEvent;
import com.bonait.bnframework.modbus.OvenModbusTcpServer;
import com.bonait.bnframework.modbus.RobotModbusTcpServer;
import com.bonait.bnframework.newui.widget.NewToastUtil;
import com.bonait.bnframework.oldui.activity.ErrorInfoActivity;
import com.bonait.bnframework.newui.dialog.WaiteProgressDialog;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
* @author: liup
* @description: 烹饪过程-烤箱
* @date: 2024/6/26 10:11.
*/
public class Cooking2Fragment extends BaseFragment {
private String TAG = "CookingFragment=>";
private FragmentCooking2Binding viewBinding;
/**
* 商品id
*/
private String goodId = "";
/**
* 子属性组合id 属性组合名称
*/
private String subAttributeGroupId = "";
private String subAttributeGroupName = "";
private BPA_GOODS_SUBATTRIBUTE_GROUP goodsSubattributeGroup;

private boolean isMaking = true;

/**
* 进度
*/
private int process=0;
private final int MSG_Fresh_Step = 1000;
private WaiteProgressDialog progressDialog;
/**
* 0炒锅 1烤箱
*/
private int type;
private BPA_ORDER_DETAIL orderDetail;
private Handler handler = new Handler(Looper.getMainLooper()){
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
switch (msg.what){
case MSG_Fresh_Step:

break;
}
}
};
public static Cooking2Fragment newInstance(int type){
Cooking2Fragment fragment = new Cooking2Fragment();
fragment.type = type;
return fragment;
};

@Override
protected View onCreateView() {
LogUtils.d(TAG+"onCreateView");
View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_cooking2, null);
viewBinding = FragmentCooking2Binding.bind(root);
DisplayManager.scaleViewGroup(viewBinding.getRoot());
return root;
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
EventBus.getDefault().register(this);
ConfigName.getInstance().lastTime = 0;
initData();
initView();
LogUtils.d(TAG+" onViewCreated");
}

private void initData(){
orderDetail = OrderDetailUtil.getByMaking(type);
process = 0;
if(orderDetail!=null){
process = Math.max(orderDetail.process-1,0);
viewBinding.ll1.setVisibility(View.VISIBLE);
subAttributeGroupId = orderDetail.groupId;
subAttributeGroupName = orderDetail.groupName==null?"":orderDetail.groupName;
goodId = orderDetail.goodsId;
goodsSubattributeGroup = SubAttributeGroupDBUtil.getById(subAttributeGroupId);
}else {
viewBinding.ll1.setVisibility(View.GONE);
}
}

private BPA_GOODS goods;
private void initView(){
goods = GoodsDBUtil.getById(goodId);
LogUtils.d(TAG+"initView goodId= "+goodId +" goods="+goods);
if(goods!=null){
String name = (subAttributeGroupName.isEmpty()||subAttributeGroupName.equals(goods.name))?goods.name:(goods.name+"\n"+subAttributeGroupName);
viewBinding.goodname.setText(name);
}
if(orderDetail==null || goods==null){
return;
}
if(orderDetail.status == 1){
viewBinding.startGoodmake.setImageResource(R.mipmap.zhizuo_js);
isMaking = true;
}else {
viewBinding.startGoodmake.setImageResource(R.mipmap.zhizuo_ks);
isMaking = false;
}

viewBinding.startGoodmake.setOnClickListener(v->{
if(!isMaking){
if (isFastClick()) {
NewToastUtil.getInstance().showToastBottom("点击太快了,请重试");
return;
}
isMaking = true;
String name = (subAttributeGroupName.isEmpty()||subAttributeGroupName.equals(goods.name))?goods.name:(goods.name+"\n"+subAttributeGroupName);
viewBinding.goodname.setText(name);

onRecordStart();
}else {
if(ConfigName.getInstance().isFast2Click()){
NewToastUtil.getInstance().showToastBottom("请勿快速点击!");
return;
}
if(ExecuteTheRecipe.MakeStatus2){
if(progressDialog == null){
progressDialog = new WaiteProgressDialog(getActivity());
}else {
progressDialog.dismiss();
}
progressDialog.setTitleAndMessage("烹饪中","正在停止制作,请耐心稍等...");
progressDialog.setCancelable(false);
progressDialog.show();
}
lastTime = System.currentTimeMillis();
isMaking = false;
ExecuteTheRecipe.IsForcedEnd2 = true;
ExecuteTheRecipe.IsPause2 = false;
ExecuteTheRecipe.MakeStatus2 = false;
ExecuteTheRecipe.IsStart2 = false;
onRecordStop();
setReset();
}
});
setProcess();
}

private long lastTime;

private boolean isFastClick(){
long curTime = System.currentTimeMillis();
if(curTime - lastTime < 2500){
return true;
}
lastTime = curTime;
return false;
}

/**
* 复位
*/
private void setReset() {
if(progressDialog!=null){
progressDialog.dismiss();
}
}

/**
* 启动
*/
private void onRecordStart() {
if (goodsSubattributeGroup != null&& !ExecuteTheRecipe.MakeStatus2 && OvenModbusTcpServer.get().plcIsConnect&& RobotModbusTcpServer.get().plcIsConnect) {
ExecuteTheRecipe.IsForcedEnd2 = false;
ExecuteTheRecipe.IsPause2 = false;

ExecuteTheRecipe.MakeStatus2 = true;
ExecuteTheRecipe.IsStart2 = true;
NewToastUtil.getInstance().showToast("开始制作");
viewBinding.startGoodmake.setImageResource(R.mipmap.zhizuo_js);
setReset();
process = 0;
setProcess();
ExecuteTheRecipe.MakeStatus2 = true;
orderDetail.status = 1;
OrderDetailUtil.update(orderDetail);
startMakingThread(orderDetail);
}
}

/**
* 制作线程
*/
private void startMakingThread(BPA_ORDER_DETAIL orderDetail){
ExecuteTheRecipe.startMakingThread(orderDetail);
}


/**
* 停止
*/
public void onRecordStop() {
EventBus.getDefault().post(new MakingStepEvent(1,-2));
viewBinding.startGoodmake.setImageResource(R.mipmap.zhizuo_ks);
ExecuteTheRecipe.reset2();
if (goodsSubattributeGroup != null) {
NewToastUtil.getInstance().showToast("停止制作");
process = 0;
orderDetail.status = 0;
orderDetail.process = 0;
OrderDetailUtil.update(orderDetail);
setProcess();
}
}

/**
* 设置进度条
*
* @param
*/
@SuppressLint("SetTextI18n")
private void setProcess() {
LogUtils.d(this+"setProcess process="+process);
if(viewBinding.goodname.getText().toString().contains("制作完成")){
viewBinding.progress.SetValue((100));
viewBinding.timeDesc.setText("共"+ExecuteTheRecipe.cookingTime/60+"分"+ExecuteTheRecipe.cookingTime%60+"秒,已烹饪"+ExecuteTheRecipe.cookingTime+"分,");
}else {
if(ExecuteTheRecipe.cookingTime!=0){
LogUtils.d("setProcess 烤箱烹饪倒计时 cookingTime="+ExecuteTheRecipe.cookingTime+"; cookedTime="+ExecuteTheRecipe.cookedTime);
viewBinding.timeDesc.setText("共"+ExecuteTheRecipe.cookingTime/60+"分"+ExecuteTheRecipe.cookingTime%60+"秒,已烹饪"+ExecuteTheRecipe.cookedTime/60+"分"+ExecuteTheRecipe.cookedTime%60+"秒");
viewBinding.progress.SetValue(Math.min(process*100/(ExecuteTheRecipe.cookingTime),100));
}else {
viewBinding.progress.SetValue((0));
}
}
// if(handler!=null){
// handler.sendEmptyMessage(MSG_Fresh_Step);
// }
}

/**
* 故障提示
*/
private void onErrorDialog(){
String tip = ModbusHelper.get().isBtnStop()?"设备已急停,请关闭急停按钮再调试!":"设备有报警,请前往设备故障页检查!";
AlertDialogUtils.showTipDialog((AppCompatActivity) getActivity(), "报警", tip, new AlertDialogUtils.DialogClickListener() {
@Override
public void onConfirm() {
if(!ModbusHelper.get().isBtnStop()){
Intent intent = new Intent(getActivity(), ErrorInfoActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}

@Override
public void onCancel() {

}
});
}

@Override
public void onDestroy() {
super.onDestroy();
LogUtils.d(TAG+"onDestroy");
EventBus.getDefault().unregister(this);
if(handler!=null){
handler.removeCallbacksAndMessages(null);
handler = null;
}
if(progressDialog !=null){
progressDialog.dismiss();
}
progressDialog = null;
}

@Override
protected boolean canDragBack() {
return false;
}

//接收工序执行步骤
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMakingStepEvent(MakingStepEvent event){
if(event.type == type){
LogUtils.d(TAG+" onMakingStepEvent process="+event.process);
if(event.process==-1){
String content = "制作异常!!!\n"+viewBinding.goodname.getText().toString().replace("\n","-");
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(content);
spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#EA0909")),0,7, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
viewBinding.goodname.setText(spannableStringBuilder);
isMaking = false;
process= 0;
setProcess();
viewBinding.startGoodmake.setImageResource(R.mipmap.zhizuo_ks);
}else if(event.process==-2){
String content = "强制停止!!!\n"+viewBinding.goodname.getText().toString().replace("\n","-");
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(content);
spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#EA0909")),0,7, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);

viewBinding.goodname.setText(spannableStringBuilder);
viewBinding.startGoodmake.setImageResource(R.mipmap.zhizuo_ks);
isMaking = false;
process = 0;
setProcess();
}else if(event.process==-3){
String content = "制作完成!!!\n"+viewBinding.goodname.getText().toString().replace("\n","-");
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(content);
spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#567722")),0,7, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);

viewBinding.goodname.setText(spannableStringBuilder);

viewBinding.startGoodmake.setImageResource(R.mipmap.zhizuo_ks);
isMaking = false;
process = 100;
setProcess();
}else {
process = event.process;
setProcess();
}
}
}
}

+ 17
- 75
app/src/main/java/com/bonait/bnframework/newui/fragment/main/HomeDevicesFragment.java View File

@@ -14,6 +14,7 @@ import androidx.annotation.Nullable;

import com.apkfuns.logutils.LogUtils;
import com.bonait.bnframework.R;
import com.bonait.bnframework.Service.ModbusTcpServer;
import com.bonait.bnframework.business.ExecuteTheRecipe;
import com.bonait.bnframework.common.base.BaseFragment;
import com.bonait.bnframework.common.constant.ConfigName;
@@ -21,13 +22,12 @@ import com.bonait.bnframework.common.helper.I.IWriteCallBack;
import com.bonait.bnframework.common.utils.DisplayManager;
import com.bonait.bnframework.databinding.FragmentHomeDeviceDebugBinding;
import com.bonait.bnframework.modbus.ModbusCenter;
import com.bonait.bnframework.modbus.OvenModbusTcpServer;
import com.bonait.bnframework.modbus.RackModbusTcpServer;
import com.bonait.bnframework.modbus.RobotModbusTcpServer;
import com.bonait.bnframework.modbus.WokModbusTcpServer;
import com.bonait.bnframework.newui.dialog.control.ChuCanCheckDialog;
import com.bonait.bnframework.newui.dialog.check.FoodCheckDialog;
import com.bonait.bnframework.newui.dialog.control.RobotControlDialog;
import com.bonait.bnframework.newui.dialog.control.OvenControlDialog;
import com.bonait.bnframework.newui.dialog.control.WokControlDialog;
import com.bonait.bnframework.newui.widget.NewToastUtil;
import com.orhanobut.logger.Logger;
@@ -100,68 +100,7 @@ public class HomeDevicesFragment extends BaseFragment {
}

private void initView(){

viewBinding.btnLineOpen.setOnClickListener(v->{
if(ConfigName.getInstance().isFastClick()){
NewToastUtil.getInstance().showToast("点击过快!");
return;
}
if(!OvenModbusTcpServer.get().plcIsConnect&&!ConfigName.TEST){
NewToastUtil.getInstance().showToastError("烤箱/货架设备未连接!");
return;
}
Object object1 = ModbusCenter.getListingValue("输送线反馈");
if(object1 instanceof Boolean){
if((Boolean) object1){
NewToastUtil.getInstance().showToast("输送线已启动");
}else {
ModbusCenter.WritePlc("输送线启动", true, new IWriteCallBack() {
@Override
public void onSuccess() {
NewToastUtil.getInstance().showToast("输送线已启动!");
}

@Override
public void onFailure(String ErrorMsg) {
NewToastUtil.getInstance().showToast("输送线启动失败!"+ErrorMsg);
}
});
}
}else {
NewToastUtil.getInstance().showToast("输送线检测异常");
}
});
viewBinding.btnLineClose.setOnClickListener(v->{
if(ConfigName.getInstance().isFastClick()){
NewToastUtil.getInstance().showToast("点击过快!");
return;
}
if(!OvenModbusTcpServer.get().plcIsConnect&&!ConfigName.TEST){
NewToastUtil.getInstance().showToastError("烤箱/货架设备未连接!");
return;
}
Object object1 = ModbusCenter.getListingValue("输送线反馈");
if(object1 instanceof Boolean){
if(!(Boolean) object1){
NewToastUtil.getInstance().showToast("输送线已停止");
}else {
ModbusCenter.WritePlc("输送线停止", true, new IWriteCallBack() {
@Override
public void onSuccess() {
NewToastUtil.getInstance().showToast("输送线已停止!");
}

@Override
public void onFailure(String ErrorMsg) {
NewToastUtil.getInstance().showToast("输送线停止失败!"+ErrorMsg);
}
});
}
}else {
NewToastUtil.getInstance().showToast("输送线检测异常");
}
});
viewBinding.btnFoods.setOnClickListener(v->{
viewBinding.btnRobot.setOnClickListener(v->{
if(ConfigName.getInstance().isFastClick()){
return;
}
@@ -184,27 +123,34 @@ public class HomeDevicesFragment extends BaseFragment {
}
WokControlDialog dialog = new WokControlDialog();
if(getActivity()!=null){
Bundle bundle = new Bundle();
bundle.putInt("deviceNum",1);
dialog.setArguments(bundle);
dialog.show(getActivity().getSupportFragmentManager(),"炒锅控制");
}
});
viewBinding.btnKaoxiang.setOnClickListener(v->{
viewBinding.btnChaoguo2.setOnClickListener(v->{
if(ConfigName.getInstance().isFastClick()){
return;
}
if(!OvenModbusTcpServer.get().plcIsConnect&&!ConfigName.TEST){
NewToastUtil.getInstance().showToastError("烤箱/货架设备未连接!");
if(!WokModbusTcpServer.get().plcIsConnect &&!ConfigName.TEST){
NewToastUtil.getInstance().showToastError("炒锅设备未连接!");
return;
}
OvenControlDialog dialog = new OvenControlDialog();
WokControlDialog dialog = new WokControlDialog();
if(getActivity()!=null){
dialog.show(getActivity().getSupportFragmentManager(),"烤箱控制");
Bundle bundle = new Bundle();
bundle.putInt("deviceNum",2);
dialog.setArguments(bundle);
dialog.show(getActivity().getSupportFragmentManager(),"炒锅控制");
}
});

viewBinding.btnDishCheck.setOnClickListener(v->{
if(ConfigName.getInstance().isFastClick()){
return;
}
if(!OvenModbusTcpServer.get().plcIsConnect&&!ConfigName.TEST){
if(!RackModbusTcpServer.get().plcIsConnect&&!ConfigName.TEST){
NewToastUtil.getInstance().showToastError("烤箱/货架设备未连接!");
return;
}
@@ -218,7 +164,7 @@ public class HomeDevicesFragment extends BaseFragment {
if(ConfigName.getInstance().isFastClick()){
return;
}
if(!OvenModbusTcpServer.get().plcIsConnect&&!ConfigName.TEST){
if(!RackModbusTcpServer.get().plcIsConnect&&!ConfigName.TEST){
NewToastUtil.getInstance().showToastError("烤箱/货架设备未连接!");
return;
}
@@ -278,10 +224,6 @@ public class HomeDevicesFragment extends BaseFragment {

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (ExecuteTheRecipe.MakeStatus||ExecuteTheRecipe.MakeStatus2) {
NewToastUtil.getInstance().showToast("正在制作订单,无法调试!");
return false;
}
if(ConfigName.getInstance().user.name.equals("一般用户")){
NewToastUtil.getInstance().showToast("一般用户不能进行操作!");
return false;


+ 1
- 48
app/src/main/java/com/bonait/bnframework/newui/fragment/main/HomeGoodsFragment.java View File

@@ -46,14 +46,13 @@ import java.util.List;
public class HomeGoodsFragment extends BaseFragment {
private FragmentHomeGoodsBinding viewBinding;
private HomeGoodsAdapter goodsAdapter;
private GoodsClassifyAdapter classifyAdapter,classifyAdapter2;
private GoodsClassifyAdapter classifyAdapter;
private ArrayList<BPA_GOODS> goodsList = new ArrayList<>();
private ArrayList<BPA_GOODS_CLASSIFY> classifyList = new ArrayList<>();
private AddOrderDialog addOrderDialog;
private OrderNameAdapter orderChaoAdapter;
private OrderNameAdapter orderKaoAdapter;
private List<BPA_ORDER_DETAIL> orderChaoDetails = new ArrayList<>();
private List<BPA_ORDER_DETAIL> orderKaoDetails = new ArrayList<>();

@Override
protected View onCreateView() {
@@ -88,7 +87,6 @@ public class HomeGoodsFragment extends BaseFragment {
goodsList = new ArrayList<>();
classifyList = new ArrayList<>();
orderChaoDetails = new ArrayList<>();
orderKaoDetails = new ArrayList<>();
goodsAdapter = new HomeGoodsAdapter(){
@Override
protected void onItemClick(View v, int position) {
@@ -128,48 +126,19 @@ public class HomeGoodsFragment extends BaseFragment {
goodsList.clear();
goodsList.addAll(GoodsDBUtil.getByClassifyId(mData.get(classifyAdapter.getCurrentPosition()).id));
goodsAdapter.notifyDataSetChanged();
int last = classifyAdapter2.getCurrentPosition();
classifyAdapter2.setCurrentPosition(-1);
if(last>=0){
classifyAdapter2.notifyItemChanged(last);
}
viewBinding.tvTitle.setText("炒菜-"+mData.get(position).name);
}
};
classifyAdapter.setCurrentPosition(0);
viewBinding.recyclerClassify.setAdapter(classifyAdapter);

classifyAdapter2 = new GoodsClassifyAdapter() {
@Override
protected void onItemClick(View v, int position) {
LogUtils.d("分类列表点击 position="+position+" name = "+mData.get(position).name);
RecordManager.getInstance().addLogRecord("角色操作日志","点击["+mData.get(position).name+"]分类");
goodsList.clear();
goodsList.addAll(GoodsDBUtil.getByClassifyId(mData.get(classifyAdapter2.getCurrentPosition()).id));
goodsAdapter.notifyDataSetChanged();
int last = classifyAdapter.getCurrentPosition();
classifyAdapter.setCurrentPosition(-1);
if(last>=0){
classifyAdapter.notifyItemChanged(last);
}
viewBinding.tvTitle.setText("烤菜-"+mData.get(position).name);
}
};
classifyAdapter2.setCurrentPosition(-1);
viewBinding.recyclerClassify2.setAdapter(classifyAdapter2);
}

private void initOrderView(){
orderChaoDetails.clear();
orderKaoDetails.clear();
orderChaoDetails.addAll(OrderDetailUtil.getAllByType(0));
orderKaoDetails.addAll(OrderDetailUtil.getAllByType(1));
orderChaoAdapter = new OrderNameAdapter();
orderKaoAdapter = new OrderNameAdapter();
orderChaoAdapter.setNewData(orderChaoDetails);
orderKaoAdapter.setNewData(orderKaoDetails);
viewBinding.recyclerChaoOrder.setAdapter(orderChaoAdapter);
viewBinding.recyclerKaoOrder.setAdapter(orderKaoAdapter);
}

/**
@@ -225,27 +194,14 @@ public class HomeGoodsFragment extends BaseFragment {
goodsList.addAll(GoodsDBUtil.getByClassifyId(classifies.get(last2).id));
if(goodsAdapter!=null){
goodsAdapter.setNewData(goodsList);
viewBinding.tvTitle.setText("炒菜-"+classifies.get(last2).name);
}
}
}
if(classifyAdapter2!=null){
classifyAdapter2.setCurrentPosition(-1);
List<BPA_GOODS_CLASSIFY> classifies = new ArrayList<>();
for(BPA_GOODS_CLASSIFY bean : classifyList){
if(bean.type == 1){
classifies.add(bean);
}
}
classifyAdapter2.setNewData(classifies);
}
}

private void updateOrderData(){
orderChaoDetails.clear();
orderKaoDetails.clear();
orderChaoDetails.addAll(OrderDetailUtil.getAllByType(0));
orderKaoDetails.addAll(OrderDetailUtil.getAllByType(1));
if(orderChaoDetails!=null){
orderChaoAdapter.notifyDataSetChanged();
orderKaoAdapter.notifyDataSetChanged();
@@ -278,16 +234,13 @@ public class HomeGoodsFragment extends BaseFragment {
goodsList.clear();
classifyList.clear();
orderChaoDetails.clear();
orderKaoDetails.clear();
goodsList = null;
classifyList = null;
orderChaoDetails = null;
orderKaoDetails = null;
}
if(goodsAdapter!=null){
goodsAdapter = null;
classifyAdapter = null;
classifyAdapter2 = null;
orderChaoAdapter = null;
orderKaoAdapter = null;



+ 0
- 1
app/src/main/java/com/bonait/bnframework/newui/fragment/main/HomeOrderFragment.java View File

@@ -29,7 +29,6 @@ import com.bonait.bnframework.databinding.FragmentHomeOrderBinding;
import com.bonait.bnframework.event.FreshOrderEvent;
import com.bonait.bnframework.event.MakingStepEvent;
import com.bonait.bnframework.modbus.ModbusCenter;
import com.bonait.bnframework.modbus.OvenModbusTcpServer;
import com.bonait.bnframework.modbus.RobotModbusTcpServer;
import com.bonait.bnframework.modbus.WokModbusTcpServer;
import com.bonait.bnframework.newui.activity.CookingHActivity;


+ 164
- 153
app/src/main/java/com/bonait/bnframework/newui/fragment/main/HomeWarnFragment.java View File

@@ -12,7 +12,6 @@ import androidx.annotation.Nullable;

import com.apkfuns.logutils.LogUtils;
import com.bonait.bnframework.R;
import com.bonait.bnframework.business.ExecuteTheRecipe;
import com.bonait.bnframework.common.base.BaseFragment;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.db.res.StatusMode;
@@ -21,7 +20,9 @@ import com.bonait.bnframework.common.utils.DisplayManager;
import com.bonait.bnframework.databinding.DialogTipBinding;
import com.bonait.bnframework.databinding.FragmentHomeWarnInfoBinding;
import com.bonait.bnframework.modbus.ModbusCenter;
import com.bonait.bnframework.modbus.OvenModbusTcpServer;
import com.bonait.bnframework.modbus.RackModbusTcpServer;
import com.bonait.bnframework.modbus.Wok2ModbusTcpServer;
import com.bonait.bnframework.modbus.WokModbusTcpServer;
import com.bonait.bnframework.newui.adapter.warn.WarnInfoAdapter;
import com.bonait.bnframework.newui.adapter.warn.WarnRecordAdapter;
import com.bonait.bnframework.newui.widget.NewToastUtil;
@@ -45,9 +46,8 @@ public class HomeWarnFragment extends BaseFragment {
private List<String> warnInfoList;


private List<String> ovenWarnList = new ArrayList<>();
/**
* 1炒锅 2烤箱 3机器人
* 1炒锅 2炒锅 3机器人
*/
private int type = 1;

@@ -83,21 +83,6 @@ public class HomeWarnFragment extends BaseFragment {
private void initView(){
warnInfoList = new ArrayList<>();
rightDataList = new ArrayList<>();
ovenWarnList.clear();
ovenWarnList.add("急停状态反馈");
ovenWarnList.add("电柜门关到位检测");
ovenWarnList.add("档位正限位提示");
ovenWarnList.add("档位负限位提示");
ovenWarnList.add("温度正限位提示");
ovenWarnList.add("温度负限位提示");
ovenWarnList.add("档位负限位提示");
ovenWarnList.add("档位回原点超时");
ovenWarnList.add("档位定位超时");
ovenWarnList.add("温度回原点超时");
ovenWarnList.add("温度定位超时");
ovenWarnList.add("补盆动作超时");
ovenWarnList.add("烤箱开门动作超时");
ovenWarnList.add("烤箱关门动作超时");
viewBinding.titleChaoguo.setSelected(true);

viewBinding.titleChaoguo.setOnClickListener(v->{
@@ -143,8 +128,8 @@ public class HomeWarnFragment extends BaseFragment {
});
binding.submit.setOnClickListener(view1 -> {
xCom.dismissX();
if(OvenModbusTcpServer.get().plcIsConnect){
ModbusCenter.WritePlc(value,false,null);
if(RackModbusTcpServer.get().plcIsConnect){
ModbusCenter.WritePlc(1,value,false,null);
}else {
NewToastUtil.getInstance().showToastError("烤箱/货架设备未连接,请稍后重试");
}
@@ -165,155 +150,181 @@ public class HomeWarnFragment extends BaseFragment {
private void freshData(){
try {
warnInfoList.clear();
String stirError = "无故障";
String fanError= "无故障";
try {
int num1 = (int) ModbusCenter.getListingValue("搅拌电机");
int num2 = (int) ModbusCenter.getListingValue("翻转电机");
stirError = ConfigName.getInstance().statusModes_电机.get(ModbusCenter.getListingValue("搅拌电机")==null?0:num1);
fanError= ConfigName.getInstance().statusModes_电机.get(ModbusCenter.getListingValue("翻转电机")==null?0:num2);
}catch (Exception e){
}
if(type==1){
warnInfoList.add("搅拌电机:"+stirError);
warnInfoList.add("翻转电机:"+fanError);
switch (type){
case 1:
updateWokInfo(1);
break;
case 2:
updateWokInfo(2);
break;
case 3:
updateRobotInfo();
break;
}
}catch (Exception e){
LogUtils.d("homewarnfragment Exception "+e.getMessage());
}finally {
warnInfoAdapter.notifyDataSetChanged();
warnRecordAdapter.notifyDataSetChanged();
}
}

if(stirError!=null && !stirError.contains("无故障")){
String info = "炒锅:"+stirError;
if(!rightDataList.contains(info)){
rightDataList.add(info);
private void updateRobotInfo(){
Object object2 = ModbusCenter.listeningValue.get("机器人急停");
Object object3 = ModbusCenter.listeningValue.get("机器人光栅");
Object object4 = ModbusCenter.listeningValue.get("输送电机过载");
Object object5 = ModbusCenter.listeningValue.get("输送电机通讯异常");
if(object2 instanceof Boolean){
if((Boolean) object2){
if(type==3){
warnInfoList.add("机器人急停:检测到急停");
}
}
if(fanError!=null && !fanError.contains("无故障")){
String info = "炒锅:"+fanError;
if(!rightDataList.contains(info)){
rightDataList.add(info);
if(!rightDataList.contains("机器人急停:检测到急停")){
rightDataList.add("机器人急停:检测到急停");
}
}else {
if(type==3){
warnInfoList.add("机器人急停:无故障");
}
}
for (StatusMode item:ConfigName.getInstance().statusModes)
{
if(item.Name.contains("炒锅加热异常") )
{
Object K= ExecuteTheRecipe.ReadPLC("异常加热故障信息");
item.Status= K == null ? false : (boolean) K;
if(item.Status){
String info = "炒锅:炒锅加热异常";
if(!rightDataList.contains(info)){
rightDataList.add(info);
}
}
if(type == 1){
warnInfoList.add("炒锅加热:"+(item.Status?"异常":"无故障"));
}
}else
{
item.Status= ModbusCenter.getConcurrentHash(item.sort);
if(item.Status&&!item.Name.equals("急停")){
String info = "炒锅:"+item.Name;
if(!rightDataList.contains(info)){
rightDataList.add(info);
}
}
if(type == 1){
warnInfoList.add(item.Name.replace("异常","")+":"+(item.Status?"异常":"无故障"));
}
}else {
if(type==3){
warnInfoList.add("机器人急停:检测异常");
}
if(!rightDataList.contains("机器人急停:检测异常")){
rightDataList.add("机器人急停:检测异常");
}
}
if(object3 instanceof Boolean){
if((Boolean) object3){
if(type==3){
warnInfoList.add("机器人光栅:光栅检测到物体");
}

if(!rightDataList.contains("机器人光栅:光栅检测到物体")){
rightDataList.add("机器人光栅:光栅检测到物体");
}
}else {
if(type==3){
warnInfoList.add("机器人光栅:无故障");
}

}
Object object2 = ModbusCenter.listeningValue.get("机器人急停");
// Object object3 = ModbusCenter.listeningValue.get("机器人光栅");
if(object2 instanceof Boolean){
if((Boolean) object2){
if(type==3){
warnInfoList.add("机器人急停:检测到急停");
}
if(!rightDataList.contains("机器人急停:检测到急停")){
rightDataList.add("机器人急停:检测到急停");
}
}else {
if(type==3){
warnInfoList.add("机器人急停:无故障");
}
}else {
if(type==3){
warnInfoList.add("机器人光栅:检测异常");
}
if(!rightDataList.contains("机器人光栅:检测异常")){
rightDataList.add("机器人光栅:检测异常");
}
}
if(object4 instanceof Boolean){
if((Boolean) object4){
if(type==3){
warnInfoList.add("输送电机过载:过载");
}
if(!rightDataList.contains("输送电机过载:过载")){
rightDataList.add("输送电机过载:过载");
}
}else {
if(type==3){
warnInfoList.add("机器人急停:检测异常");
warnInfoList.add("输送电机过载:无故障");
}
if(!rightDataList.contains("机器人急停:检测异常")){
rightDataList.add("机器人急停:检测异常");
}
}else {
if(type==3){
warnInfoList.add("输送电机过载:检测异常");
}
if(!rightDataList.contains("输送电机过载:检测异常")){
rightDataList.add("输送电机过载:检测异常");
}
}
if(object5 instanceof Boolean){
if((Boolean) object5){
if(type==3){
warnInfoList.add("输送电机通讯:异常");
}
if(!rightDataList.contains("输送电机通讯:异常")){
rightDataList.add("输送电机通讯:异常");
}
}else {
if(type==3){
warnInfoList.add("输送电机通讯:无故障");
}
}
// if(object3 instanceof Boolean){
// if((Boolean) object3){
// if(type==3){
// warnInfoList.add("机器人光栅:光栅检测到物体");
// }
//
// if(!rightDataList.contains("机器人光栅:光栅检测到物体")){
// rightDataList.add("机器人光栅:光栅检测到物体");
// }
// }else {
// if(type==3){
// warnInfoList.add("机器人光栅:无故障");
// }
//
// }
// }else {
// if(type==3){
// warnInfoList.add("机器人光栅:检测异常");
// }
// if(!rightDataList.contains("机器人光栅:检测异常")){
// rightDataList.add("机器人光栅:检测异常");
// }
// }
//烤箱
LogUtils.d(TAG+ " ovenWarnList="+ovenWarnList.toString() + " type="+type);
for(String res : ovenWarnList){
LogUtils.d(TAG+ " 1 ovenWarnList="+ovenWarnList.toString() + " type="+type);
if(ModbusCenter.listeningValue.get(res)==null){
if(type==2){
warnInfoList.add(res+"-检测异常");
}
if(!rightDataList.contains(res)){
rightDataList.add(res+"-检测异常");
}else {
if(type==3){
warnInfoList.add("输送电机通讯:检测异常");
}
if(!rightDataList.contains("输送电机通讯:检测异常")){
rightDataList.add("输送电机通讯:检测异常");
}
}
}

private void updateWokInfo(int deviceNum){
String stirError = "无故障";
String fanError= "无故障";
try {
if(deviceNum == 1){
int num1 = (int) WokModbusTcpServer.get().getListingValue("搅拌电机");
int num2 = (int) WokModbusTcpServer.get().getListingValue("翻转电机");
stirError = ConfigName.getInstance().statusModes_电机.get(num1);
fanError= ConfigName.getInstance().statusModes_电机.get(num2);
}else if(deviceNum == 2){
int num1 = (int) Wok2ModbusTcpServer.get().getListingValue("搅拌电机");
int num2 = (int) Wok2ModbusTcpServer.get().getListingValue("翻转电机");
stirError = ConfigName.getInstance().statusModes_电机.get(num1);
fanError= ConfigName.getInstance().statusModes_电机.get(num2);
}

}catch (Exception e){
}
if(type==1){
warnInfoList.add("搅拌电机:"+stirError);
warnInfoList.add("翻转电机:"+fanError);
}

if(stirError!=null && !stirError.contains("无故障")){
String info = "炒锅:"+stirError;
if(!rightDataList.contains(info)){
rightDataList.add(info);
}
}
if(fanError!=null && !fanError.contains("无故障")){
String info = "炒锅:"+fanError;
if(!rightDataList.contains(info)){
rightDataList.add(info);
}
}
for (StatusMode item:ConfigName.getInstance().statusModes)
{
if(item.Name.contains("炒锅加热异常") )
{
Object K= ModbusCenter.ReadPlc(deviceNum,"炒锅加热异常");
item.Status= K == null ? false : (boolean) K;
if(item.Status){
String info = "炒锅:炒锅加热异常";
if(!rightDataList.contains(info)){
rightDataList.add(info);
}
}else {
boolean result= (boolean)ModbusCenter.listeningValue.get(res) ;
if(res.contains("电柜门关到位检测")){
if(!result){
if(type==2){
warnInfoList.add(res+"-无故障-已关闭");
}
}else {
if(type==2){
warnInfoList.add(res+"-未关闭");
if(!rightDataList.contains(res+"-未关闭")){
rightDataList.add(res+"-未关闭");
}
}
}
}else{
if(result){
if(type==2){
warnInfoList.add(res);
}
if(!rightDataList.contains(res)){
rightDataList.add(res);
}
}else {
if(type==2){
warnInfoList.add(res+"-无故障");
}
}
}
if(type == 1){
warnInfoList.add("炒锅加热:"+(item.Status?"异常":"无故障"));
}
}else
{
item.Status= ModbusCenter.getConcurrentHash(deviceNum,item.sort);
if(item.Status&&!item.Name.equals("急停")){
String info = "炒锅:"+item.Name;
if(!rightDataList.contains(info)){
rightDataList.add(info);
}

}
if(type == 1){
warnInfoList.add(item.Name.replace("异常","")+":"+(item.Status?"异常":"无故障"));
}
}
}catch (Exception e){
LogUtils.d("homewarnfragment Exception "+e.getMessage());
}finally {
warnInfoAdapter.notifyDataSetChanged();
warnRecordAdapter.notifyDataSetChanged();
}
}



+ 43
- 0
app/src/main/java/com/bonait/bnframework/newui/widget/DeviceStatusView.java View File

@@ -0,0 +1,43 @@
package com.bonait.bnframework.newui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;

import com.bonait.bnframework.R;
import com.bonait.bnframework.common.db.mode.BPA_GOODS_PROCESS_DETAIL;
import com.bonait.bnframework.common.db.util.GoodsProcessDetailDBUtil;
import com.bonait.bnframework.common.utils.DisplayManager;
import com.bonait.bnframework.databinding.ViewDeviceStatusBinding;
import com.bonait.bnframework.databinding.ViewFoodPosSetBinding;

import java.util.ArrayList;
import java.util.List;

/**
* @author: liup
* @description: 炒锅状态
* @date: 2024/5/16 17:53.
*/
public class DeviceStatusView extends FrameLayout {

private ViewDeviceStatusBinding viewBinding;
private int deviceNum = 1;

public DeviceStatusView(Context context, AttributeSet attrs,int deviceNum) {
super(context, attrs);
View root= LayoutInflater.from(context).inflate(R.layout.view_device_status, this);
viewBinding = ViewDeviceStatusBinding.bind(root);
DisplayManager.scaleViewGroup(viewBinding.getRoot());
this.deviceNum = deviceNum;
init();
}

private void init(){

}
}

+ 2
- 2
app/src/main/java/com/bonait/bnframework/newui/widget/imagebuttom.java View File

@@ -87,7 +87,7 @@ public class imagebuttom extends LinearLayout {
@Override
public void onConfirm() {
//强制结束
ExecuteTheRecipe.SetForcedEnd();
// ExecuteTheRecipe.SetForcedEnd();
if(mListener!=null)
{
mListener.clickListener(root,false);
@@ -107,7 +107,7 @@ public class imagebuttom extends LinearLayout {
AlertDialogUtils.showTipDialog((AppCompatActivity) getContext(), title, message, new AlertDialogUtils.DialogClickListener() {
@Override
public void onConfirm() {
ExecuteTheRecipe.StopForcedEnd();
// ExecuteTheRecipe.StopForcedEnd();
Status=!Status;
SetStatus(Status);
if(mListener!=null)


+ 45
- 54
app/src/main/res/layout/new/layout/dialog_food_control.xml View File

@@ -137,58 +137,58 @@

<TextView
android:id="@+id/btn_oven_chucai"
android:layout_width="150dp"
android:layout_width="170dp"
android:textSize="32sp"
android:textColor="@color/white"
android:text="烤箱出菜"
android:text="2号炒锅\n模拟出菜"
android:gravity="center"
android:background="@drawable/bg_round15_yellow_btn"
app:layout_constraintTop_toTopOf="@id/btn_wok_chucai"
android:layout_marginTop="150dp"
app:layout_constraintEnd_toEndOf="@id/btn_wok_chucai"
android:layout_marginStart="50dp"
android:layout_height="100dp"/>
android:layout_height="120dp"/>

<TextView
android:id="@+id/btn_weihu"
android:layout_width="150dp"
android:layout_width="170dp"
android:textSize="32sp"
android:textColor="@color/white"
android:text="去维护位"
android:gravity="center"
app:layout_constraintTop_toTopOf="@id/btn_oven_chucai"
android:layout_marginTop="150dp"
android:layout_marginTop="270dp"
app:layout_constraintEnd_toEndOf="@id/btn_wok_chucai"
android:background="@drawable/bg_round15_yellow_btn"
android:layout_height="100dp"/>

<TextView
android:id="@+id/btn_weihu_finish"
android:layout_width="150dp"
android:layout_width="170dp"
android:textSize="32sp"
android:textColor="@color/white"
android:text="完成维护"
android:gravity="center"
app:layout_constraintTop_toTopOf="@id/btn_weihu"
android:layout_marginTop="150dp"
android:layout_marginTop="120dp"
app:layout_constraintEnd_toEndOf="@id/btn_wok_chucai"
android:background="@drawable/bg_round15_yellow_btn"
android:layout_height="100dp"/>
<TextView
android:id="@+id/btn_wok_chucai"
android:layout_width="150dp"
android:layout_width="170dp"
android:textSize="32sp"
android:textColor="@color/white"
android:text="炒锅出菜"
android:text="1号炒锅\n模拟出菜"
android:gravity="center"
android:background="@drawable/bg_round15_yellow_btn"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="250dp"
android:layout_marginTop="150dp"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="50dp"
android:layout_height="100dp"/>
android:layout_height="120dp"/>

<RelativeLayout
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="100dp"
app:layout_constraintTop_toTopOf="parent"
@@ -215,7 +215,7 @@
android:id="@+id/top2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="140dp"
android:layout_marginStart="40dp"
android:background="@drawable/bg_box_click"
android:gravity="center"
android:textSize="28sp"
@@ -228,7 +228,7 @@
android:id="@+id/top3"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="270dp"
android:layout_marginStart="40dp"
android:background="@drawable/bg_box_click"
android:gravity="center"
android:textSize="28sp"
@@ -241,7 +241,7 @@
android:id="@+id/top4"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="400dp"
android:layout_marginStart="40dp"
android:background="@drawable/bg_box_click"
android:gravity="center"
android:textSize="28sp"
@@ -250,14 +250,39 @@
android:text="辅料F4"
android:textColor="@color/black"
/>
<TextView
android:id="@+id/top5"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="40dp"
android:background="@drawable/bg_box_click"
android:gravity="center"
android:textSize="28sp"
android:maxLines="2"
android:ellipsize="end"
android:text="辅料F5"
android:textColor="@color/black"
/>
<TextView
android:id="@+id/top6"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="40dp"
android:background="@drawable/bg_box_click"
android:gravity="center"
android:textSize="28sp"
android:maxLines="2"
android:ellipsize="end"
android:text="辅料F6"
android:textColor="@color/black"
/>

</RelativeLayout>
</LinearLayout>

<TextView
android:id="@+id/right1"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_marginLeft="40dp"
android:background="@drawable/bg_box_click"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
@@ -274,7 +299,6 @@
android:id="@+id/right2"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_marginLeft="40dp"
android:background="@drawable/bg_box_click"
app:layout_constraintStart_toEndOf="@id/right1"
app:layout_constraintTop_toTopOf="@id/right1"
@@ -290,7 +314,7 @@
android:id="@+id/right3"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_marginLeft="40dp"
android:layout_marginStart="40dp"
android:background="@drawable/bg_box_click"
app:layout_constraintEnd_toEndOf="@id/right1"
app:layout_constraintTop_toBottomOf="@id/right1"
@@ -306,7 +330,6 @@
android:id="@+id/right4"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_marginLeft="40dp"
android:background="@drawable/bg_box_click"
app:layout_constraintStart_toEndOf="@id/right1"
app:layout_constraintTop_toBottomOf="@id/right1"
@@ -323,7 +346,7 @@
android:id="@+id/right5"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_marginLeft="40dp"
android:layout_marginStart="40dp"
android:background="@drawable/bg_box_click"
app:layout_constraintEnd_toEndOf="@id/right1"
app:layout_constraintTop_toBottomOf="@id/right3"
@@ -339,7 +362,6 @@
android:id="@+id/right6"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_marginLeft="40dp"
android:background="@drawable/bg_box_click"
app:layout_constraintStart_toEndOf="@id/right1"
app:layout_constraintTop_toBottomOf="@id/right3"
@@ -353,38 +375,7 @@
android:textColor="@color/black"
/>

<TextView
android:id="@+id/left1"
android:layout_width="150dp"
android:layout_height="250dp"
android:background="@drawable/bg_box_click"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="780dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="490dp"
android:gravity="center"
android:textSize="28sp"
android:maxLines="1"
android:ellipsize="end"
android:text="烤盘K1"
android:textColor="@color/black"
/>
<TextView
android:id="@+id/left2"
android:layout_width="150dp"
android:layout_height="250dp"
android:layout_marginLeft="40dp"
android:background="@drawable/bg_box_click"
app:layout_constraintStart_toEndOf="@id/left1"
android:layout_marginStart="25dp"
app:layout_constraintTop_toTopOf="@id/left1"
android:gravity="center"
android:textSize="28sp"
android:maxLines="1"
android:ellipsize="end"
android:text="烤盘K2"
android:textColor="@color/black"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

</FrameLayout>

+ 39
- 184
app/src/main/res/layout/new/layout/fragment_home_device_debug.xml View File

@@ -15,85 +15,48 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_devices_all2"
android:scaleX="1.1"
android:scaleY="1.1"
android:scaleX="1.5"
android:scaleY="1.5"
/>
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@mipmap/ic_click"
android:layout_marginTop="250dp"
android:layout_marginStart="220dp"
android:layout_marginTop="400dp"
android:layout_marginStart="200dp"
/>
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@mipmap/ic_click"
android:layout_marginTop="180dp"
android:layout_marginStart="630dp"
android:layout_marginTop="300dp"
android:layout_marginStart="550dp"
/>
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@mipmap/ic_click"
android:layout_marginTop="200dp"
android:layout_marginStart="1200dp"
android:layout_marginTop="300dp"
android:layout_marginStart="1150dp"
/>
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@mipmap/ic_click"
android:layout_marginTop="500dp"
android:layout_marginStart="1500dp"
android:layout_marginTop="250dp"
android:layout_marginStart="800dp"
/>
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@mipmap/ic_click"
android:layout_marginTop="557dp"
android:layout_marginTop="650dp"
android:layout_marginStart="950dp"
/>

<!-- <ImageView-->
<!-- android:layout_width="1000dp"-->
<!-- android:layout_height="303dp"-->
<!-- android:src="@mipmap/ic_chuanshu"-->
<!-- android:layout_gravity="bottom"-->
<!-- />-->
<!-- <TextView-->
<!-- android:id="@+id/device_status_wok"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_marginTop="10dp"-->
<!-- android:layout_marginStart="10dp"-->
<!-- android:textSize="36sp"-->
<!-- android:textColor="@color/black"-->
<!-- android:text="炒锅连接状态:未连接"-->
<!-- android:gravity="center"-->
<!-- android:layout_height="wrap_content"/>-->
<!-- <TextView-->
<!-- android:id="@+id/device_status_oven"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_marginTop="60dp"-->
<!-- android:layout_marginStart="10dp"-->
<!-- android:textSize="36sp"-->
<!-- android:textColor="@color/black"-->
<!-- android:text="烤箱连接状态:未连接"-->
<!-- android:gravity="center"-->
<!-- android:layout_height="wrap_content"/>-->
<!-- <TextView-->
<!-- android:id="@+id/device_status_robot"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_marginTop="110dp"-->
<!-- android:layout_marginStart="10dp"-->
<!-- android:textSize="36sp"-->
<!-- android:textColor="@color/black"-->
<!-- android:text="机器人连接状态:未连接"-->
<!-- android:gravity="center"-->
<!-- android:layout_height="wrap_content"/>-->

<TextView
android:layout_width="wrap_content"
android:layout_marginTop="100dp"
android:layout_marginTop="200dp"
android:layout_marginStart="1100dp"
android:textSize="36sp"
android:textColor="@color/white"
@@ -106,29 +69,29 @@
<TextView
android:id="@+id/btn_dish_check"
android:layout_width="320dp"
android:layout_marginTop="100dp"
android:layout_marginTop="200dp"
android:layout_marginStart="1050dp"
android:textSize="36sp"
android:textColor="@color/white"
android:layout_height="300dp"/>
android:layout_height="200dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_marginTop="400dp"
android:layout_marginStart="1400dp"
android:layout_marginTop="100dp"
android:layout_marginStart="770dp"
android:textSize="36sp"
android:textColor="@color/white"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:text="点击调试出餐架"
android:text="点击调试\n出餐架"
android:gravity="center"
android:background="#c0BEAA6A"
android:layout_height="80dp"/>
android:layout_height="120dp"/>
<TextView
android:id="@+id/btn_chucan_check"
android:layout_width="300dp"
android:layout_marginTop="400dp"
android:layout_marginStart="1400dp"
android:layout_width="200dp"
android:layout_marginTop="100dp"
android:layout_marginStart="750dp"
android:textSize="36sp"
android:textColor="@color/white"
android:layout_height="300dp"/>
@@ -136,12 +99,12 @@

<TextView
android:layout_width="wrap_content"
android:layout_height="70dp"
android:layout_marginTop="150dp"
android:layout_height="120dp"
android:layout_marginTop="250dp"
android:background="#c0BEAA6A"
android:gravity="center"
android:layout_marginStart="150dp"
android:text="点击调试炒锅"
android:text="点击调试\n1号炒锅"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textColor="@color/white"
@@ -149,37 +112,37 @@

<TextView
android:id="@+id/btn_chaoguo"
android:layout_width="400dp"
android:layout_marginTop="150dp"
android:layout_width="300dp"
android:layout_marginTop="250dp"
android:textSize="36sp"
android:textColor="@color/white"
android:gravity="center"
android:layout_marginStart="150dp"
android:layout_height="500dp"/>
android:layout_height="400dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_marginTop="80dp"
android:layout_marginStart="560dp"
android:layout_marginTop="150dp"
android:layout_marginStart="500dp"
android:textSize="36sp"
android:textColor="@color/white"
android:text="点击调试烤箱"
android:text="点击调试\n2号炒锅"
android:gravity="center"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:background="#c0BEAA6A"
android:layout_height="70dp"/>
android:layout_height="120dp"/>
<TextView
android:id="@+id/btn_kaoxiang"
android:id="@+id/btn_chaoguo2"
android:layout_width="250dp"
android:layout_marginTop="80dp"
android:layout_marginStart="560dp"
android:layout_marginTop="150dp"
android:layout_marginStart="500dp"
android:gravity="center"
android:layout_height="400dp"/>

<TextView
android:layout_width="200dp"
android:layout_marginTop="400dp"
android:layout_marginTop="500dp"
android:layout_marginStart="900dp"
android:textSize="36sp"
android:textColor="@color/white"
@@ -188,122 +151,14 @@
android:background="#c0BEAA6A"
android:layout_height="150dp"/>
<TextView
android:id="@+id/btn_foods"
android:id="@+id/btn_robot"
android:layout_width="200dp"
android:layout_marginTop="400dp"
android:layout_marginTop="500dp"
android:layout_marginStart="900dp"
android:textSize="36sp"
android:textColor="@color/white"
android:gravity="center"
android:layout_height="420dp"/>
<!-- <TextView-->
<!-- android:id="@+id/btn_weihu"-->
<!-- android:layout_width="150dp"-->
<!-- android:layout_marginTop="650dp"-->
<!-- android:layout_marginStart="670dp"-->
<!-- android:textSize="36sp"-->
<!-- android:textColor="@color/white"-->
<!-- android:text="去维护位"-->
<!-- android:gravity="center"-->
<!-- android:background="@drawable/bg_round15_yellow_btn"-->
<!-- android:layout_height="80dp"/>-->

<!-- <TextView-->
<!-- android:id="@+id/tv_chucai_box"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_marginTop="300dp"-->
<!-- android:layout_marginStart="770dp"-->
<!-- android:textSize="36sp"-->
<!-- android:textColor="@color/black"-->
<!-- android:text="出餐位检测:有盆"-->
<!-- android:gravity="center"-->
<!-- android:layout_height="wrap_content"/>-->

<!-- <TextView-->
<!-- android:id="@+id/btn_bulpen"-->
<!-- android:layout_width="170dp"-->
<!-- android:layout_marginTop="650dp"-->
<!-- android:layout_marginStart="1250dp"-->
<!-- android:textSize="36sp"-->
<!-- android:textColor="@color/white"-->
<!-- android:text="手动补盆"-->
<!-- android:gravity="center"-->
<!-- android:background="@drawable/bg_round15_yellow_btn"-->
<!-- android:layout_height="80dp"/>-->

<!-- <TextView-->
<!-- android:id="@+id/tv_buliao_box"-->
<!-- android:layout_width="300dp"-->
<!-- android:layout_marginTop="550dp"-->
<!-- android:layout_marginStart="670dp"-->
<!-- android:textSize="36sp"-->
<!-- android:textColor="@color/black"-->
<!-- android:text="出料盆检测:无盆"-->
<!-- android:gravity="center"-->
<!-- android:layout_height="wrap_content"/>-->

<!-- <TextView-->
<!-- android:id="@+id/tv_chuliao_box"-->
<!-- android:layout_width="300dp"-->
<!-- android:layout_marginTop="600dp"-->
<!-- android:layout_marginStart="670dp"-->
<!-- android:textSize="36sp"-->
<!-- android:textColor="@color/black"-->
<!-- android:text="补料盆检测:无盆"-->
<!-- android:gravity="center"-->
<!-- android:layout_height="wrap_content"/>-->

<!-- <TextView-->
<!-- android:id="@+id/tv_shusongxian"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_marginTop="700dp"-->
<!-- android:layout_marginStart="500dp"-->
<!-- android:textSize="36sp"-->
<!-- android:textColor="@color/black"-->
<!-- android:text="输送线状态:停止"-->
<!-- android:gravity="center"-->
<!-- android:layout_height="80dp"/>-->

<TextView
android:id="@+id/btn_line_open"
android:layout_width="180dp"
android:layout_gravity="bottom"
android:layout_marginBottom="200dp"
android:layout_marginStart="430dp"
android:textSize="36sp"
android:textColor="@color/white"
android:text="启动输送线"
android:gravity="center"
android:background="@drawable/bg_round15_yellow_btn"
android:visibility="gone"
android:layout_height="80dp"/>

<TextView
android:id="@+id/btn_line_close"
android:layout_width="180dp"
android:layout_gravity="bottom"
android:layout_marginBottom="200dp"
android:layout_marginStart="650dp"
android:textSize="36sp"
android:textColor="@color/white"
android:text="关闭输送线"
android:gravity="center"
android:visibility="gone"
android:background="@drawable/bg_round15_yellow_btn"
android:layout_height="80dp"/>

<!-- <TextView-->
<!-- android:id="@+id/btn_chucai"-->
<!-- android:layout_width="300dp"-->
<!-- android:layout_marginTop="390dp"-->
<!-- android:layout_marginStart="620dp"-->
<!-- android:textSize="36sp"-->
<!-- android:textColor="@color/white"-->
<!-- android:text="出菜"-->
<!-- android:gravity="center"-->
<!-- android:background="#c0BEAA6A"-->
<!-- android:layout_height="150dp"/>-->


</FrameLayout>


+ 8
- 72
app/src/main/res/layout/new/layout/fragment_home_goods.xml View File

@@ -11,62 +11,21 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_classify"
android:layout_width="200dp"
android:orientation="vertical"
android:background="@color/white"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:layout_weight="1"
android:layout_height="match_parent">
<TextView
android:layout_height="90dp"
android:layout_width="200dp"
android:background="@color/main_title_color1"
android:textSize="36sp"
android:textColor="@color/white"
android:text="炒菜"
android:gravity="center"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_classify"
android:layout_width="200dp"
android:orientation="vertical"
android:background="@color/white"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:layout_weight="1"
android:layout_height="0dp">
</androidx.recyclerview.widget.RecyclerView>
<TextView
android:layout_height="90dp"
android:layout_width="200dp"
android:background="@color/main_title_color1"
android:textSize="36sp"
android:textColor="@color/white"
android:text="烤菜"
android:gravity="center"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_classify2"
android:layout_width="200dp"
android:orientation="vertical"
android:background="@color/white"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:layout_weight="1"
android:layout_height="0dp"
>
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
</androidx.recyclerview.widget.RecyclerView>

<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="220dp"
tools:text="炒菜-小炒肉"
android:textSize="32sp"
/>
<androidx.recyclerview.widget.RecyclerView
android:layout_marginStart="220dp"
android:layout_toStartOf="@id/ll_right"
android:layout_marginEnd="20dp"
android:layout_marginTop="55dp"
android:paddingTop="20dp"
android:id="@+id/recycler_goods"
android:layout_width="match_parent"
android:orientation="vertical"
@@ -89,7 +48,7 @@
android:background="@color/main_title_color1"
android:textSize="32sp"
android:textColor="@color/black"
android:text="炒菜订单"
android:text="订单列表"
android:gravity="center"
/>
<androidx.recyclerview.widget.RecyclerView
@@ -100,29 +59,6 @@
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="vertical"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="5dp"
/>
<TextView
android:id="@+id/tv2"
android:layout_height="50dp"
android:layout_width="match_parent"
android:textSize="32sp"
android:textColor="@color/black"
android:background="@color/main_title_color1"
android:text="烤箱订单"
android:gravity="center"
/>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_kao_order"
android:layout_width="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="vertical"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>

</RelativeLayout>


+ 13
- 15
app/src/main/res/layout/new/layout/fragment_home_order.xml View File

@@ -19,14 +19,14 @@
android:layout_height="match_parent">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_weight="2"
android:orientation="vertical"
android:layout_height="match_parent">
<!-- android:background="@drawable/bg_tab_title_select
bg_tab_title_textcolor_select"-->
<TextView
android:id="@+id/tv_chaocai"
android:text="炒菜"
android:text="订单列表"
android:textSize="32sp"
android:background="@color/main_title_color1"
android:textColor="@color/white"
@@ -45,34 +45,32 @@
android:orientation="vertical"
android:layout_height="match_parent"/>
</LinearLayout>

<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginEnd="20dp"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_height="match_parent">

<TextView
android:id="@+id/tv_kaoxiang"
android:text="烤箱"
android:text="设备状态"
android:textSize="32sp"
android:background="@color/main_title_color1"
android:textColor="@color/white"
android:gravity="center"
android:layout_marginBottom="20dp"
android:layout_width="200dp"
android:layout_gravity="center_horizontal"
android:layout_height="70dp"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_info2"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_marginStart="25dp"
android:layout_marginEnd="50dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
<LinearLayout
android:id="@+id/ll_devices"
android:layout_width="400dp"
android:orientation="vertical"
android:layout_height="match_parent"/>
</LinearLayout>
android:layout_height="match_parent">

</LinearLayout>

</LinearLayout>
</LinearLayout>




+ 5
- 5
app/src/main/res/layout/new/layout/fragment_home_warn_info.xml View File

@@ -16,7 +16,7 @@
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="480dp"
android:layout_width="580dp"
android:orientation="horizontal"
android:background="@drawable/bg_tab_title"
android:layout_height="70dp">
@@ -26,7 +26,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bg_tab_title_select"
android:text="炒锅"
android:text="1号炒锅"
style="@style/TextView_desc"
android:textColor="@drawable/bg_tab_title_textcolor_select"
/>
@@ -41,7 +41,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bg_tab_title_select"
android:text="烤箱"
android:text="2号炒锅"
style="@style/TextView_desc"
android:textColor="@drawable/bg_tab_title_textcolor_select"
/>
@@ -54,9 +54,9 @@
android:id="@+id/title_robot"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_weight="1.5"
android:background="@drawable/bg_tab_title_select"
android:text="机器人"
android:text="机器人+输送线"
style="@style/TextView_desc"
android:textColor="@drawable/bg_tab_title_textcolor_select"
/>


+ 65
- 0
app/src/main/res/layout/new/layout/view_device_status.xml View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="300dp"
tools:layout_width="400dp"
android:paddingBottom="20dp"
android:id="@+id/root"
android:paddingTop="20dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
>

<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="1号炒锅"
android:textSize="@dimen/sp_36"
android:maxLines="1"
android:singleLine="true"
android:ellipsize="end"
android:textColor="@color/black"
/>

<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="空闲"
android:textSize="@dimen/sp_36"
android:maxLines="1"
android:singleLine="true"
android:ellipsize="end"
android:layout_gravity="end"
android:textColor="@color/black"
/>

<TextView
android:id="@+id/tv_goods"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="正在烹饪:小炒肉-大份小炒肉-大份小炒肉-大份小炒肉-大份小炒肉-大份小炒肉-大份"
android:textSize="@dimen/sp_32"
android:maxLines="3"
android:ellipsize="end"
android:layout_gravity="center_vertical"
android:textColor="@color/black"
/>

<TextView
android:id="@+id/tv_wendu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="炒锅温度:??°C"
android:textSize="@dimen/sp_32"
android:maxLines="1"
android:singleLine="true"
android:ellipsize="end"
android:layout_gravity="end|bottom"
android:textColor="@color/black"
/>

</FrameLayout>

BIN
View File


Loading…
Cancel
Save