@@ -28,6 +28,7 @@ import com.bonait.bnframework.common.helper.CrashHandler; | |||
import com.bonait.bnframework.common.helper.I.IMessageLogNotify; | |||
import com.bonait.bnframework.common.helper.MessageLog; | |||
import com.bonait.bnframework.common.helper.SdCart; | |||
import com.bonait.bnframework.common.utils.ToastUtils; | |||
import com.bonait.bnframework.manager.ActivityLifecycleManager; | |||
import com.bonait.bnframework.common.constant.Constants; | |||
import com.bonait.bnframework.common.notification.MainNotification; | |||
@@ -157,6 +158,8 @@ public class MainApplication extends Application { | |||
{ | |||
ConfigData.getInstance().RevertPLC(); | |||
} | |||
RevertProcess(); | |||
} | |||
/** | |||
* 删除表-重新生成新表 | |||
@@ -165,7 +168,21 @@ public class MainApplication extends Application { | |||
{ | |||
DBHelper.getInstance(this).DeleteCreateTables(BPA_CLOUDDATA.class,null); | |||
DBHelper.getInstance(this).DeleteCreateTables(BPA_PLCADDRESS.class,null); | |||
} | |||
public void RevertProcess() | |||
{ | |||
ArrayList<BPA_PROCESS> arrayList= QueryDB.GetProcessALL(); | |||
for (BPA_PROCESS item:arrayList) | |||
{ | |||
ArrayList<BPA_PROCESSModel> arrayList1= QueryDB.GetProcessModelALL(); | |||
for (BPA_PROCESSModel item1:arrayList1) | |||
{ | |||
QueryDB.DeleteProcessModel(item1); | |||
} | |||
QueryDB.DeleteProcess(item); | |||
} | |||
InitProcessData(); | |||
} | |||
/** | |||
@@ -176,12 +193,12 @@ public class MainApplication extends Application { | |||
List<String> mxname=Arrays.asList("搅拌","位置","加热","主料","液体料","延迟","出菜"); | |||
Map<String,List<String>> mx=new IdentityHashMap<>(); | |||
mx.put("搅拌",Arrays.asList("搅拌速度","延迟(秒)")); | |||
mx.put("位置",Arrays.asList("位置动作","延迟(秒)")); | |||
mx.put("位置",Arrays.asList("位置动作","转动速度","延迟(秒)")); | |||
mx.put("加热",Arrays.asList("加热功率","延迟(秒)")); | |||
mx.put("主料",Arrays.asList("主料名称","主料重量","烹饪(秒)","投料动作")); | |||
mx.put("主料",Arrays.asList("主料名称","主料重量","延迟(秒)","投料动作")); | |||
mx.put("液体料",new ArrayList<>()); | |||
mx.put("延迟",Arrays.asList("延迟(秒)")); | |||
mx.put("出菜",Arrays.asList("时间(秒)")); | |||
mx.put("出菜",Arrays.asList("延迟(秒)")); | |||
int index=1; | |||
for (String key:mxname) | |||
@@ -207,14 +224,14 @@ public class MainApplication extends Application { | |||
else if (item.equals("位置动作")) | |||
{ | |||
processModel.datatype=2; | |||
processModel.data="原点位、出餐位、倒菜位、抽料位、清洗位、炒菜位1、炒菜位2、炒菜位3"; | |||
processModel.data="原点位、投料位、出餐启动、倒菜位、抽料位、清洗位、炒菜位1、炒菜位2、炒菜位3"; | |||
} | |||
else if (item.equals("投料动作")) | |||
{ | |||
processModel.datatype=2; | |||
processModel.data="投出抖动三次、投出等待三秒、直接投出、手动投料"; | |||
} | |||
else if (item.equals("正转速度") || item.equals("反转速度") || item.equals("搅拌速度")) | |||
else if (item.equals("正转速度") || item.equals("反转速度") || item.equals("转动速度")|| item.equals("搅拌速度")) | |||
{ | |||
processModel.datatype=2; | |||
processModel.data="停止、最低、低速、中速、高速、最高、极高"; | |||
@@ -313,6 +330,7 @@ public class MainApplication extends Application { | |||
@Override | |||
public void InfoMsg(String msg) { | |||
Log.i("Info", msg); | |||
} | |||
@Override | |||
public void WarnMsg(String msg) { | |||
@@ -355,6 +373,7 @@ public class MainApplication extends Application { | |||
break; | |||
} | |||
log.text = msg; | |||
QueryDB.AddAlertlog(log); | |||
} | |||
}; | |||
@@ -10,9 +10,12 @@ import com.bonait.bnframework.common.db.QueryDB; | |||
import com.bonait.bnframework.common.db.mode.BPA_CLOUDDATA; | |||
import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; | |||
import com.bonait.bnframework.common.db.mode.BPA_SYSTEMSET; | |||
import com.bonait.bnframework.common.db.mode.Res_PLCADDRESS; | |||
import com.bonait.bnframework.common.helper.ConfigUtil; | |||
import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback; | |||
import com.bonait.bnframework.common.image.utils.LocalCacheUtils; | |||
import com.bonait.bnframework.common.modbus.ModbusTcpHelper; | |||
import com.bonait.bnframework.common.modbus.ModbusTcpServer; | |||
import com.bonait.bnframework.common.model.ResAPI; | |||
import com.bonait.bnframework.common.model.ResListAPI; | |||
import com.bonait.bnframework.common.model.mode.CloudGood; | |||
@@ -379,12 +382,13 @@ public class ConfigData { | |||
QueryDB.DeletePlcaddress(item); | |||
} | |||
int k=1; | |||
for (Map.Entry<String, String> entry : ConfigName.getInstance().PlcAddress_ys.entrySet()) { | |||
String key = entry.getKey(); | |||
String value = entry.getValue(); | |||
for (Res_PLCADDRESS item:ConfigName.getInstance().PlcAddress_大炒) | |||
{ | |||
BPA_PLCADDRESS plc=new BPA_PLCADDRESS(); | |||
plc.name=key; | |||
plc.address=value; | |||
plc.name=item.name; | |||
plc.address=item.address; | |||
plc.isread=item.isread; | |||
plc.iswrite=item.iswrite; | |||
plc.sort=k; | |||
k++; | |||
QueryDB.AddPlcaddress(plc); | |||
@@ -395,5 +399,52 @@ public class ConfigData { | |||
} | |||
} | |||
//endregion | |||
//region PLC初始化 | |||
/** | |||
* 连接PLC | |||
*/ | |||
public void ConnectPLC() | |||
{ | |||
ConfigName.getInstance().PLC_Address.clear(); | |||
ArrayList<BPA_PLCADDRESS> address=QueryDB.GetPlcaddressALL(); | |||
for (BPA_PLCADDRESS item:address) | |||
{ | |||
if(!item.address.isEmpty() && !item.address.equals("-------------")) | |||
{ | |||
ConfigName.getInstance().PLC_Address.put(item.name,item); | |||
} | |||
} | |||
ExecuteTheRecipe.Listening();//启动数据监听 | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
ModbusTcpServer.get().Connect(); | |||
} catch (Exception e) { | |||
} | |||
} | |||
}).start(); | |||
} | |||
/** | |||
* 关闭PLC | |||
*/ | |||
public void ColsePLC() | |||
{ | |||
ModbusTcpHelper.get().release();//释放modbus | |||
} | |||
/** | |||
* PLC初始化完成时,需要注册的服务 | |||
*/ | |||
public void PLC_Init() | |||
{ | |||
} | |||
//endregion | |||
} | |||
@@ -1,29 +1,48 @@ | |||
package com.bonait.bnframework.business; | |||
import android.content.Context; | |||
import com.bonait.bnframework.common.constant.ConfigName; | |||
import com.bonait.bnframework.common.db.QueryDB; | |||
import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; | |||
import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; | |||
import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; | |||
import com.bonait.bnframework.common.db.mode.BPA_SILOS; | |||
import com.bonait.bnframework.common.helper.I.IThread; | |||
import com.bonait.bnframework.common.helper.I.IWriteCallBack; | |||
import com.bonait.bnframework.common.helper.ThreadManager; | |||
import com.bonait.bnframework.common.modbus.ModbusTcpServer; | |||
import com.bonait.bnframework.common.utils.AlertDialogUtils; | |||
import com.bonait.bnframework.common.utils.ToastUtils; | |||
import com.bonait.bnframework.modules.home.fragment.mode.LocationStatus; | |||
import com.bonait.bnframework.modules.home.fragment.mode.MyStatus; | |||
import com.qmuiteam.qmui.widget.dialog.QMUIDialog; | |||
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.IdentityHashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.concurrent.ConcurrentHashMap; | |||
/** | |||
* 执行配方 | |||
*/ | |||
public class ExecuteTheRecipe { | |||
/** | |||
* 监听变量值 | |||
*/ | |||
public static HashMap<String, Object> ListeningValue = new HashMap<String, Object>(); | |||
/** | |||
* 执行配方 | |||
* | |||
* @param recipe | |||
* @return | |||
*/ | |||
public static Context context=null; | |||
public static boolean Execute(BPA_GOODSRECIPE recipe) { | |||
boolean status = false; | |||
try { | |||
@@ -34,7 +53,7 @@ public class ExecuteTheRecipe { | |||
ExecuteMaterialIssuance(recipe.processvalue); | |||
} else if (recipe.materialType == 1)//工序模型 | |||
{ | |||
ExecuteOperationSteps(recipe.processname,recipe.processvalue); | |||
ExecuteOperationSteps(recipe.processname, recipe.processvalue); | |||
} | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
@@ -51,37 +70,29 @@ public class ExecuteTheRecipe { | |||
*/ | |||
private static void ExecuteMaterialIssuance(String text) { | |||
try { | |||
if(!text.isEmpty()) | |||
{ | |||
if (!text.isEmpty()) { | |||
//仓号 值 | |||
HashMap<Integer,Integer> formulation=new HashMap<>(); | |||
HashMap<Integer, Integer> formulation = new HashMap<>(); | |||
//region 获取仓号和值 | |||
List<String> data=new ArrayList<>(); | |||
if(text.contains("|")) | |||
{ | |||
String[] res= text.split("[|]"); | |||
for (int i=0;i<res.length;i++) | |||
{ | |||
List<String> data = new ArrayList<>(); | |||
if (text.contains("|")) { | |||
String[] res = text.split("[|]"); | |||
for (int i = 0; i < res.length; i++) { | |||
data.add(res[i]); | |||
} | |||
}else | |||
{ | |||
} else { | |||
data.add(text); | |||
} | |||
for(String item:data) | |||
{ | |||
if(!item.isEmpty() && item.contains(",")) | |||
{ | |||
String[] wl= item.split("[,]"); | |||
if (wl != null && wl.length == 2) | |||
{ | |||
String name=wl[0]; | |||
int val=Integer.parseInt(wl[1]); | |||
List<BPA_SILOS> bpa_silos= QueryDB.GetSolisByMaterialName(name); | |||
if(bpa_silos.size()>0 && val>0) | |||
{ | |||
BPA_SILOS silos= bpa_silos.get(0); | |||
formulation.put(silos.num,val); | |||
for (String item : data) { | |||
if (!item.isEmpty() && item.contains(",")) { | |||
String[] wl = item.split("[,]"); | |||
if (wl != null && wl.length == 2) { | |||
String name = wl[0]; | |||
int val = Integer.parseInt(wl[1]); | |||
List<BPA_SILOS> bpa_silos = QueryDB.GetSolisByMaterialName(name); | |||
if (bpa_silos.size() > 0 && val > 0) { | |||
BPA_SILOS silos = bpa_silos.get(0); | |||
formulation.put(silos.num, val); | |||
} | |||
} | |||
} | |||
@@ -91,7 +102,7 @@ public class ExecuteTheRecipe { | |||
for (Map.Entry<Integer, Integer> entry : formulation.entrySet()) { | |||
Integer key = entry.getKey(); | |||
Integer value = entry.getValue(); | |||
Write_PLC_Material(key,value); | |||
Write_PLC_Material(key, value); | |||
} | |||
} | |||
} catch (Exception ex) { | |||
@@ -106,66 +117,51 @@ public class ExecuteTheRecipe { | |||
*/ | |||
private static void ExecuteOperationSteps(String processname, String text) { | |||
try { | |||
if(!text.isEmpty() && !processname.isEmpty()) | |||
{ | |||
if (!text.isEmpty() && !processname.isEmpty()) { | |||
//工序名称和值 | |||
HashMap<String,String> formulation=new HashMap<>(); | |||
HashMap<String, String> formulation = new HashMap<>(); | |||
//region 获取仓号和值 | |||
List<String> data=new ArrayList<>(); | |||
if(text.contains("|")) | |||
{ | |||
String[] res= text.split("[|]"); | |||
for (int i=0;i<res.length;i++) | |||
{ | |||
List<String> data = new ArrayList<>(); | |||
if (text.contains("|")) { | |||
String[] res = text.split("[|]"); | |||
for (int i = 0; i < res.length; i++) { | |||
data.add(res[i]); | |||
} | |||
}else | |||
{ | |||
} else { | |||
data.add(text); | |||
} | |||
for(String item:data) | |||
{ | |||
if(!item.isEmpty() && item.contains(",")) | |||
{ | |||
String[] wl= item.split("[,]"); | |||
if (wl != null && wl.length == 2) | |||
{ | |||
String name=wl[0]; | |||
String val=wl[1]; | |||
formulation.put(name,val); | |||
for (String item : data) { | |||
if (!item.isEmpty() && item.contains(",")) { | |||
String[] wl = item.split("[,]"); | |||
if (wl != null && wl.length == 2) { | |||
String name = wl[0]; | |||
String val = wl[1]; | |||
formulation.put(name, val); | |||
} | |||
} | |||
} | |||
//endregion | |||
//写入PLC | |||
if(formulation.size()>0) | |||
{ | |||
switch (processname) | |||
{ | |||
if (formulation.size() > 0) { | |||
switch (processname) { | |||
case "搅拌": | |||
Write_PLC_Stir(formulation); | |||
break; | |||
case "热油": | |||
Write_PLC_Hotoil(formulation); | |||
break; | |||
case "主料": | |||
Write_PLC_Ingredients(formulation); | |||
case "位置": | |||
Write_PLC_Location(formulation); | |||
break; | |||
case "加热": | |||
Write_PLC_Heating(formulation); | |||
break; | |||
case "主料": | |||
Write_PLC_Ingredients(formulation); | |||
break; | |||
case "延迟": | |||
Write_PLC_Delay(formulation); | |||
break; | |||
case "勾芡": | |||
Write_PLC_Gouqiu(formulation); | |||
break; | |||
case "出菜": | |||
Write_PLC_Outdishes(formulation); | |||
break; | |||
case "热锅": | |||
Write_PLC_Hotpan(formulation); | |||
break; | |||
} | |||
} | |||
} | |||
@@ -175,19 +171,45 @@ public class ExecuteTheRecipe { | |||
} | |||
//region 物料PLC控制 | |||
/** | |||
* 写入仓号需求值 | |||
* | |||
* @param num | |||
* @param val | |||
*/ | |||
private static void Write_PLC_Material(int num,int val) | |||
{ | |||
try | |||
{ | |||
ToastUtils.info("写入PLC仓号需求:" + num+","+val); | |||
Thread.sleep(1000); | |||
}catch (Exception ex) | |||
{ | |||
private static void Write_PLC_Material(int num, int val) { | |||
try { | |||
WritePLC("料仓" + num + "需求值", val, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
WritePLC("料仓" + num +"下料",true,null); | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
} | |||
}); | |||
//一直等待下料完成 否则就一直等待 6s超时 | |||
String name="料仓" + num +"下料完成"; | |||
final boolean[] IsComplete = {false}; | |||
long a = System.currentTimeMillis(); | |||
while (!IsComplete[0]) { | |||
if ((System.currentTimeMillis() - a) > 1000 * 60) { | |||
break; | |||
}else | |||
{ | |||
Object sb= ListeningValue.get(name); | |||
if(sb!=null) | |||
{ | |||
IsComplete[0]=(boolean)(sb); | |||
} | |||
} | |||
Thread.sleep(100);//10 *6 | |||
} | |||
ToastUtils.info("写入PLC仓号需求:" + num + "," + val); | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} | |||
} | |||
@@ -197,165 +219,210 @@ public class ExecuteTheRecipe { | |||
/** | |||
* 写PLC搅拌 | |||
* | |||
* @param data | |||
*/ | |||
private static void Write_PLC_Stir(HashMap<String,String> data) | |||
{ | |||
try | |||
{ | |||
private static void Write_PLC_Stir(HashMap<String, String> data) { | |||
try { | |||
for (HashMap.Entry<String, String> entry : data.entrySet()) { | |||
String key = entry.getKey(); | |||
String value = entry.getValue(); | |||
ToastUtils.info("写入PLC工序需求:" + key+","+value); | |||
Thread.sleep(1000); | |||
ToastUtils.info("工序:" + key + "," + value); | |||
if (key.contains("延迟")) { | |||
int val = Integer.parseInt(value); | |||
ToastUtils.info("延迟:" + value + "s"); | |||
Thread.sleep(val * 1000); | |||
} else { | |||
int writeValue = GetMXValue(key,value); | |||
WritePLC(key, writeValue, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
if(writeValue==0) | |||
{ | |||
WritePLC("搅拌",false,null); | |||
}else | |||
{ | |||
WritePLC("搅拌",true,null); | |||
} | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
} | |||
}); | |||
} | |||
} | |||
}catch (Exception ex) | |||
{ | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* 写PLC热油 | |||
* 写PLC位置 | |||
* | |||
* @param data | |||
*/ | |||
private static void Write_PLC_Hotoil(HashMap<String,String> data) | |||
{ | |||
try | |||
{ | |||
private static void Write_PLC_Location(HashMap<String, String> data) { | |||
try { | |||
for (HashMap.Entry<String, String> entry : data.entrySet()) { | |||
String key = entry.getKey(); | |||
String value = entry.getValue(); | |||
ToastUtils.info("写入PLC工序需求:" + key+","+value); | |||
Thread.sleep(1000); | |||
ToastUtils.info("工序:" + key + "," + value); | |||
if (key.contains("延迟")) { | |||
int val = Integer.parseInt(value); | |||
ToastUtils.info("延迟:" + value + "s"); | |||
Thread.sleep(val * 1000); | |||
} else { | |||
//原点位,等待机器移动倒响应位置 | |||
WritePLC(value, true,null); | |||
//一直等待机器移动到该位置,否则就一直等待 6s超时 | |||
String name=value+"反馈"; | |||
final boolean[] IsComplete = {false}; | |||
long a = System.currentTimeMillis(); | |||
while (!IsComplete[0]) { | |||
if ((System.currentTimeMillis() - a) > 1000 * 60) { | |||
break; | |||
}else | |||
{ | |||
Object sb= ListeningValue.get(name); | |||
if(sb!=null) | |||
{ | |||
IsComplete[0]=(boolean)(sb); | |||
} | |||
} | |||
Thread.sleep(100);//10 *6 | |||
} | |||
} | |||
} | |||
}catch (Exception ex) | |||
{ | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* 写PLC主料 | |||
* | |||
* @param data | |||
*/ | |||
private static void Write_PLC_Ingredients(HashMap<String,String> data) | |||
{ | |||
try | |||
{ | |||
private static void Write_PLC_Ingredients(HashMap<String, String> data) { | |||
try { | |||
String name=""; | |||
String zl=""; | |||
int val=0; | |||
for (HashMap.Entry<String, String> entry : data.entrySet()) { | |||
String key = entry.getKey(); | |||
String value = entry.getValue(); | |||
ToastUtils.info("写入PLC工序需求:" + key+","+value); | |||
Thread.sleep(1000); | |||
if(key.contains("名称")) | |||
{ | |||
name=value; | |||
}else if(key.contains("重量")) | |||
{ | |||
zl=value; | |||
} | |||
} | |||
}catch (Exception ex) | |||
{ | |||
ToastUtils.info("工序:手动投料," + name + "," + zl); | |||
String title = "手动投料-温馨提示!"; | |||
String message = "客官请投入主料,["+name+"]重量"+zl+"g,投入后点击[确定]继续流程!"; | |||
AlertDialogUtils.showDialog(context, title, message, new QMUIDialogAction.ActionListener() { | |||
@Override | |||
public void onClick(QMUIDialog dialog, int index) { | |||
dialog.dismiss(); | |||
} | |||
}); | |||
ToastUtils.info("确定完成,继续制作!"); | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* 写PLC 加热 | |||
* | |||
* @param data | |||
*/ | |||
private static void Write_PLC_Heating(HashMap<String,String> data) | |||
{ | |||
try | |||
{ | |||
private static void Write_PLC_Heating(HashMap<String, String> data) { | |||
try { | |||
for (HashMap.Entry<String, String> entry : data.entrySet()) { | |||
String key = entry.getKey(); | |||
String value = entry.getValue(); | |||
ToastUtils.info("写入PLC工序需求:" + key+","+value); | |||
Thread.sleep(1000); | |||
} | |||
}catch (Exception ex) | |||
{ | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* 写PLC 延迟 | |||
* @param data | |||
*/ | |||
private static void Write_PLC_Delay(HashMap<String,String> data) | |||
{ | |||
try | |||
{ | |||
for (HashMap.Entry<String, String> entry : data.entrySet()) { | |||
String key = entry.getKey(); | |||
String value = entry.getValue(); | |||
if(key.contains("延迟")) | |||
{ | |||
int val=Integer.parseInt(value); | |||
ToastUtils.info("延迟:"+value+"s"); | |||
Thread.sleep(val*1000); | |||
ToastUtils.info("工序:" + key + "," + value); | |||
if (key.contains("延迟")) { | |||
int val = Integer.parseInt(value); | |||
ToastUtils.info("延迟:" + value + "s"); | |||
Thread.sleep(val * 1000); | |||
} else { | |||
int writeValue = GetMXValue(key,value); | |||
WritePLC(key, writeValue, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
if(writeValue==0) | |||
{ | |||
WritePLC("加热",false,null); | |||
}else | |||
{ | |||
WritePLC("加热",true,null); | |||
} | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
} | |||
}); | |||
} | |||
} | |||
}catch (Exception ex) | |||
{ | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* 写PLC 勾芡 | |||
* 写PLC 延迟 | |||
* | |||
* @param data | |||
*/ | |||
private static void Write_PLC_Gouqiu(HashMap<String,String> data) | |||
{ | |||
try | |||
{ | |||
private static void Write_PLC_Delay(HashMap<String, String> data) { | |||
try { | |||
for (HashMap.Entry<String, String> entry : data.entrySet()) { | |||
String key = entry.getKey(); | |||
String value = entry.getValue(); | |||
ToastUtils.info("写入PLC工序需求:" + key+","+value); | |||
Thread.sleep(1000); | |||
if (key.contains("延迟")) { | |||
int val = Integer.parseInt(value); | |||
ToastUtils.info("延迟:" + value + "s"); | |||
Thread.sleep(val * 1000); | |||
} | |||
} | |||
}catch (Exception ex) | |||
{ | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* 写PLC 出菜 | |||
* | |||
* @param data | |||
*/ | |||
private static void Write_PLC_Outdishes(HashMap<String,String> data) | |||
{ | |||
try | |||
{ | |||
private static void Write_PLC_Outdishes(HashMap<String, String> data) { | |||
try { | |||
for (HashMap.Entry<String, String> entry : data.entrySet()) { | |||
String key = entry.getKey(); | |||
String value = entry.getValue(); | |||
int val=Integer.parseInt(value); | |||
ToastUtils.info("出菜延迟:"+value+"s"); | |||
Thread.sleep(val*1000); | |||
} | |||
}catch (Exception ex) | |||
{ | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* 写PLC 热锅 | |||
* @param data | |||
*/ | |||
private static void Write_PLC_Hotpan(HashMap<String,String> data) | |||
{ | |||
try | |||
{ | |||
for (HashMap.Entry<String, String> entry : data.entrySet()) { | |||
String key = entry.getKey(); | |||
String value = entry.getValue(); | |||
ToastUtils.info("写入PLC工序需求:" + key+","+value); | |||
Thread.sleep(1000); | |||
ToastUtils.info("工序:" + key + "," + value); | |||
if (key.contains("延迟")) { | |||
int val = Integer.parseInt(value); | |||
ToastUtils.info("延迟:" + value + "s"); | |||
Thread.sleep(val * 1000); | |||
} | |||
} | |||
}catch (Exception ex) | |||
{ | |||
WritePLC("出菜", true,null); | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} | |||
} | |||
@@ -365,89 +432,195 @@ public class ExecuteTheRecipe { | |||
/** | |||
* 点击清洗按钮 | |||
* | |||
* @param data | |||
*/ | |||
public static void Write_PLC_Clean(MyStatus data) | |||
{ | |||
try | |||
{ | |||
if(data==MyStatus.Start) | |||
{ | |||
public static void Write_PLC_Clean(MyStatus data) { | |||
try { | |||
if (data == MyStatus.Start) { | |||
ToastUtils.info("点击启动搅拌清洗按钮"); | |||
}else if(data==MyStatus.Paused) | |||
{ | |||
} else if (data == MyStatus.Paused) { | |||
ToastUtils.info("点击暂停清洗按钮"); | |||
}else if(data==MyStatus.Stop) | |||
{ | |||
} else if (data == MyStatus.Stop) { | |||
ToastUtils.info("点击停止清洗按钮"); | |||
} | |||
}catch (Exception ex) | |||
{ | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* 点击清洗按钮 | |||
* | |||
* @param data | |||
*/ | |||
public static void Write_PLC_Location(LocationStatus data) | |||
{ | |||
try | |||
{ | |||
if(data==LocationStatus.InLocation) | |||
{ | |||
public static void Write_PLC_Location(LocationStatus data) { | |||
try { | |||
if (data == LocationStatus.InLocation) { | |||
ToastUtils.info("点击炒菜位按钮"); | |||
}else if(data==LocationStatus.OutLocation) | |||
{ | |||
} else if (data == LocationStatus.OutLocation) { | |||
ToastUtils.info("点击出菜位按钮"); | |||
}else if(data==LocationStatus.PourWaterLocation) | |||
{ | |||
} else if (data == LocationStatus.PourWaterLocation) { | |||
ToastUtils.info("点击倒水位按钮"); | |||
} | |||
}catch (Exception ex) | |||
{ | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* 点击摇欠按钮 | |||
* | |||
* @param data | |||
*/ | |||
public static void Write_PLC_YaoQian(MyStatus data) | |||
{ | |||
try | |||
{ | |||
if(data==MyStatus.Start) | |||
{ | |||
public static void Write_PLC_YaoQian(MyStatus data) { | |||
try { | |||
if (data == MyStatus.Start) { | |||
ToastUtils.info("点击摇浅按钮"); | |||
}else if(data==MyStatus.Stop) | |||
{ | |||
} else if (data == MyStatus.Stop) { | |||
ToastUtils.info("点击停摇按钮"); | |||
} | |||
}catch (Exception ex) | |||
{ | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} | |||
} | |||
/** | |||
* 火力点击 | |||
* | |||
* @param data | |||
*/ | |||
public static void Write_PLC_HuoLI(int data) | |||
{ | |||
try | |||
{ | |||
public static void Write_PLC_HuoLI(int data) { | |||
try { | |||
ToastUtils.info("火力按钮点击,当前级别:" + data); | |||
}catch (Exception ex) | |||
{ | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} | |||
} | |||
//endregion | |||
//region PLC监听线程 | |||
public static void Listening() { | |||
ThreadManager.Get().StartLong("PLC设备数据监听", true, new IThread() { | |||
@Override | |||
public void Run() throws InterruptedException { | |||
try { | |||
for (String item : ConfigName.getInstance().PLC_Address.keySet()) { | |||
String key = item; | |||
BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(item); | |||
if (plcaddress.isread == 1) { | |||
Object val = ReadPLC(key); | |||
ListeningValue.put(key, val); | |||
} | |||
} | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} | |||
Thread.sleep(10); | |||
} | |||
@Override | |||
public void RunComplete() throws InterruptedException { | |||
} | |||
}); | |||
} | |||
//endregion | |||
//region PLC基础控制类 | |||
/** | |||
* 写PLC数据 | |||
* | |||
* @param name | |||
* @param value | |||
*/ | |||
public static void WritePLC(String name, Object value, IWriteCallBack callback) { | |||
try { | |||
if (ConfigName.getInstance().PLC_Address.containsKey(name)) { | |||
BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); | |||
if (!plcaddress.address.isEmpty() && ConfigName.getInstance().PlcIsConnect) { | |||
if (plcaddress.address.toUpperCase().startsWith("VD"))//int | |||
{ | |||
ModbusTcpServer.get().WriteInt(plcaddress.address, (int) value, callback); | |||
} else if (plcaddress.address.toUpperCase().startsWith("M"))//bool | |||
{ | |||
ModbusTcpServer.get().WriteBool(plcaddress.address, (boolean) value, callback); | |||
} else if (plcaddress.address.toUpperCase().startsWith("VW"))//short | |||
{ | |||
ModbusTcpServer.get().WriteShort(plcaddress.address, (Short) value, callback); | |||
} | |||
} | |||
} | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} finally { | |||
} | |||
} | |||
/** | |||
* 读PLC数据 | |||
* | |||
* @param name | |||
* @return | |||
*/ | |||
public static Object ReadPLC(String name) { | |||
final Object[] ReturnsVariable = {null}; | |||
try { | |||
if (ConfigName.getInstance().PLC_Address.containsKey(name)) { | |||
BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); | |||
if (!plcaddress.address.isEmpty() && ConfigName.getInstance().PlcIsConnect) { | |||
if (plcaddress.address.toUpperCase().startsWith("VD"))//int | |||
{ | |||
ModbusTcpServer.get().ReadInt(plcaddress.address, 1, val -> { | |||
ReturnsVariable[0] = val[0]; | |||
}); | |||
} else if (plcaddress.address.toUpperCase().startsWith("M"))//bool | |||
{ | |||
ModbusTcpServer.get().ReadBool(plcaddress.address, 1, val -> { | |||
ReturnsVariable[0] = val[0]; | |||
}); | |||
} else if (plcaddress.address.toUpperCase().startsWith("VW"))//short | |||
{ | |||
ModbusTcpServer.get().ReadShort(plcaddress.address, 1, val -> { | |||
ReturnsVariable[0] = val[0]; | |||
}); | |||
} | |||
} | |||
} | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} finally { | |||
return ReturnsVariable[0]; | |||
} | |||
} | |||
//endregion | |||
//region 获取基础挡位变量 | |||
/** | |||
* 获取挡位变量 | |||
* @param name | |||
* @param value | |||
* @return | |||
*/ | |||
public static int GetMXValue(String name, String value) { | |||
final int[] ReturnsVariable = {0}; | |||
try { | |||
if (name.contains("速度")) { | |||
ReturnsVariable[0] = ConfigName.getInstance().StirringSpeed.get(value); | |||
} else if (name.contains("功率")) { | |||
ReturnsVariable[0] = ConfigName.getInstance().HeatingGear.get(value); | |||
} | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} finally { | |||
return ReturnsVariable[0]; | |||
} | |||
} | |||
//endregion | |||
@@ -2,12 +2,18 @@ package com.bonait.bnframework.common.constant; | |||
import android.content.Context; | |||
import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; | |||
import com.bonait.bnframework.common.db.mode.BPA_USER; | |||
import com.bonait.bnframework.common.db.mode.Res_PLCADDRESS; | |||
import com.bonait.bnframework.common.model.AddrType; | |||
import com.bonait.bnframework.common.model.mode.DeviceInformation; | |||
import com.bonait.bnframework.common.model.mode.OrganizeMode; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.LinkedHashMap; | |||
import java.util.List; | |||
import java.util.concurrent.ConcurrentHashMap; | |||
/** | |||
@@ -166,6 +172,10 @@ public class ConfigName { | |||
//endregion | |||
//region PlC连接参数 | |||
/** | |||
* Plc是否连接 | |||
*/ | |||
public boolean PlcIsConnect=false; | |||
/** | |||
* Plc地址 | |||
*/ | |||
@@ -200,129 +210,168 @@ public class ConfigName { | |||
//region PLC地址配置 | |||
/** | |||
* PLC地址配置 | |||
*/ | |||
public HashMap<String,String> PlcAddress=new HashMap<String,String>(); | |||
public LinkedHashMap<String,String> PlcAddress_ys=new LinkedHashMap<String,String>(){ | |||
{ | |||
//硬件设备 初始化 | |||
put("硬件设备","-------------"); | |||
put("初始化", "M10.0"); | |||
put("停止", "M10.1"); | |||
put("复位", "M10.2"); | |||
//搅拌模型 | |||
put("模型控制","-------------" ); | |||
put("搅拌", "M10.3"); //搅拌启停 | |||
put("搅拌速度", "VW102"); | |||
//翻转正转模型 | |||
put("翻转正转", "M10.4"); | |||
put("正转速度", "VW104"); | |||
//翻转反转模型 | |||
put("翻转反转", "M10.5"); | |||
put("反转速度", "VW104"); | |||
//加热模型 | |||
put("加热", "M10.6"); | |||
put("加热功率", "VW100"); | |||
//抽水放水 | |||
put("炒锅抽水", "M10.7"); | |||
put("炒锅放水", "M11.0"); | |||
//出菜模型 | |||
put("出菜", "M11.5"); | |||
//位置动作 | |||
put("原点位", "M11.4"); | |||
put("出餐位", "M11.5"); | |||
put("倒菜位", "M12.7"); | |||
put("抽料位", "M11.7"); | |||
put("清洗位", "M13.0"); | |||
put("炒菜位1", "M12.0"); | |||
put("炒菜位2", "M12.1"); | |||
put("炒菜位3", "M12.2"); | |||
put("炒锅清洗", "M11.6"); | |||
put("液体料","-------------" ); | |||
//液体料模型 | |||
put("开始校正", "M12.6"); | |||
put("校准时间", "VW112"); | |||
put("料仓1", "M11.1"); | |||
put("料仓2", "M11.2"); | |||
put("料仓3", "M11.3"); | |||
put("通道1手动", "M12.3");//手动 | |||
put("通道2手动", "M12.4"); | |||
put("通道3手动", "M12.5"); | |||
put("料仓1校准值", "VW114"); | |||
put("料仓2校准值", "VW116"); | |||
put("料仓3校准值", "VW118"); | |||
put("料仓1", "M11.1"); | |||
put("料仓2", "M11.2"); | |||
put("料仓3", "M11.3"); | |||
//上下限 | |||
put("位置上下限","-------------"); | |||
put("原点位置下限", "VD150"); | |||
put("原点位置上限", "VD152"); | |||
put("洗锅位置下限", "VD154"); | |||
put("洗锅位置上限", "VD156"); | |||
put("倒菜位置下限", "VD158"); | |||
put("倒菜位置上限", "VD160"); | |||
put("抽调料位置下限", "VD162"); | |||
put("抽调料位置上限", "VD164"); | |||
put("1#炒制位置下限", "VD166"); | |||
put("1#炒制位置上限", "VD168"); | |||
put("2#炒制位置下限", "VD170"); | |||
put("2#炒制位置上限", "VD172"); | |||
put("3#炒制位置下限", "VD174"); | |||
put("3#炒制位置上限", "VD176"); | |||
put("炒锅工作范围下限", "VD178"); | |||
put("炒锅工作范围上限", "VD180"); | |||
put("反馈信号-基本","-------------"); | |||
put("初始化完成", "M40.0"); | |||
put("设备急停", "M40.1"); | |||
put("炒锅在原点位置", "M40.2"); | |||
put("抽料位置反馈", "M40.3"); | |||
put("炒制位置1反馈", "M40.4"); | |||
put("炒制位置2反馈", "M40.5"); | |||
put("炒制位置3反馈", "M40.6"); | |||
put("炒锅在出餐倒菜位置反馈", "M40.7"); | |||
put("炒锅在投料位置反馈", "M41.0"); | |||
put("炒锅在洗锅位置反馈", "M41.1"); | |||
put("通道1出料完成", "M41.2"); | |||
put("通道2出料完成", "M41.3"); | |||
put("通道3出料完成", "M41.4"); | |||
put("清洗完成", "M41.5"); | |||
put("倒菜完成", "M41.6"); | |||
put("炒锅倒菜减速位", "M41.7"); | |||
put("监测信号-基本", "-------------"); | |||
put("当前锅底温度", "VW300"); | |||
put("炒锅搅拌转速", "VW302"); | |||
put("当前加热档位", "VW304"); | |||
put("炒锅当前电压", "VW306"); | |||
put("炒锅当前电流", "VW308"); | |||
put("炒锅当前功率", "VW310"); | |||
put("搅拌频率", "VW312"); | |||
put("搅拌电机电压", "VW314"); | |||
put("搅拌电机电流", "VW316"); | |||
put("搅拌变频器温度", "VW318"); | |||
put("翻转频率", "VW320"); | |||
put("翻转电机电压", "VW322"); | |||
put("翻转电机电流", "VW324"); | |||
put("翻转变频器温度", "VW326"); | |||
put("编码器当前位值", "VW328"); | |||
} | |||
}; | |||
* PLC地址 | |||
*/ | |||
public static ConcurrentHashMap<String, BPA_PLCADDRESS> PLC_Address = new ConcurrentHashMap<String, BPA_PLCADDRESS>(); | |||
/** | |||
* 大炒基础PLC模型 | |||
*/ | |||
public List<Res_PLCADDRESS> PlcAddress_大炒=new ArrayList<Res_PLCADDRESS>(){{ | |||
//硬件设备 初始化 | |||
add(new Res_PLCADDRESS("硬件设备","-------------",0,0)); | |||
add(new Res_PLCADDRESS("初始化","M10.0",1,1)); | |||
add(new Res_PLCADDRESS("停止" ,"M10.1",1,1)); | |||
add(new Res_PLCADDRESS("复位" ,"M10.2",0,1)); | |||
//搅拌模型 | |||
add(new Res_PLCADDRESS("模型控制","-------------",0,0)); | |||
add(new Res_PLCADDRESS("搅拌","M10.3",0,1)); | |||
add(new Res_PLCADDRESS("搅拌速度","VW102",1,1)); | |||
//翻转正转模型 | |||
add(new Res_PLCADDRESS("翻转正转","M10.4",0,1)); | |||
add(new Res_PLCADDRESS("正转速度","VW104",1,1)); | |||
//翻转反转模型 | |||
add(new Res_PLCADDRESS("翻转反转","M10.5",0,1)); | |||
add(new Res_PLCADDRESS("反转速度","VW104",1,1)); | |||
//加热模型 | |||
add(new Res_PLCADDRESS("加热","M10.6",0,1)); | |||
add(new Res_PLCADDRESS("加热功率","VW100",1,1)); | |||
//抽水放水 | |||
add(new Res_PLCADDRESS("炒锅抽水","M10.7",0,1)); | |||
add(new Res_PLCADDRESS("炒锅放水","M11.0",0,1)); | |||
//出菜模型 | |||
add(new Res_PLCADDRESS("出菜","M11.5",0,1)); | |||
//位置动作 | |||
add(new Res_PLCADDRESS("原点位","M11.4",0,1)); | |||
add(new Res_PLCADDRESS("投料位","M11.4",0,1)); | |||
add(new Res_PLCADDRESS("倒菜位","M12.7",0,1)); | |||
add(new Res_PLCADDRESS("抽料位","M11.7",0,1)); | |||
add(new Res_PLCADDRESS("清洗位","M13.0",0,1)); | |||
add(new Res_PLCADDRESS("炒菜位1","M12.0",0,1)); | |||
add(new Res_PLCADDRESS("炒菜位2","M12.1",0,1)); | |||
add(new Res_PLCADDRESS("炒菜位3","M12.2",0,1)); | |||
add(new Res_PLCADDRESS("出餐启动","M11.5",0,1)); | |||
add(new Res_PLCADDRESS("炒锅清洗","M11.6",0,1)); | |||
//液体料模型 | |||
add(new Res_PLCADDRESS("液体料","-------------",0,0)); | |||
add(new Res_PLCADDRESS("料仓1下料","M11.1",0,1)); | |||
add(new Res_PLCADDRESS("料仓2下料","M11.2",0,1)); | |||
add(new Res_PLCADDRESS("料仓3下料","M11.3",0,1)); | |||
add(new Res_PLCADDRESS("料仓1下料手动","M12.3",0,1)); | |||
add(new Res_PLCADDRESS("料仓2下料手动","M12.4",0,1)); | |||
add(new Res_PLCADDRESS("料仓3下料手动","M12.5",0,1)); | |||
add(new Res_PLCADDRESS("开始校正","M12.6",0,1)); | |||
add(new Res_PLCADDRESS("料仓1需求值","VW106",1,1)); | |||
add(new Res_PLCADDRESS("料仓2需求值","VW108",1,1)); | |||
add(new Res_PLCADDRESS("料仓3需求值","VW110",1,1)); | |||
add(new Res_PLCADDRESS("校准时间","VW112",1,1)); | |||
add(new Res_PLCADDRESS("料仓1校准值","VW114",1,1)); | |||
add(new Res_PLCADDRESS("料仓2校准值","VW116",1,1)); | |||
add(new Res_PLCADDRESS("料仓3校准值","VW118",1,1)); | |||
//上下限 | |||
add(new Res_PLCADDRESS("位置上下限","-------------",0,0)); | |||
add(new Res_PLCADDRESS("原点位置下限","VD150",1,1)); | |||
add(new Res_PLCADDRESS("原点位置上限","VD154",1,1)); | |||
add(new Res_PLCADDRESS("洗锅位置下限","VD158",1,1)); | |||
add(new Res_PLCADDRESS("洗锅位置上限","VD162",1,1)); | |||
add(new Res_PLCADDRESS("倒菜位置下限","VD166",1,1)); | |||
add(new Res_PLCADDRESS("倒菜位置上限","VD170",1,1)); | |||
add(new Res_PLCADDRESS("抽调料位置下限","VD174",1,1)); | |||
add(new Res_PLCADDRESS("抽调料位置上限","VD178",1,1)); | |||
add(new Res_PLCADDRESS("1#炒制位置下限","VD182",1,1)); | |||
add(new Res_PLCADDRESS("1#炒制位置上限","VD186",1,1)); | |||
add(new Res_PLCADDRESS("2#炒制位置下限","VD190",1,1)); | |||
add(new Res_PLCADDRESS("2#炒制位置上限","VD194",1,1)); | |||
add(new Res_PLCADDRESS("3#炒制位置下限","VD198",1,1)); | |||
add(new Res_PLCADDRESS("3#炒制位置上限","VD202",1,1)); | |||
add(new Res_PLCADDRESS("炒锅工作范围下限","VD206",1,1)); | |||
add(new Res_PLCADDRESS("炒锅工作范围上限","VD210",1,1)); | |||
//反馈信号 | |||
add(new Res_PLCADDRESS("反馈信号","-------------",0,0)); | |||
add(new Res_PLCADDRESS("初始化完成","M40.0",1,0)); | |||
add(new Res_PLCADDRESS("设备急停","M40.1",1,0)); | |||
add(new Res_PLCADDRESS("原点位反馈","M40.2",1,0)); | |||
add(new Res_PLCADDRESS("抽料位反馈","M40.3",1,0)); | |||
add(new Res_PLCADDRESS("炒菜位1反馈","M40.4",1,0)); | |||
add(new Res_PLCADDRESS("炒菜位2反馈","M40.5",1,0)); | |||
add(new Res_PLCADDRESS("炒菜位3反馈","M40.6",1,0)); | |||
add(new Res_PLCADDRESS("倒菜位反馈","M40.7",1,0)); | |||
add(new Res_PLCADDRESS("投料位反馈","M41.0",1,0)); | |||
add(new Res_PLCADDRESS("清洗位反馈","M41.1",1,0)); | |||
add(new Res_PLCADDRESS("料仓1下料完成","M41.2",1,0)); | |||
add(new Res_PLCADDRESS("料仓2下料完成","M41.3",1,0)); | |||
add(new Res_PLCADDRESS("料仓3下料完成","M41.4",1,0)); | |||
add(new Res_PLCADDRESS("炒锅清洗反馈","M41.5",1,0)); | |||
add(new Res_PLCADDRESS("出餐启动反馈","M41.6",1,0)); | |||
add(new Res_PLCADDRESS("炒锅倒菜减速位","M41.7",1,0)); | |||
//检测信号 | |||
add(new Res_PLCADDRESS("监测信号","-------------",0,0)); | |||
add(new Res_PLCADDRESS("当前锅底温度","VD300",1,0)); | |||
add(new Res_PLCADDRESS("炒锅搅拌转速","VD304",1,0)); | |||
add(new Res_PLCADDRESS("当前加热档位","VD308",1,0)); | |||
add(new Res_PLCADDRESS("炒锅当前电压","VD312",1,0)); | |||
add(new Res_PLCADDRESS("炒锅当前电流","VD316",1,0)); | |||
add(new Res_PLCADDRESS("炒锅当前功率","VD320",1,0)); | |||
add(new Res_PLCADDRESS("搅拌频率","VW324",1,0)); | |||
add(new Res_PLCADDRESS("搅拌电机电流","VW326",1,0)); | |||
add(new Res_PLCADDRESS("搅拌电机电压","VW328",1,0)); | |||
add(new Res_PLCADDRESS("搅拌变频器温度","VW330",1,0)); | |||
add(new Res_PLCADDRESS("翻转频率","VW332",1,0)); | |||
add(new Res_PLCADDRESS("翻转电机电流","VW334",1,0)); | |||
add(new Res_PLCADDRESS("翻转电机电压","VW336",1,0)); | |||
add(new Res_PLCADDRESS("翻转变频器温度","VW338",1,0)); | |||
add(new Res_PLCADDRESS("编码器当前位值","VD340",1,0)); | |||
//状态上报 | |||
add(new Res_PLCADDRESS("状态上报","-------------",0,0)); | |||
add(new Res_PLCADDRESS("搅拌电机","VW350",1,0)); | |||
add(new Res_PLCADDRESS("翻转电机","VW352",1,0)); | |||
add(new Res_PLCADDRESS("炒锅","VW354",1,0)); | |||
}}; | |||
/** | |||
* 速度 | |||
*/ | |||
public ConcurrentHashMap<String,Integer> StirringSpeed=new ConcurrentHashMap<String,Integer>() | |||
{{ | |||
put("停止",0); | |||
put("最低",10); | |||
put("低速",20); | |||
put("中速",30); | |||
put("高速",40); | |||
put("最高",50); | |||
put("极高",60); | |||
}}; | |||
/** | |||
* 挡位 功率 | |||
*/ | |||
public ConcurrentHashMap<String,Integer> HeatingGear=new ConcurrentHashMap<String,Integer>() | |||
{{ | |||
put("停止",0); | |||
put("一档",2); | |||
put("二档",4); | |||
put("三档",6); | |||
put("四档",8); | |||
put("五档",10); | |||
}}; | |||
//endregion | |||
} | |||
@@ -46,12 +46,7 @@ public class DataBus { | |||
} | |||
//endregion | |||
//region 连接状态 | |||
/** | |||
* Plc是否连接 | |||
*/ | |||
public boolean PlcIsConnect=false; | |||
//endregion | |||
//region 跳转页面 | |||
@@ -2784,6 +2784,9 @@ public class QueryDB { | |||
((BPA_PLCADDRESS) data).name = cursor.getString((int) cursor.getColumnIndex("name")); | |||
((BPA_PLCADDRESS) data).address = cursor.getString((int) cursor.getColumnIndex("address")); | |||
((BPA_PLCADDRESS) data).sort = cursor.getInt((int) cursor.getColumnIndex("sort")); | |||
((BPA_PLCADDRESS) data).isread = cursor.getInt((int) cursor.getColumnIndex("isread")); | |||
((BPA_PLCADDRESS) data).iswrite = cursor.getInt((int) cursor.getColumnIndex("iswrite")); | |||
break; | |||
} | |||
((ModeBase) data).id = cursor.getString((int) cursor.getColumnIndex("id")); | |||
@@ -1,11 +1,14 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
import com.bonait.bnframework.common.model.AddrType; | |||
/** | |||
* PLC地址管理 | |||
*/ | |||
public class BPA_PLCADDRESS extends ModeBase{ | |||
public String name; | |||
public String address; | |||
public int isread;//是否可读 | |||
public int iswrite;//是否可写 | |||
public int sort; | |||
} |
@@ -0,0 +1,14 @@ | |||
package com.bonait.bnframework.common.db.mode; | |||
import com.bonait.bnframework.common.model.AddrType; | |||
public class Res_PLCADDRESS extends BPA_PLCADDRESS{ | |||
public Res_PLCADDRESS(String _name, String _address, int _isread, int _iswrite) | |||
{ | |||
this.name=_name; | |||
this.address=_address; | |||
this.isread=_isread; | |||
this.iswrite=_iswrite; | |||
} | |||
} |
@@ -1,6 +1,7 @@ | |||
package com.bonait.bnframework.common.modbus; | |||
import com.bonait.bnframework.business.ConfigData; | |||
import com.bonait.bnframework.common.constant.ConfigName; | |||
import com.bonait.bnframework.common.constant.DataBus; | |||
import com.bonait.bnframework.common.helper.DataFormat; | |||
@@ -190,12 +191,10 @@ public class ModbusTcpServer { | |||
.setRetries(0) | |||
.setEncapsulated(false) | |||
.setKeepAlive(true); | |||
while (DataBus.getInstance().PlcIsConnect==false) | |||
while (ConfigName.getInstance().PlcIsConnect==false) | |||
{ | |||
ConnectPLC(); | |||
Thread.sleep(5000); | |||
} | |||
} | |||
@@ -208,32 +207,15 @@ public class ModbusTcpServer { | |||
@Override | |||
public void onSuccess(ModbusMaster modbusMaster) { | |||
MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " 连接成功"); | |||
DataBus.getInstance().PlcIsConnect = true; | |||
//1.数据中心 | |||
// DeviceData.Get().Init(); | |||
// //2.业务线程 | |||
// BusinessServer.Get().Init(); | |||
// //3.设置自动模式 | |||
// DeviceData.Get().setHandOrAutoSwitch(true, null); | |||
// DeviceData.Get().setCleaningMode(false, null);//关闭自动清洗模式 | |||
// //4.启动设备服务 | |||
// DeviceServer.Get().Init(); | |||
// //5.启动日志服务 | |||
// LogServer.Get().Init(); | |||
// //6.云订单服务 | |||
// OrderServer.Get().Init(); | |||
// //7.加热服务 | |||
// ReheatServer.Get().Init(); | |||
// //8.扫码服务 | |||
// ScanCodeServer.Get().Init(); | |||
ConfigName.getInstance().PlcIsConnect = true; | |||
ConfigData.getInstance().PLC_Init(); | |||
} | |||
@Override | |||
public void onFailure(Throwable tr) { | |||
DataBus.getInstance().PlcIsConnect = false; | |||
ConfigName.getInstance().PlcIsConnect = false; | |||
MessageLog.ShowError("设备 " + ConfigName.getInstance().Address + " 连接失败:" + tr.getMessage()); | |||
} | |||
@Override | |||
public void onFinally() { | |||
@@ -0,0 +1,14 @@ | |||
package com.bonait.bnframework.common.model; | |||
/** | |||
* 地址类型 | |||
*/ | |||
public enum AddrType { | |||
_int,//VD150 | |||
_bool,//M10.0 | |||
_short,//VW100 | |||
} | |||
// String sState = AddrType._int.name();//enum转为String | |||
//callState = AddrType.valueOf(sState);//String转为enum |
@@ -51,6 +51,12 @@ public class BottomNavigation2Activity extends BaseActivity { | |||
Init(); | |||
} | |||
@Override | |||
protected void onDestroy() { | |||
ConfigData.getInstance().ColsePLC(); | |||
super.onDestroy(); | |||
} | |||
/** | |||
* viewPager里添加fragment | |||
*/ | |||
@@ -142,8 +148,14 @@ public class BottomNavigation2Activity extends BaseActivity { | |||
return super.onKeyDown(keyCode, event); | |||
} | |||
/** | |||
* 初始化 | |||
*/ | |||
public void Init() | |||
{ | |||
//判断连接环境 | |||
ConfigData.getInstance().ToggleEnvironment(); | |||
//2.初始化PLC | |||
ConfigData.getInstance().ConnectPLC(); | |||
} | |||
} |
@@ -173,6 +173,7 @@ public class Home1Fragment extends BaseFragment { | |||
*/ | |||
public void MakeThread() | |||
{ | |||
ExecuteTheRecipe.context=context; | |||
ThreadManager.Get().StartLong("商品制作线程-2023", true, new IThread() { | |||
@Override | |||
public void Run() throws InterruptedException { | |||
@@ -184,6 +185,7 @@ public class Home1Fragment extends BaseFragment { | |||
ArrayList<BPA_GOODSRECIPE> goodsrecipes = QueryDB.GetGoodsSrecipeID(good.id); | |||
for(BPA_GOODSRECIPE item:goodsrecipes) | |||
{ | |||
ExecuteTheRecipe.Execute(item); | |||
} | |||
}catch (Exception ex) | |||
@@ -3,8 +3,11 @@ package com.bonait.bnframework.modules.home.fragment.from.fragment; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import androidx.appcompat.app.AppCompatActivity; | |||
import androidx.recyclerview.widget.RecyclerView; | |||
import android.app.Activity; | |||
import android.content.Context; | |||
import android.content.ContextWrapper; | |||
import android.os.Bundle; | |||
import android.text.InputType; | |||
import android.view.LayoutInflater; | |||
@@ -19,6 +22,7 @@ import com.bonait.bnframework.common.constant.ConfigName; | |||
import com.bonait.bnframework.common.db.QueryDB; | |||
import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; | |||
import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; | |||
import com.bonait.bnframework.common.modbus.ModbusTcpServer; | |||
import com.bonait.bnframework.common.utils.AlertDialogUtils; | |||
import com.bonait.bnframework.common.utils.NetworkUtils; | |||
import com.bonait.bnframework.common.utils.ToastUtils; | |||
@@ -39,6 +43,7 @@ public class SystemCsPLCFragment extends BaseFragment { | |||
LinearLayout plcview;//工序子集 | |||
private Context context; | |||
@Override | |||
protected View onCreateView() { | |||
View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_system_cs_plc, null); | |||
@@ -57,14 +62,44 @@ public class SystemCsPLCFragment extends BaseFragment { | |||
/** | |||
* 初始化 | |||
*/ | |||
public void Init() | |||
{ | |||
public void Init() { | |||
plcview.removeAllViews(); | |||
ArrayList<BPA_PLCADDRESS> arrayList= QueryDB.GetPlcaddressALL(); | |||
for (BPA_PLCADDRESS item:arrayList) | |||
{ | |||
fragment_plc gongxu=new fragment_plc(this.context,null,item); | |||
plcview.addView(gongxu); | |||
ArrayList<BPA_PLCADDRESS> arrayList = QueryDB.GetPlcaddressALL(); | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
Activity activity = findActivity(context); | |||
if (activity != null) { | |||
activity.runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
for (BPA_PLCADDRESS item : arrayList) { | |||
fragment_plc gongxu = new fragment_plc(context, null, item); | |||
plcview.addView(gongxu); | |||
} | |||
} catch (Exception e) { | |||
} | |||
} | |||
}); | |||
} | |||
} catch (Exception e) { | |||
} | |||
} | |||
}).start(); | |||
} | |||
private Activity findActivity(@NonNull Context context) { | |||
if (context instanceof Activity) { | |||
return (Activity) context; | |||
} else if (context instanceof ContextWrapper) { | |||
return findActivity(((ContextWrapper) context).getBaseContext()); | |||
} else { | |||
return null; | |||
} | |||
} | |||
@@ -98,9 +133,9 @@ public class SystemCsPLCFragment extends BaseFragment { | |||
* 当在activity设置viewPager + BottomNavigation + fragment时, | |||
* 为防止viewPager左滑动切换界面,与fragment左滑返回上一界面冲突引起闪退问题, | |||
* 必须加上此方法,禁止fragment左滑返回上一界面。 | |||
* | |||
* <p> | |||
* 切记!切记!切记!否则会闪退! | |||
* | |||
* <p> | |||
* 当在fragment设置viewPager + BottomNavigation + fragment时,则不会出现这个问题。 | |||
*/ | |||
@Override | |||
@@ -42,6 +42,11 @@ public class fragment_plc extends LinearLayout { | |||
Button update_plc; | |||
@BindView(R.id.edittext_plc) | |||
EditText edittext_plc; | |||
@BindView(R.id.check_isread) | |||
CheckBox check_isread; | |||
@BindView(R.id.check_iswrite) | |||
CheckBox check_iswrite; | |||
private View root; | |||
public fragment_plc(Context context, @Nullable AttributeSet attrs,BPA_PLCADDRESS _model) { | |||
super(context, attrs); | |||
@@ -57,13 +62,16 @@ public class fragment_plc extends LinearLayout { | |||
name.setText("\n"+model.name+":"); | |||
edittext_plc.setVisibility(View.GONE); | |||
update_plc.setVisibility(View.GONE); | |||
check_isread.setVisibility(View.GONE); | |||
check_iswrite.setVisibility(View.GONE); | |||
}else | |||
{ | |||
name_PLC.setText(model.name); | |||
edittext_plc.setInputType(InputType.TYPE_CLASS_TEXT); | |||
edittext_plc.setText(model.address.toCharArray(), 0, model.address.length()); | |||
check_isread.setChecked(model.isread==1); | |||
check_iswrite.setChecked(model.iswrite==1); | |||
} | |||
} | |||
public BPA_PLCADDRESS model=null; | |||
@@ -84,6 +92,8 @@ public class fragment_plc extends LinearLayout { | |||
@Override | |||
public void onClick(QMUIDialog dialog, int index) { | |||
model.address=text; | |||
model.iswrite=check_iswrite.isChecked()?1:0; | |||
model.isread=check_isread.isChecked()?1:0; | |||
QueryDB.UpdatePlcaddress(model); | |||
ToastUtils.info("修改成功!"); | |||
dialog.dismiss(); | |||
@@ -8,7 +8,7 @@ | |||
android:layout_marginBottom="@dimen/dp_10" | |||
android:orientation="horizontal"> | |||
<RelativeLayout | |||
android:layout_width="160dp" | |||
android:layout_width="130dp" | |||
android:layout_height="match_parent"> | |||
<TextView | |||
android:id="@+id/name_PLC" | |||
@@ -46,16 +46,34 @@ | |||
android:layout_width="wrap_content" | |||
android:layout_alignParentRight="true" | |||
android:layout_height="match_parent"> | |||
<Button | |||
android:id="@+id/update_plc" | |||
android:layout_width="80dp" | |||
android:layout_height="26dp" | |||
android:layout_marginLeft="@dimen/dp_10" | |||
android:background="@drawable/button1" | |||
android:layout_centerInParent="true" | |||
<LinearLayout | |||
android:layout_width="wrap_content" | |||
android:layout_height="match_parent"> | |||
<CheckBox | |||
android:id="@+id/check_isread" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="监听" | |||
android:layout_marginRight="@dimen/dp_10" | |||
android:buttonTint="@color/radiusImageView_selected_mask_color"/> | |||
<CheckBox | |||
android:id="@+id/check_iswrite" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="可写" | |||
android:layout_marginRight="@dimen/dp_10" | |||
android:buttonTint="@color/radiusImageView_selected_mask_color"/> | |||
<Button | |||
android:id="@+id/update_plc" | |||
android:layout_width="80dp" | |||
android:layout_height="26dp" | |||
android:layout_marginRight="@dimen/dp_10" | |||
android:background="@drawable/button1" | |||
android:layout_centerInParent="true" | |||
android:text="修改" | |||
android:textSize="14dp" /> | |||
android:text="修改" | |||
android:textSize="14dp" /> | |||
</LinearLayout> | |||
</RelativeLayout> | |||
</LinearLayout> |