diff --git a/app/src/main/java/com/bonait/bnframework/business/ConfigData.java b/app/src/main/java/com/bonait/bnframework/business/ConfigData.java index 76c55051..af6eff6b 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ConfigData.java +++ b/app/src/main/java/com/bonait/bnframework/business/ConfigData.java @@ -248,15 +248,7 @@ public class ConfigData { ConfigName.getInstance().HuoLi = ConfigUtil.read(ConfigName.getInstance().dishesCon, "HuoLi", ConfigName.getInstance().HuoLi); ConfigName.getInstance().MaxTemp = ConfigUtil.read(ConfigName.getInstance().dishesCon, "MaxTemp", ConfigName.getInstance().MaxTemp); - ConfigName.getInstance().gkcxCount = ConfigUtil.read(ConfigName.getInstance().dishesCon, "gkcxCount", ConfigName.getInstance().gkcxCount); - ConfigName.getInstance().jiaobanCount = ConfigUtil.read(ConfigName.getInstance().dishesCon, "jiaobanCount", ConfigName.getInstance().jiaobanCount); - ConfigName.getInstance().qingxiCount = ConfigUtil.read(ConfigName.getInstance().dishesCon, "qingxiCount", ConfigName.getInstance().qingxiCount); - ConfigName.getInstance().touliaoCount = ConfigUtil.read(ConfigName.getInstance().dishesCon, "touliaoCount", ConfigName.getInstance().touliaoCount); - ConfigName.getInstance().yetiliaoCount = ConfigUtil.read(ConfigName.getInstance().dishesCon, "yetiliaoCount", ConfigName.getInstance().yetiliaoCount); - ConfigName.getInstance().yanchiCount = ConfigUtil.read(ConfigName.getInstance().dishesCon, "yanchiCount", ConfigName.getInstance().yanchiCount); - ConfigName.getInstance().jiareCount = ConfigUtil.read(ConfigName.getInstance().dishesCon, "jiareCount", ConfigName.getInstance().jiareCount); - ConfigName.getInstance().jiarewendingCount = ConfigUtil.read(ConfigName.getInstance().dishesCon, "jiarewendingCount", ConfigName.getInstance().jiarewendingCount); - ConfigName.getInstance().RunCount = ConfigUtil.read(ConfigName.getInstance().dishesCon, "RunCount", ConfigName.getInstance().RunCount); + } @@ -275,15 +267,6 @@ public class ConfigData { ConfigUtil.write(ConfigName.getInstance().dishesCon, "HuoLi", ConfigName.getInstance().HuoLi); ConfigUtil.write(ConfigName.getInstance().dishesCon, "MaxTemp", ConfigName.getInstance().MaxTemp); - ConfigUtil.write(ConfigName.getInstance().dishesCon, "gkcxCount", ConfigName.getInstance().gkcxCount); - ConfigUtil.write(ConfigName.getInstance().dishesCon, "jiaobanCount", ConfigName.getInstance().jiaobanCount); - ConfigUtil.write(ConfigName.getInstance().dishesCon, "qingxiCount", ConfigName.getInstance().qingxiCount); - ConfigUtil.write(ConfigName.getInstance().dishesCon, "touliaoCount", ConfigName.getInstance().touliaoCount); - ConfigUtil.write(ConfigName.getInstance().dishesCon, "yetiliaoCount", ConfigName.getInstance().yetiliaoCount); - ConfigUtil.write(ConfigName.getInstance().dishesCon, "yanchiCount", ConfigName.getInstance().yanchiCount); - ConfigUtil.write(ConfigName.getInstance().dishesCon, "jiareCount", ConfigName.getInstance().jiareCount); - ConfigUtil.write(ConfigName.getInstance().dishesCon, "jiarewendingCount", ConfigName.getInstance().jiarewendingCount); - ConfigUtil.write(ConfigName.getInstance().dishesCon, "RunCount", ConfigName.getInstance().RunCount); } diff --git a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java index 0a253ec0..20b0ef2c 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java +++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java @@ -56,9 +56,13 @@ public class ExecuteTheRecipe { */ public static boolean IsStart = false; /** - * 是否暂停 + * 通知手动暂停 */ - public static boolean IsPause = false; + public static IRunT NoticeHandSuspension = null; + /** + * 手动操作耗时时长 + */ + public static int HandTime = 0; //endregion //region 强制结束 @@ -240,11 +244,11 @@ public class ExecuteTheRecipe { int otherG = silos.silosmargin - (val / 10); QueryDB.UpdateYL(silos.id, otherG >= 0 ? otherG : 0); - - WritePLC(name, true); //开始出料 + //开始出料 + WritePLC(name, true); //等待出料完成,false信号 - ThreadWhileFlase(name); + ThreadWhileMaterialOver(name); } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); } @@ -260,6 +264,11 @@ public class ExecuteTheRecipe { */ private static void Write_PLC_Ingredients(HashMap data) { try { + long startTime = System.currentTimeMillis(); //起始时间 + if (NoticeHandSuspension != null) { + NoticeHandSuspension.Run(true); + } + String name = ""; for (HashMap.Entry entry : data.entrySet()) { String key = entry.getKey(); @@ -280,7 +289,7 @@ public class ExecuteTheRecipe { @Override public void run() { try { - new QMUIDialog.MessageDialogBuilder(context).setCancelable(false).setTitle(title).setMessage(message).addAction("确定", new QMUIDialogAction.ActionListener() { + new QMUIDialog.MessageDialogBuilder(context).setCancelable(false).setCanceledOnTouchOutside(false).setTitle(title).setMessage(message).addAction("确定", new QMUIDialogAction.ActionListener() { @Override public void onClick(QMUIDialog dialog, int index) { IsComplete[0] = true; @@ -298,6 +307,13 @@ public class ExecuteTheRecipe { Thread.sleep(100);//10 *6 } + long endTime = System.currentTimeMillis(); //结束时间 + int time = (int) ((endTime - startTime) / 1000); + HandTime = HandTime + time; + if (NoticeHandSuspension != null) { + NoticeHandSuspension.Run(false); + } + ExecuteTheRecipe.showlog("手动已确认投入主料:" + name + "-继续流程"); } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); @@ -488,6 +504,7 @@ public class ExecuteTheRecipe { //endregion //region 界面事件 + /** * 阻断按钮 * @@ -497,7 +514,7 @@ public class ExecuteTheRecipe { try { Log.e("按钮按下", name); WritePLC(name, true); - Thread.sleep(200); + Thread.sleep(100); WritePLC(name, false); Log.e("按钮复位", name); ExecuteTheRecipe.showlog("写入plc-------" + name); @@ -509,6 +526,7 @@ public class ExecuteTheRecipe { /** * 发现主窗体 + * * @param context * @return */ @@ -524,6 +542,7 @@ public class ExecuteTheRecipe { //endregion //region 延迟函数 + /** * 线程延迟函数(避免线程阻塞等待) * @@ -533,8 +552,7 @@ public class ExecuteTheRecipe { ExecuteTheRecipe.showlog("工序线程等待-------时长:" + delay + "秒,请耐心等待,开始计时!"); long startTime = System.currentTimeMillis(); - while ((System.currentTimeMillis() - startTime) <= (delay * 1000) && !IsForcedEnd) - { + while ((System.currentTimeMillis() - startTime) <= (delay * 1000) && !IsForcedEnd) { try { Thread.sleep(100); } catch (InterruptedException ex) { @@ -564,8 +582,7 @@ public class ExecuteTheRecipe { Object sb = ReadPLC(name); if (sb != null) { IsComplete[0] = (boolean) (sb); - if(IsComplete[0]) - { + if (IsComplete[0]) { ExecuteTheRecipe.showlog(name + ",接收到信号!"); } } @@ -585,7 +602,7 @@ public class ExecuteTheRecipe { * * @param name */ - public static void ThreadWhileFlase(String name) { + public static void ThreadWhileMaterialOver(String name) { //"炒菜位1反馈"; final boolean[] IsComplete = {true}; long a = System.currentTimeMillis(); @@ -598,8 +615,7 @@ public class ExecuteTheRecipe { Object sb = ReadPLC(name); if (sb != null) { IsComplete[0] = (boolean) (sb); - if(IsComplete[0]==false) - { + if (IsComplete[0] == false) { ExecuteTheRecipe.showlog(name + ",接收到信号!"); } } @@ -800,6 +816,7 @@ public class ExecuteTheRecipe { * 显示日志 */ public static void showlog(String msg) { + msg=ConfigName.getInstance().user.name+"_"+msg; Log.e("hbl", msg); ToastUtils.info(msg); } @@ -819,6 +836,7 @@ public class ExecuteTheRecipe { BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); if (!plcaddress.address.isEmpty() && ConfigName.getInstance().PlcIsConnect) { SiemensHelper1.get().writePLC(plcaddress.address, value); + showlog(name+"_写入值_"+value); } } } catch (Exception ex) { diff --git a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java index bb55d442..a1a031ef 100644 --- a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java +++ b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java @@ -447,44 +447,4 @@ public class ConfigName { add("超级管理员"); }}; //endregion - - //region 计数累计 - /** - * 锅口朝向次数 - */ - public int gkcxCount=0; - /** - * 搅拌分钟数 - */ - public int jiaobanCount = 0;//搅拌分钟数 - /** - * 清洗次数 - */ - public int qingxiCount = 0; - /** - * 投料次数 - */ - public int touliaoCount = 0; - /** - * 液体料次数 - */ - public int yetiliaoCount = 0; - - /** - * 延迟加热次数 - */ - public int yanchiCount = 0; - /** - * 加热次数 - */ - public int jiareCount = 0; - /** - * 加热稳定性次数 - */ - public int jiarewendingCount = 0; - /** - * 炒菜运行 - */ - public int RunCount = 0; - //endregion } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java index c42a4a14..4b28af5e 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java @@ -11,10 +11,15 @@ import android.content.Context; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.EditText; import android.widget.ImageView; import android.widget.RelativeLayout; +import android.widget.Spinner; import android.widget.TextView; import com.bonait.bnframework.R; @@ -26,9 +31,12 @@ import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; +import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.res.StatusMode; import com.bonait.bnframework.common.db.res.lcMode; import com.bonait.bnframework.common.helper.CountDownTimerExt; +import com.bonait.bnframework.common.helper.I.IRunT; +import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.image.MyBitmapUtils; import com.bonait.bnframework.common.message.MessageLooper; @@ -43,6 +51,7 @@ import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; import com.qmuiteam.qmui.widget.textview.QMUILinkTextView; +import com.suke.widget.SwitchButton; import java.util.ArrayList; import java.util.List; @@ -88,6 +97,8 @@ public class MakeGoodFragment extends BaseFragment { @BindView(R.id.dialog_jykz) RelativeLayout dialog_jykz; + @BindView(R.id.gongxumiaoshu) + TextView gongxumiaoshu;//工序描述 /** * 当前制作商品信息 @@ -116,7 +127,8 @@ public class MakeGoodFragment extends BaseFragment { context = getContext(); initTopBar(); Initdata(); - StatusThread(); + StatusOrMakeGoodThread(); + Init_弹窗(); } /** @@ -125,9 +137,21 @@ public class MakeGoodFragment extends BaseFragment { private void initTopBar() { mTopBar.setTitle("菠萝燃气炒菜系统" + ConfigName.getInstance().Version); } + + /** + * 设置下拉框 + * + * @param spinner + * @param map + */ + private void SetAdapter(Spinner spinner, List map) { + ArrayAdapter adapter = new ArrayAdapter<>(getContext(), R.layout.spinner_text_item, map); + adapter.setDropDownViewResource(R.layout.spinner_dropdown_item); + spinner.setAdapter(adapter); + } //endregion - //region 私有函数 + //region 点击事件处理 /** * 点击事件 @@ -138,9 +162,19 @@ public class MakeGoodFragment extends BaseFragment { , R.id.btn_xtkz, R.id.btn_hlkz , R.id.btn_sjkz, R.id.btn_jykz , R.id.close_xtkz, R.id.close_hlkz - , R.id.close_kbkz, R.id.close_jykz}) + , R.id.close_kbkz, R.id.close_jykz + + + , R.id.button_搅拌点动 + , R.id.button_搅拌上升, R.id.button_搅拌下降 + , R.id.button_锅前倾, R.id.button_锅后仰 + + , R.id.button_出料 + , R.id.button_点火复位 + }) public void onViewClicked(View view) { switch (view.getId()) { + //region 界面的操作 case R.id.xzcp://选择菜谱按钮点击 skipToActivity(CpxzActivity.class); ToastUtils.info("打开菜谱选择界面"); @@ -199,254 +233,188 @@ public class MakeGoodFragment extends BaseFragment { }); } break; - } - } - //endregion + //endregion - //region 公共函数 + //region PLC操作 - /** - * 初始化数据 - */ - public void Initdata() { - //1.初始化状态数据 - InitStatusdata(); - //2. - SetProcesssUI(0); - startbutton.setText("开始烹饪"); - startbutton.setBackgroundResource(R.drawable.bg_btn_login_selected); - SetVisibility(0); - //3.接收选择菜谱事件 - DataBus.getInstance().mListener = new MyClickListener() { - @Override - public void clickListener(View v, Object data) { + case R.id.button_搅拌上升: + ExecuteTheRecipe.BottomClick("搅拌上升"); + break; + case R.id.button_搅拌下降: + ExecuteTheRecipe.BottomClick("搅拌下降"); + break; + case R.id.button_锅前倾: + ExecuteTheRecipe.BottomClick("锅口向前"); + break; + case R.id.button_锅后仰: + ExecuteTheRecipe.BottomClick("锅口向后"); + break; - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { -// if (!IsMake(true)) { -// return; -// } - good = (BPA_GOODS) data; - SetProcesssUI(0); - } - }); - } + case R.id.button_出料: + String s1 = edit_设定重量.getText().toString(); + String s2 = edit_提前量.getText().toString(); + if (s1.isEmpty()) { + ToastUtils.warning("设定重量不能为空!"); + return; + } + if (s2.isEmpty()) { + ToastUtils.warning("提前量不能为空!"); + return; + } + int s1_1 = 0; + int s2_1 = 0; + try { + s1_1 = Integer.parseInt(s1); + s2_1 = Integer.parseInt(s2); + } catch (Exception ex) { + ToastUtils.warning("数据解析异常!" + ex.getMessage()); + return; + } + ExecuteTheRecipe.WritePLC("设定重量", s1_1); + ExecuteTheRecipe.WritePLC("设定提前量", s2_1); + ExecuteTheRecipe.WritePLC("设定提前量", s2_1); + ExecuteTheRecipe.WritePLC("料仓1出料", true); + break; - @Override - public void clickListenerNew(View v, int k, Object data) { + case R.id.button_点火复位: + ExecuteTheRecipe.BottomClick("点火复位开关"); + break; - } - }; + //endregion + } } /** - * 状态线程 + * 开关事件处理 */ - public void StatusThread() { - //商品制作线程 - new Thread(new Runnable() { - @Override - public void run() { - while (true) { - try { - - if (ExecuteTheRecipe.IsStart && good != null) { - long startTime = System.currentTimeMillis(); //起始时间 - ExecuteTheRecipe.showlog("--------------------------------------"); - ExecuteTheRecipe.showlog("开始烹饪菜谱【" + good.name + "】"); - - try { - //获取工艺 - ArrayList goodsrecipes = QueryDB.GetGoodsSrecipeID(good.id); - for (BPA_GOODSRECIPE item : goodsrecipes) { - ExecuteTheRecipe.Execute(item); - } - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } finally { - long endTime = System.currentTimeMillis(); //结束时间 - int time = (int) ((endTime - startTime) / 1000); - - ExecuteTheRecipe.showlog("结束烹饪菜谱【" + good.name + "】,关闭搅拌、关闭加热," + String.format("方法使用时间 %d s", time)); - - if (!ExecuteTheRecipe.IsForcedEnd) { - QueryDB.UpdateGoodsMakeTime(good.id, time); - } + public SwitchButton.OnCheckedChangeListener checkedChangeListener = new SwitchButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(SwitchButton view, boolean isChecked) { + switch (view.getId()) { + case R.id.switch_系统启停: + ExecuteTheRecipe.WritePLC("系统启停开关", isChecked); + break; + case R.id.switch_超温停气: + ExecuteTheRecipe.WritePLC("超温停气开关", isChecked); + break; + case R.id.switch_搅拌控制: + if (isChecked) { + ExecuteTheRecipe.BottomClick("搅拌启动开关"); + } else { + ExecuteTheRecipe.BottomClick("搅拌停止开关"); + } + break; + case R.id.switch_抽油启停: + ExecuteTheRecipe.WritePLC("料仓1出料", isChecked); + break; + case R.id.switch_备用气缸: + ExecuteTheRecipe.WritePLC("料仓2出料", isChecked); + break; + case R.id.switch_点火控制: + ExecuteTheRecipe.WritePLC("点火启动开关", isChecked); + break; - Activity activity = getActivity(); - if (activity != null) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - onRecordStop(); - if (ExecuteTheRecipe.IsForcedEnd)//强制结束 - { - ExecuteTheRecipe.showlog("菜谱【" + good.name + "】已强制结束..."); - ExecuteTheRecipe.StopForcedEnd();//设置恢复强制结束 - } - } - }); - } - ExecuteTheRecipe.showlog("--------------------------------------"); - } - } - Thread.sleep(1000); - } catch (InterruptedException e) { + } + } + }; + + public View.OnTouchListener touchListener=new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + boolean IsChick=false; + if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { + Log.e("鼠标", "按下: "); + IsChick=true; + } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { + Log.e("鼠标", "松开: "); + IsChick=false; + } - } - } + switch (view.getId()) { + case R.id.button_搅拌点动: + ExecuteTheRecipe.WritePLC("搅拌点动开关",IsChick); + break; } - }).start(); + return false; + } + }; + //endregion + //region 计时器 + private CountDownTimerExt countDownTimer = null;//计时器 - //刷新UI监控 - new Thread(new Runnable() { + /** + * 启动 + */ + public void onRecordStart() { + getActivity().runOnUiThread(new Runnable() { @Override public void run() { - while (true) { - try { - if (ConfigName.getInstance().PlcIsConnect) { - for (StatusMode mode : sbzt) { - Object obj = ExecuteTheRecipe.ReadPLC(mode.YName); - if (obj != null) { - mode.Status = (boolean) obj; - } + if (good != null) { + startbutton.setText("强制结束"); + startbutton.setBackgroundResource(R.drawable.bg_btn_login_red); + xzcp.setVisibility(View.INVISIBLE); + + int time = good.maketime; + SetProcesssUI(0); + if (countDownTimer == null) { + countDownTimer = new CountDownTimerExt(time * 1000, 1000) { + @Override + public void onTimerTick(long value) { + int overtime = (int) ((value) / 1000);//剩余时间 + SetProcesssUI(time - overtime); } - for (StatusMode mode : gzzt) { - Object obj = ExecuteTheRecipe.ReadPLC(mode.YName); - if (obj != null) { - mode.Status = (boolean) obj; - } + @Override + public void onTimerFinish() { + SetProcesssUI(time); } - - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - ReshData(); - } - }); - } - - Thread.sleep(1000); - } catch (InterruptedException e) { - ToastUtils.info("异常信息:" + e.getMessage()); + }; } + countDownTimer.start(); + ExecuteTheRecipe.IsStart = true; } } - }).start(); + }); } - //endregion - - //region 设备监控状态 - /** - * 设备状态 - */ - public List sbzt = new ArrayList<>(); - public devicestatus_adapter adapter_sbzt = null; /** - * 故障状态 - */ - public List gzzt = new ArrayList<>(); - public devicestatus_adapter adapter_gzzt = null; - - /** - * 初始化数据 + * 停止 */ - public void InitStatusdata() { - sbzt.clear(); - sbzt.add(new StatusMode("急停按钮", "监控_急停按钮", false, R.mipmap.status_y, R.mipmap.status_z, 0)); - sbzt.add(new StatusMode("搅拌上限", "监控_搅拌上限", false, R.mipmap.status_y, R.mipmap.status_z, 0)); - sbzt.add(new StatusMode("搅拌下限", "监控_搅拌下限", false, R.mipmap.status_y, R.mipmap.status_z, 0)); - sbzt.add(new StatusMode("锅后限位", "监控_锅后限位", false, R.mipmap.status_y, R.mipmap.status_z, 0)); - sbzt.add(new StatusMode("搅拌原点", "监控_搅拌原点", false, R.mipmap.status_y, R.mipmap.status_z, 0)); - sbzt.add(new StatusMode("点火正常", "监控_点火正常", false, R.mipmap.status_y, R.mipmap.status_z, 0)); - - - gzzt.clear(); - gzzt.add(new StatusMode("急停按下", "急停按下!", false, R.mipmap.status_y, R.mipmap.status_z, 0)); - gzzt.add(new StatusMode("油泵故障", "油泵故障!", false, R.mipmap.status_y, R.mipmap.status_z, 0)); - gzzt.add(new StatusMode("搅拌故障", "搅拌故障!", false, R.mipmap.status_y, R.mipmap.status_z, 0)); - gzzt.add(new StatusMode("点火异常", "点火异常!", false, R.mipmap.status_y, R.mipmap.status_z, 0)); - gzzt.add(new StatusMode("高温报警", "高温报警!", false, R.mipmap.status_y, R.mipmap.status_z, 0)); - gzzt.add(new StatusMode("备用故障1", "备用故障1", false, R.mipmap.status_y, R.mipmap.status_z, 0)); - - StaggeredGridLayoutManager layout = new StaggeredGridLayoutManager - (3, StaggeredGridLayoutManager.VERTICAL); - recycler_view_sbzt.setLayoutManager(layout); - adapter_sbzt = new devicestatus_adapter(getContext(), sbzt); - recycler_view_sbzt.setAdapter(adapter_sbzt); + public void onRecordStop() { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + if (good != null) { + startbutton.setText("开始烹饪"); + startbutton.setBackgroundResource(R.drawable.bg_btn_login_selected); + xzcp.setVisibility(View.VISIBLE); + SetProcesssUI(0); - StaggeredGridLayoutManager layout1 = new StaggeredGridLayoutManager - (3, StaggeredGridLayoutManager.VERTICAL); - recycler_view_gzzt.setLayoutManager(layout1); - adapter_gzzt = new devicestatus_adapter(getContext(), gzzt); - recycler_view_gzzt.setAdapter(adapter_gzzt); - } + if (countDownTimer != null) { + countDownTimer.stop(); + countDownTimer = null; + } + ExecuteTheRecipe.IsStart = false; + } + } + }); - /** - * 刷新数据 - */ - public void ReshData() { - adapter_sbzt.refresh(); - adapter_gzzt.refresh(); } - //endregion - - //region 计时器 - private CountDownTimerExt countDownTimer = null;//计时器 /** - * 启动 + * 暂停 */ - public void onRecordStart() { - if (good != null) { - startbutton.setText("强制结束"); - startbutton.setBackgroundResource(R.drawable.bg_btn_login_red); - xzcp.setVisibility(View.INVISIBLE); - - int time = good.maketime; - SetProcesssUI(0); - if (countDownTimer == null) { - countDownTimer = new CountDownTimerExt(time * 1000, 1000) { - @Override - public void onTimerTick(long value) { - int overtime = (int) ((value) / 1000);//剩余时间 - SetProcesssUI(time - overtime); - } - - @Override - public void onTimerFinish() { - SetProcesssUI(time); - } - }; - } - countDownTimer.start(); - ExecuteTheRecipe.IsStart = true; - } + public void onRecordPause() { + countDownTimer.pause(); } /** - * 停止 + * 继续 */ - public void onRecordStop() { - if (good != null) { - startbutton.setText("开始烹饪"); - startbutton.setBackgroundResource(R.drawable.bg_btn_login_selected); - xzcp.setVisibility(View.VISIBLE); - - SetProcesssUI(0); - - if (countDownTimer != null) { - countDownTimer.stop(); - countDownTimer = null; - } - - ExecuteTheRecipe.IsStart = false; - } + public void onRecordPauseStart() { + countDownTimer.resume(); } //endregion @@ -565,5 +533,345 @@ public class MakeGoodFragment extends BaseFragment { } } + + /** + * 设置工序描述 + * + * @param text + */ + public void SetProcessDescription(String text) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + gongxumiaoshu.setText(text + ""); + } + }); + } + //endregion + + //region 设备监控状态 + /** + * 设备状态 + */ + public List sbzt = new ArrayList<>(); + public devicestatus_adapter adapter_sbzt = null; + /** + * 故障状态 + */ + public List gzzt = new ArrayList<>(); + public devicestatus_adapter adapter_gzzt = null; + + /** + * 初始化数据 + */ + public void InitStatusdata() { + sbzt.clear(); + sbzt.add(new StatusMode("急停按钮", "监控_急停按钮", false, R.mipmap.status_y, R.mipmap.status_z, 0)); + sbzt.add(new StatusMode("搅拌上限", "监控_搅拌上限", false, R.mipmap.status_y, R.mipmap.status_z, 0)); + sbzt.add(new StatusMode("搅拌下限", "监控_搅拌下限", false, R.mipmap.status_y, R.mipmap.status_z, 0)); + sbzt.add(new StatusMode("锅后限位", "监控_锅后限位", false, R.mipmap.status_y, R.mipmap.status_z, 0)); + sbzt.add(new StatusMode("搅拌原点", "监控_搅拌原点", false, R.mipmap.status_y, R.mipmap.status_z, 0)); + sbzt.add(new StatusMode("点火正常", "监控_点火正常", false, R.mipmap.status_y, R.mipmap.status_z, 0)); + + + gzzt.clear(); + gzzt.add(new StatusMode("急停按下", "急停按下!", false, R.mipmap.status_y, R.mipmap.status_z, 0)); + gzzt.add(new StatusMode("油泵故障", "油泵故障!", false, R.mipmap.status_y, R.mipmap.status_z, 0)); + gzzt.add(new StatusMode("搅拌故障", "搅拌故障!", false, R.mipmap.status_y, R.mipmap.status_z, 0)); + gzzt.add(new StatusMode("点火异常", "点火异常!", false, R.mipmap.status_y, R.mipmap.status_z, 0)); + gzzt.add(new StatusMode("高温报警", "高温报警!", false, R.mipmap.status_y, R.mipmap.status_z, 0)); + gzzt.add(new StatusMode("备用故障1", "备用故障1", false, R.mipmap.status_y, R.mipmap.status_z, 0)); + + StaggeredGridLayoutManager layout = new StaggeredGridLayoutManager + (3, StaggeredGridLayoutManager.VERTICAL); + recycler_view_sbzt.setLayoutManager(layout); + adapter_sbzt = new devicestatus_adapter(getContext(), sbzt); + recycler_view_sbzt.setAdapter(adapter_sbzt); + + + StaggeredGridLayoutManager layout1 = new StaggeredGridLayoutManager + (3, StaggeredGridLayoutManager.VERTICAL); + recycler_view_gzzt.setLayoutManager(layout1); + adapter_gzzt = new devicestatus_adapter(getContext(), gzzt); + recycler_view_gzzt.setAdapter(adapter_gzzt); + } + + /** + * 刷新数据 + */ + public void ReshData() { + adapter_sbzt.refresh(); + adapter_gzzt.refresh(); + } + //endregion + + //region 公共函数 + + /** + * 初始化数据 + */ + public void Initdata() { + //1.初始化状态数据 + InitStatusdata(); + //2. + SetProcesssUI(0); + startbutton.setText("开始烹饪"); + startbutton.setBackgroundResource(R.drawable.bg_btn_login_selected); + SetVisibility(0); + SetProcessDescription("等待开始..."); + //3.接收选择菜谱事件 + DataBus.getInstance().mListener = new MyClickListener() { + @Override + public void clickListener(View v, Object data) { + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { +// if (!IsMake(true)) { +// return; +// } + SetProcessDescription("等待开始..."); + good = (BPA_GOODS) data; + SetProcesssUI(0); + } + }); + } + + @Override + public void clickListenerNew(View v, int k, Object data) { + + } + }; + } + //endregion + + //region 状态显示或商品制作线程 + + /** + * 线程 + */ + public void StatusOrMakeGoodThread() { + ExecuteTheRecipe.context = getContext(); + //商品制作线程 + new Thread(new Runnable() { + @Override + public void run() { + while (true) { + try { + + if (ExecuteTheRecipe.IsStart && good != null) { + long startTime = System.currentTimeMillis(); //起始时间 + ExecuteTheRecipe.showlog("--------------------------------------"); + ExecuteTheRecipe.showlog("开始烹饪菜谱【" + good.name + "】"); + ExecuteTheRecipe.HandTime = 0;//默认将手动操作时间复位 + try { + //获取工艺 + ArrayList goodsrecipes = QueryDB.GetGoodsSrecipeID(good.id); + for (BPA_GOODSRECIPE item : goodsrecipes) { + SetProcessDescription("正在执行:" + item.processms); + ExecuteTheRecipe.Execute(item); + } + } catch (Exception ex) { + ToastUtils.error("异常信息:" + ex.getMessage()); + } finally { + int time = (int) ((System.currentTimeMillis() - startTime) / 1000);//使用总时间 + ExecuteTheRecipe.showlog("结束烹饪菜谱【" + good.name + "】," + String.format("方法使用时间 %d s", time)); + if (!ExecuteTheRecipe.IsForcedEnd) //不是强制结束,从写炒制时间 + { + int ztime = time - ExecuteTheRecipe.HandTime; + good.maketime = ztime > 0 ? ztime : time; + QueryDB.UpdateGoodsMakeTime(good.id, good.maketime); + } else { + ExecuteTheRecipe.showlog("菜谱【" + good.name + "】已强制结束..."); + } + + onRecordStop(); + ExecuteTheRecipe.StopForcedEnd();//设置恢复强制结束 + ExecuteTheRecipe.showlog("--------------------------------------"); + } + } + Thread.sleep(1000); + } catch (InterruptedException e) { + + } + } + } + }).start(); + + + //刷新UI监控 + new Thread(new Runnable() { + @Override + public void run() { + while (true) { + try { + if (ConfigName.getInstance().PlcIsConnect) { + for (StatusMode mode : sbzt) { + Object obj = ExecuteTheRecipe.ReadPLC(mode.YName); + if (obj != null) { + mode.Status = (boolean) obj; + } + } + + for (StatusMode mode : gzzt) { + Object obj = ExecuteTheRecipe.ReadPLC(mode.YName); + if (obj != null) { + mode.Status = (boolean) obj; + } + } + + //读取锅体重量 + Object zl = ExecuteTheRecipe.ReadPLC("炒锅当前重量"); + if (zl != null) { + PanWeight.setText(zl + ""); + } + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + ReshData(); + } + }); + } + + Thread.sleep(1000); + } catch (InterruptedException e) { + ToastUtils.info("异常信息:" + e.getMessage()); + } + } + } + }).start(); + + //接收暂停计时器 + ExecuteTheRecipe.NoticeHandSuspension = new IRunT() { + @Override + public void Run(Object o) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + if ((boolean) o) { + onRecordPause(); + } else { + onRecordPauseStart(); + } + } + }); + } + }; + } + //endregion + + //region 弹窗处理 + @BindView(R.id.switch_系统启停) + SwitchButton switch_系统启停; + + @BindView(R.id.switch_超温停气) + SwitchButton switch_超温停气; + + @BindView(R.id.switch_搅拌控制) + SwitchButton switch_搅拌控制; + + @BindView(R.id.switch_抽油启停) + SwitchButton switch_抽油启停; + + @BindView(R.id.switch_备用气缸) + SwitchButton switch_备用气缸; + + @BindView(R.id.editsp_物料) + Spinner editsp_物料; + + @BindView(R.id.editsp_点火模式) + Spinner editsp_点火模式; + + @BindView(R.id.switch_点火控制) + SwitchButton switch_点火控制; + + + @BindView(R.id.button_搅拌点动) + EditText button_搅拌点动;//button_搅拌点动 + + @BindView(R.id.image_搅拌上升) + ImageView image_搅拌上升; + + @BindView(R.id.button_搅拌下降) + ImageView button_搅拌下降; + + @BindView(R.id.image_锅前倾) + ImageView image_锅前倾; + + @BindView(R.id.image_锅后仰) + ImageView image_锅后仰; + /** + * 初始化弹窗 + */ + public void Init_弹窗() { + Init_弹窗_事件(); + Init_弹窗_物料(); + } + + /** + * 初始化弹框中的事件 + */ + public void Init_弹窗_事件() { + switch_系统启停.setOnCheckedChangeListener(checkedChangeListener); + switch_超温停气.setOnCheckedChangeListener(checkedChangeListener); + switch_搅拌控制.setOnCheckedChangeListener(checkedChangeListener); + + switch_抽油启停.setOnCheckedChangeListener(checkedChangeListener); + switch_备用气缸.setOnCheckedChangeListener(checkedChangeListener); + + switch_点火控制.setOnCheckedChangeListener(checkedChangeListener); + editsp_点火模式.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + String name =editsp_点火模式.getSelectedItem().toString(); + if(name.equals("手动")) + { + ExecuteTheRecipe.WritePLC("点火手自动切换开关",true); + }else + { + ExecuteTheRecipe.WritePLC("点火手自动切换开关",false); + } + } + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + + + button_搅拌点动.setOnTouchListener(touchListener); + } + + + @BindView(R.id.PanWeight) + TextView PanWeight;//锅体的重量 + + @BindView(R.id.edit_设定重量) + EditText edit_设定重量;//设定重量 + + @BindView(R.id.edit_提前量) + EditText edit_提前量;//提前量 + public ArrayList materials = new ArrayList<>(); + public List names = new ArrayList<>(); + + /** + * 初始化物料 + */ + public void Init_弹窗_物料() { + materials.clear(); + names.clear(); + List bpa_materials = QueryDB.GetMaterialALL(); + for (BPA_MATERIAL item : bpa_materials) { + materials.add(item); + names.add(item.name); + } + SetAdapter(editsp_物料, names); + + List ms = new ArrayList<>(); + ms.add("手动"); + ms.add("自动"); + SetAdapter(editsp_点火模式, ms); + } //endregion } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_make_good.xml b/app/src/main/res/layout/fragment_make_good.xml index b92b194b..093ad125 100644 --- a/app/src/main/res/layout/fragment_make_good.xml +++ b/app/src/main/res/layout/fragment_make_good.xml @@ -251,15 +251,18 @@ - + android:layout_height="wrap_content"> + +