# Conflicts: # app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java # app/src/main/java/com/bonait/bnframework/business/MainInit.java # app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java # app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java # app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java # app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DzcjyActivity.java # app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.javaNewNaiChaPeiLiaoBaTai
@@ -0,0 +1,4 @@ | |||
<changelist name="Uncommitted_changes_before_Checkout_at_2023_12_4_14_14_[Changes]" date="1701670451875" recycled="true" deleted="true"> | |||
<option name="PATH" value="$PROJECT_DIR$/.idea/shelf/Uncommitted_changes_before_Checkout_at_2023_12_4_14_14_[Changes]/shelved.patch" /> | |||
<option name="DESCRIPTION" value="Uncommitted changes before Checkout at 2023/12/4 14:14 [Changes]" /> | |||
</changelist> |
@@ -165,4 +165,7 @@ dependencies { | |||
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4' | |||
implementation 'com.contrarywind:Android-PickerView:3.2.6' | |||
//曲线拟合方程式。 | |||
implementation 'org.apache.commons:commons-math3:3.6.1' | |||
} |
@@ -1,43 +1,70 @@ | |||
package com.bonait.bnframework.business; | |||
import android.app.Activity; | |||
import android.content.Context; | |||
import android.content.ContextWrapper; | |||
import android.media.MediaPlayer; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import android.util.Log; | |||
import androidx.annotation.NonNull; | |||
import com.bonait.bnframework.R; | |||
import com.bonait.bnframework.common.constant.ConfigName; | |||
import com.bonait.bnframework.common.constant.DataBus; | |||
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.db.res.AlertLogEnum; | |||
import com.bonait.bnframework.common.db.res.ResGoodsMake; | |||
import com.bonait.bnframework.common.db.res.ResGoodsRecipe; | |||
import com.bonait.bnframework.common.db.res.SilosLsjyMode; | |||
import com.bonait.bnframework.common.db.res.UserLogEnum; | |||
import com.bonait.bnframework.common.helper.ByteHelper; | |||
import com.bonait.bnframework.common.helper.DataFormat; | |||
import com.bonait.bnframework.common.helper.I.IReadCallBack; | |||
import com.bonait.bnframework.common.helper.I.IRun; | |||
import com.bonait.bnframework.common.helper.I.IRunT; | |||
import com.bonait.bnframework.common.helper.I.IThread; | |||
import com.bonait.bnframework.common.helper.I.IWriteCallBack; | |||
import com.bonait.bnframework.common.helper.MediaPlayerHelper; | |||
import com.bonait.bnframework.common.helper.MessageLog; | |||
import com.bonait.bnframework.common.helper.RTrig; | |||
import com.bonait.bnframework.common.helper.ThreadManager; | |||
import com.bonait.bnframework.common.modbus.ModbusClient; | |||
import com.bonait.bnframework.common.modbus.ModbusMaster; | |||
import com.bonait.bnframework.common.modbus.ModbusTcpServer; | |||
import com.bonait.bnframework.common.utils.AlertDialogUtils; | |||
import com.bonait.bnframework.common.utils.ToastUtils; | |||
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.LinkedHashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.concurrent.ConcurrentHashMap; | |||
import kotlin.UShort; | |||
/** | |||
* 执行配方 | |||
*/ | |||
public class ExecuteTheRecipe { | |||
//region 变量 | |||
/**是否处于自动模式*/ | |||
public static boolean isAutoMode=true; | |||
/**是否处于称重模式*/ | |||
public static boolean isGravimetricMode=false; | |||
/**PLC连接是否超时,默认超时。*/ | |||
public static boolean isTimeOut=true; | |||
/** | |||
* 等待超时时间 | |||
*/ | |||
@@ -359,9 +386,13 @@ public class ExecuteTheRecipe { | |||
} | |||
//endregion | |||
//计算系数,称重模式下配方默认是按1kg配料的,所以需要计算系数。 | |||
double ratio=OutletWeigh/10.0/1000; | |||
//PLCControl.get().Speak("配料开始",null); | |||
int count = 0; | |||
for (LinkedHashMap.Entry<Integer, List<ResGoodsRecipe>> entry : rgrs.entrySet()) { | |||
WritePLC("配料完成", false,null); | |||
//WritePLC("配料完成", false,null); | |||
final Integer key = entry.getKey(); | |||
@@ -374,7 +405,11 @@ public class ExecuteTheRecipe { | |||
} | |||
count=2; | |||
DataBus.getInstance().UpdateGoodsMake(GoodMake.subOrder.id, "步骤【" + key + "】准备下发物料:" + RecipesNames, count, key, false); | |||
final boolean[] stepCompleted = {false}; | |||
final boolean[] siloComplted=new boolean[goodsRecipes.size()]; | |||
//region 给每个料仓下发指令 | |||
for (int m = 0; m < goodsRecipes.size(); m++) { | |||
ResGoodsRecipe recipe = goodsRecipes.get(m); | |||
final String message = "[" + GoodMake.good.name + "]步骤【" + key + "】下发【" + recipe.materialName + "】"; | |||
@@ -387,53 +422,103 @@ public class ExecuteTheRecipe { | |||
silos = item; | |||
} | |||
if (silos == null) { | |||
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, message + "下发失败!物料没有管理料仓!"); | |||
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, message + "下发失败!物料没有关联料仓!"); | |||
} else { | |||
//MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, message + "准备下发【" + silos.num + "】号料仓PLC控制命令,需求量:=" + recipe.value); | |||
int _val = (int)Math.round((Double.parseDouble(recipe.value) * 10)); | |||
WritePLC("需求值" + silos.num, (short) _val, null); | |||
//減去料仓数量 | |||
int otherG=silos.silosmargin-(_val/10); | |||
QueryDB.UpdateYL(silos.id,otherG>=0?otherG:0); | |||
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, message + "准备下发【" + silos.num + "】号料仓PLC控制命令,需求量:=" + recipe.value); | |||
double silo_adjustTime=Double.parseDouble(silos.jTime); | |||
double silo_adjustValue=Double.parseDouble(silos.jValue); | |||
double demand_value=Double.parseDouble(recipe.value); | |||
int delayTime=0; | |||
if (silos.name.equals("外置仓")){ | |||
delayTime=(int)(getDelayTimeByLCID(silos.id,demand_value)*1000); | |||
}else{ | |||
//打开时间= 校准时间/校准重量*需求量 .方法单位是ms,需要*1000. | |||
delayTime=(int)(silo_adjustTime/silo_adjustValue*demand_value*1000); | |||
} | |||
//如果在称重模式下,要计算比例,否则直接出料。 | |||
if (isGravimetricMode){ | |||
delayTime=(int)(delayTime*ratio); | |||
} | |||
//保存当前值,传入OnSuccess里。 | |||
final int[] index={0}; | |||
index[0]=m; | |||
final String siloId= silos.id; | |||
//出完料后的余量。 | |||
final int afterMargin=silos.silosmargin-(int)demand_value; | |||
PLCControl.get().openMotorAndClose(silos.num, delayTime, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
ToastUtils.success("[" + GoodMake.good.name + "] 配料完成!"); | |||
QueryDB.UpdateYL(siloId, afterMargin ); | |||
siloComplted[index[0]]=true; | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
ToastUtils.error("[" + GoodMake.good.name + "] 配料失败!"); | |||
} | |||
}); | |||
MessageLog.ShowInfo("[" + GoodMake.good.name + "]步骤【" + key + "】开始配料成功!"); | |||
} | |||
} | |||
//endregion | |||
MessageLog.ShowInfo(RecipesNames + "下发成功!"); | |||
//endregion | |||
//region 旧代码 | |||
//等待配料完成,一直等待 | |||
final boolean[] IsComplete = {false}; | |||
OnChargeMixtureCompleteNotify = new IRun() { | |||
@Override | |||
public void Run() { | |||
IsComplete[0] = true; | |||
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "[" + GoodMake.good.name + "]步骤【" + key + "】配料完成!"); | |||
} | |||
}; | |||
// | |||
// OnChargeMixtureCompleteNotify = new IRun() { | |||
// @Override | |||
// public void Run() { | |||
// IsComplete[0] = true; | |||
// MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "[" + GoodMake.good.name + "]步骤【" + key + "】配料完成!"); | |||
// } | |||
// }; | |||
//启动配料 | |||
WritePLC("配料启动",true,new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
MessageLog.ShowInfo("[" + GoodMake.good.name + "]步骤【" + key + "】启动配料成功!"); | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
MessageLog.ShowInfo("[" + GoodMake.good.name + "]步骤【" + key + "】启动配料失败!"); | |||
MessageLog.ShowAlertMessage(AlertLogEnum.异常订单未制作日志, "[" + GoodMake.good.name + "]步骤【" + key + "】启动配料失败!"); | |||
} | |||
}); | |||
// WritePLC("配料启动",true,new IWriteCallBack() { | |||
// @Override | |||
// public void onSuccess() { | |||
// MessageLog.ShowInfo("[" + GoodMake.good.name + "]步骤【" + key + "】启动配料成功!"); | |||
// } | |||
// | |||
// @Override | |||
// public void onFailure(String ErrorMsg) { | |||
// MessageLog.ShowInfo("[" + GoodMake.good.name + "]步骤【" + key + "】启动配料失败!"); | |||
// MessageLog.ShowAlertMessage(AlertLogEnum.异常订单未制作日志, "[" + GoodMake.good.name + "]步骤【" + key + "】启动配料失败!"); | |||
// } | |||
// }); | |||
//endregion | |||
//一分钟未完成 强制认为完成了。 | |||
long a = System.currentTimeMillis(); | |||
while (!IsComplete[0]) { | |||
while (!stepCompleted[0]) { | |||
if ((System.currentTimeMillis() - a) > 1000 * 60) { | |||
break; | |||
} | |||
Thread.sleep(100);//10 *6 | |||
stepCompleted[0]=true; | |||
for (int i=0;i<siloComplted.length;i++){ | |||
if (siloComplted[i]==false){ | |||
stepCompleted[0]=false; | |||
break; | |||
} | |||
}for (int i=0;i<siloComplted.length;i++){ | |||
if (siloComplted[i]==false){ | |||
stepCompleted[0]=false; | |||
break; | |||
} | |||
} | |||
Thread.sleep(500);//10 *6 | |||
} | |||
//更新缓存商品制作列表状态 | |||
count += goodsRecipes.size(); | |||
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "[" + GoodMake.good.name + "]步骤【" + key + "】配料完成!"); | |||
DataBus.getInstance().UpdateGoodsMake(GoodMake.subOrder.id, "步骤【" + key + "】:" + RecipesNames + "-配料完成!", count, key, true); | |||
MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "[" + GoodMake.good.name + "]步骤【" + key + "】下发" + RecipesNames + "执行完成!"); | |||
} | |||
@@ -460,6 +545,27 @@ public class ExecuteTheRecipe { | |||
//region PLC基础控制类 | |||
/**PLC通讯超时处理**/ | |||
public static void timeOutHandler(){ | |||
//ConfigName.getInstance().SerialIsConnect=false; | |||
ToastUtils.info("检测到PLC连接超时,尝试执行超时处理。"); | |||
//ModbusTcpHelper.get().release(); | |||
//ModbusRTUServer.get().ConnectPLC(); | |||
PLCControl.get().initalPLC(new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
ToastUtils.success("超时处理--复位PLC变量完成。"); | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
//ToastUtils.error("超时处理--复位PLC变量失败。"); | |||
} | |||
}); | |||
} | |||
/** | |||
* 写PLC数据 | |||
* | |||
@@ -511,6 +617,49 @@ public class ExecuteTheRecipe { | |||
} | |||
} | |||
/** | |||
* RTU模式向写PLC数据 | |||
* | |||
* @param name | |||
* @param value | |||
*/ | |||
public static void WritePLCForRTU(String name, Object value, IWriteCallBack callback) { | |||
try { | |||
int plcAddress=ConfigName.getInstance().SerialPLCAddress; | |||
if (plcAddress<1) return; | |||
if (ConfigName.getInstance().PLC_Address.containsKey(name)) { | |||
BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); | |||
if (!plcaddress.address.isEmpty() && !isTimeOut) { | |||
if (plcaddress.address.toUpperCase().startsWith("D"))//int | |||
{ | |||
int startAddress=ModbusRTUServer.GetAddress(plcaddress.address); | |||
short newvalue=Short.parseShort(value.toString()); | |||
ModbusRTUServer.get().WriteShort(plcAddress,startAddress, newvalue, callback); | |||
} else if (plcaddress.address.toUpperCase().startsWith("M"))//bool | |||
{ | |||
int startAddress=ModbusRTUServer.GetAddress(plcaddress.address); | |||
boolean newValue=Boolean.parseBoolean(value.toString()); | |||
ModbusRTUServer.get().WriteBool(plcAddress,startAddress, newValue, callback); | |||
} else if (plcaddress.address.toUpperCase().startsWith("X"))//bool | |||
{ | |||
int startAddress=ModbusRTUServer.GetAddress(plcaddress.address); | |||
boolean newValue=Boolean.parseBoolean(value.toString()); | |||
ModbusRTUServer.get().WriteBool(plcAddress,startAddress, newValue, callback); | |||
} else if (plcaddress.address.toUpperCase().startsWith("Y"))//bool | |||
{ | |||
int startAddress=ModbusRTUServer.GetAddress(plcaddress.address); | |||
boolean newValue=Boolean.parseBoolean(value.toString()); | |||
ModbusRTUServer.get().WriteBool(plcAddress,startAddress, newValue, callback); | |||
} | |||
} | |||
} | |||
} catch (Exception ex) { | |||
ToastUtils.error("异常信息:" + ex.getMessage()); | |||
} finally { | |||
} | |||
} | |||
/** | |||
* 读PLC数据 | |||
* | |||
@@ -898,23 +1047,11 @@ public class ExecuteTheRecipe { | |||
final boolean[] issucess1 = {false}; | |||
final boolean[] issucess2 = {false}; | |||
final boolean[] issucess3 = {false}; | |||
//写校准模式 | |||
WritePLC("砝码校准模式", true, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
issucess1[0] =true; | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
} | |||
}); | |||
WritePLC("关闭写保护", true, new IWriteCallBack() { | |||
// 1. 关闭写保护。 | |||
PLCControl.get().closeWriteProtect(new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
issucess2[0] =true; | |||
issucess1[0]=true; | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
@@ -922,17 +1059,59 @@ public class ExecuteTheRecipe { | |||
} | |||
}); | |||
WritePLC("零点校准", true, new IWriteCallBack() { | |||
// 2.称台清零。 | |||
PLCControl.get().zeroScale(new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
issucess3[0] =true; | |||
issucess2[0]=true; | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
} | |||
}); | |||
return issucess1[0] && issucess2[0]&& issucess3[0]; | |||
return issucess1[0] && issucess2[0]; | |||
//region 旧代码。 | |||
// final boolean[] issucess1 = {false}; | |||
// final boolean[] issucess2 = {false}; | |||
// final boolean[] issucess3 = {false}; | |||
// | |||
// //写校准模式 | |||
// WritePLC("砝码校准模式", true, new IWriteCallBack() { | |||
// @Override | |||
// public void onSuccess() { | |||
// issucess1[0] =true; | |||
// } | |||
// | |||
// @Override | |||
// public void onFailure(String ErrorMsg) { | |||
// | |||
// } | |||
// }); | |||
// WritePLC("关闭写保护", true, new IWriteCallBack() { | |||
// @Override | |||
// public void onSuccess() { | |||
// issucess2[0] =true; | |||
// } | |||
// @Override | |||
// public void onFailure(String ErrorMsg) { | |||
// | |||
// } | |||
// }); | |||
// | |||
// WritePLC("零点校准", true, new IWriteCallBack() { | |||
// @Override | |||
// public void onSuccess() { | |||
// issucess3[0] =true; | |||
// } | |||
// @Override | |||
// public void onFailure(String ErrorMsg) { | |||
// | |||
// } | |||
// }); | |||
// return issucess1[0] && issucess2[0]&& issucess3[0]; | |||
// endregion | |||
} | |||
/** | |||
@@ -940,14 +1119,42 @@ public class ExecuteTheRecipe { | |||
*/ | |||
public static boolean StopJiaoYanMode() | |||
{ | |||
final boolean[] issucess1 = {false}; | |||
final boolean[] issucess2 = {false}; | |||
//region 旧代码 | |||
// final boolean[] issucess1 = {false}; | |||
// final boolean[] issucess2 = {false}; | |||
// | |||
// //写校准模式 | |||
// WritePLC("砝码校准模式", false, new IWriteCallBack() { | |||
// @Override | |||
// public void onSuccess() { | |||
// issucess1[0] =true; | |||
// } | |||
// | |||
// @Override | |||
// public void onFailure(String ErrorMsg) { | |||
// | |||
// } | |||
// }); | |||
// WritePLC("打开写保护", true, new IWriteCallBack() { | |||
// @Override | |||
// public void onSuccess() { | |||
// issucess2[0] =true; | |||
// } | |||
// @Override | |||
// public void onFailure(String ErrorMsg) { | |||
// | |||
// } | |||
// }); | |||
//return issucess1[0] && issucess2[0]; | |||
//endregion | |||
//写校准模式 | |||
WritePLC("砝码校准模式", false, new IWriteCallBack() { | |||
final boolean[] issucess1 = {false}; | |||
// 1. 打开写保护 | |||
PLCControl.get().openWriteProtect(new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
issucess1[0] =true; | |||
issucess1[0]=true; | |||
} | |||
@Override | |||
@@ -955,17 +1162,46 @@ public class ExecuteTheRecipe { | |||
} | |||
}); | |||
WritePLC("打开写保护", true, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
issucess2[0] =true; | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
return issucess1[0]; | |||
} | |||
//endregion | |||
} | |||
}); | |||
return issucess1[0] && issucess2[0]; | |||
//region 外置仓相关 | |||
/**根据外置仓的仓位ID获取对应克重的延时时间*/ | |||
public static double getDelayTimeByLCID(String lcID,double weight){ | |||
if (lcID.isEmpty() || weight<=0){ | |||
return 0; | |||
} | |||
BPA_SILOS silo= QueryDB.GetSilosID(lcID); | |||
if (silo ==null || silo.maxweight==null || silo.minweight==null || silo.bcsfValue==null){ | |||
return 0; | |||
} | |||
final double maxWeight=Double.parseDouble(silo.maxweight); | |||
final double minWeight=Double.parseDouble(silo.minweight); | |||
final double[] coefficients=stringToDoubleArray(silo.bcsfValue); | |||
if (weight<=minWeight || weight>=maxWeight){ | |||
return 0; | |||
} | |||
double delayTime=0.0; | |||
final int degree=coefficients.length-1; | |||
for (int i=0;i<coefficients.length;i++){ | |||
delayTime+=coefficients[i]* Math.pow(weight,degree-i); | |||
} | |||
return delayTime; | |||
} | |||
/**根据字符串,返回double数组,字符串必须是[1.0,2.0,3.0]这种形式*/ | |||
private static double[] stringToDoubleArray(@NonNull String str) { | |||
String[] strArray = str.substring(1, str.length() - 1).split(", "); | |||
double[] doubleArray=new double[strArray.length]; | |||
for (int i=0;i< strArray.length;i++){ | |||
doubleArray[i]=Double.parseDouble(strArray[i]); | |||
} | |||
return doubleArray; | |||
} | |||
//endregion | |||
} |
@@ -0,0 +1,340 @@ | |||
package com.bonait.bnframework.business.devicesControl; | |||
import android.os.Handler; | |||
import android.os.Looper; | |||
import com.bonait.bnframework.business.ExecuteTheRecipe; | |||
import com.bonait.bnframework.common.constant.ConfigName; | |||
import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; | |||
import com.bonait.bnframework.common.helper.DataFormat; | |||
import com.bonait.bnframework.common.helper.I.IWriteCallBack; | |||
import com.bonait.bnframework.common.modbus.ModbusRTUServer; | |||
import com.bonait.bnframework.common.utils.ToastUtils; | |||
import java.nio.ByteBuffer; | |||
import java.nio.ByteOrder; | |||
public class PLCControl { | |||
//region 单例模式 | |||
private static volatile PLCControl instance = null; | |||
public static PLCControl get() { | |||
PLCControl manager = instance; | |||
if (manager == null) { | |||
synchronized (PLCControl.class) { | |||
manager = instance; | |||
if (manager == null) { | |||
manager = new PLCControl(); | |||
instance = manager; | |||
} | |||
} | |||
} | |||
return manager; | |||
} | |||
private PLCControl() { | |||
} | |||
//endregion | |||
/**语音模块的从站地址,这个最好不改,设备端不好修改默认地址*/ | |||
private final int voiceAddress=1; | |||
/**电子秤的从站地址*/ | |||
private final int scaleAddress=2; | |||
/**PLC的从站地址*/ | |||
private final int PLCAddress=3; | |||
//region 语音模块控制 , 从站地址:1 | |||
public void Speak(String content,IWriteCallBack callBack){ | |||
try { | |||
if (!content.isEmpty() /*&& !ExecuteTheRecipe.isTimeOut*/) { | |||
int address = 0; | |||
short[] values=getGB2312(content); | |||
ModbusRTUServer.get().WriteString(voiceAddress, address, values, callBack); | |||
} | |||
} | |||
catch (Exception ex) { | |||
ToastUtils.error("Exception message:" + ex.getMessage()); | |||
} | |||
} | |||
//endregion | |||
//region 电子秤控制, 从站地址:2 | |||
/**获取称当前重量、当前AD值、当前零位,文档建议150ms以上轮询一次*/ | |||
public int getCurrentWeight(){ | |||
//int readLength=3; | |||
int[] result=new int[]{0}; | |||
try { | |||
ModbusRTUServer.get().ReadInts(scaleAddress, 0, 1, DataFormat.BADC, val-> { | |||
result[0]=val[0]; | |||
}); | |||
}catch (Exception ex){ | |||
ToastUtils.error("Exception message:" + ex.getMessage()); | |||
}finally { | |||
return result[0]; | |||
} | |||
} | |||
/**写入砝码重量*/ | |||
public void writeCounterWeight(short counterWeight,IWriteCallBack callBack){ | |||
try { | |||
ModbusRTUServer.get().WriteShort(scaleAddress, 6,counterWeight,callBack); | |||
}catch (Exception ex){ | |||
ToastUtils.error("Exception message:" + ex.getMessage()); | |||
} | |||
} | |||
/**去皮*/ | |||
public void tare(IWriteCallBack callBack){ | |||
try { | |||
ModbusRTUServer.get().WriteShort(scaleAddress, 21,(short) 1,callBack); | |||
}catch (Exception ex){ | |||
ToastUtils.error("Exception message:" + ex.getMessage()); | |||
} | |||
} | |||
/**恢复去皮*/ | |||
public void cancelTare(IWriteCallBack callBack){ | |||
try { | |||
ModbusRTUServer.get().WriteShort(scaleAddress, 21,(short) 2,callBack); | |||
}catch (Exception ex){ | |||
ToastUtils.error("Exception message:" + ex.getMessage()); | |||
} | |||
} | |||
/**零点校准,写入前需要先关闭写保护*/ | |||
public void zeroScale(IWriteCallBack callBack){ | |||
try { | |||
ModbusRTUServer.get().WriteShort(scaleAddress, 22,(short) 1,callBack); | |||
}catch (Exception ex){ | |||
ToastUtils.error("Exception message:" + ex.getMessage()); | |||
} | |||
} | |||
/**恢复出厂设置,写入前需要先关闭写保护*/ | |||
public void factoryReset(IWriteCallBack callBack){ | |||
try { | |||
ModbusRTUServer.get().WriteShort(scaleAddress, 22,(short) 9,callBack); | |||
}catch (Exception ex){ | |||
ToastUtils.error("Exception message:" + ex.getMessage()); | |||
} | |||
} | |||
/**打开写保护*/ | |||
public void openWriteProtect(IWriteCallBack callBack){ | |||
try { | |||
ModbusRTUServer.get().WriteShort(scaleAddress, 23,(short) 0,callBack); | |||
}catch (Exception ex){ | |||
ToastUtils.error("Exception message:" + ex.getMessage()); | |||
} | |||
} | |||
/**关闭写保护,零点校准、写入砝码重量、恢复出厂设置都需要先执行此操作*/ | |||
public void closeWriteProtect(IWriteCallBack callBack){ | |||
try { | |||
ModbusRTUServer.get().WriteShort(scaleAddress, 23,(short) 1,callBack); | |||
}catch (Exception ex){ | |||
ToastUtils.error("Exception message:" + ex.getMessage()); | |||
} | |||
} | |||
//endregion | |||
//region PLC控制 设备从站地址:3 | |||
/**复位PLC所有输出以及心跳,[如果输出更换了点位的话,无法复位所有电机]*/ | |||
public void initalPLC(IWriteCallBack callBack){ | |||
try { | |||
short[] values = new short[14]; | |||
final boolean[] isSuccess={false,false,false}; | |||
int startAddress = ModbusRTUServer.GetAddress("D10"); | |||
ModbusRTUServer.get().WriteShorts(PLCAddress, startAddress, values, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
isSuccess[0]=true; | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
} | |||
}); | |||
int timeoutFlag = ModbusRTUServer.GetAddress("M0"); | |||
ModbusRTUServer.get().WriteBool(PLCAddress, timeoutFlag, false, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
isSuccess[1]=true; | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
} | |||
}); | |||
clrHeartbeat("心跳时间", new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
isSuccess[2]=true; | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
} | |||
}); | |||
if (callBack != null) { | |||
if (isSuccess[0] && isSuccess[1] && isSuccess[2]){ | |||
callBack.onSuccess(); | |||
}else{ | |||
callBack.onFailure("Initial Failure"); | |||
} | |||
} | |||
} catch (Exception ex) { | |||
if (callBack != null) { | |||
callBack.onFailure(ex.getMessage()); | |||
} | |||
} | |||
} | |||
/**打开电机,指定时间后关闭 | |||
* @param delayTime 关闭延迟时间,单位:ms | |||
* */ | |||
public void openMotorAndClose(int index,int delayTime,IWriteCallBack callBack){ | |||
try { | |||
openMotor(index, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
new Handler(Looper.getMainLooper()).postDelayed(()->{ | |||
closeMotor(index, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
callBack.onSuccess(); | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
callBack.onFailure(ErrorMsg); | |||
} | |||
}); | |||
},delayTime); | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
callBack.onFailure(ErrorMsg); | |||
} | |||
}); | |||
} catch (Exception ex) { | |||
ToastUtils.error("OpenMotorAndClose Exception:" + ex.getMessage()); | |||
} | |||
} | |||
/**打开电机*/ | |||
public void openMotor(int index, IWriteCallBack callBack) { | |||
String name="通道"+index+"开关"; | |||
try { | |||
if (ConfigName.getInstance().PLC_Address.containsKey(name)) { | |||
BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); | |||
if (!plcaddress.address.isEmpty() && !ExecuteTheRecipe.isTimeOut) { | |||
int address = ModbusRTUServer.GetAddress(plcaddress.address); | |||
ModbusRTUServer.get().WriteShort(PLCAddress, address, (short)1, callBack); | |||
} | |||
} | |||
} catch (Exception ex) { | |||
ToastUtils.error("OpenMotor Exception:" + ex.getMessage()); | |||
} | |||
} | |||
/**关闭电机*/ | |||
public void closeMotor(int index, IWriteCallBack callBack) { | |||
String name="通道"+index+"开关"; | |||
try { | |||
if (ConfigName.getInstance().PLC_Address.containsKey(name)) { | |||
BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); | |||
if (!plcaddress.address.isEmpty() && !ExecuteTheRecipe.isTimeOut) { | |||
int address = ModbusRTUServer.GetAddress(plcaddress.address); | |||
ModbusRTUServer.get().WriteShort(PLCAddress, address, (short)0, callBack); | |||
} | |||
} | |||
} catch (Exception ex) { | |||
ToastUtils.error("CloseMotor Exception:" + ex.getMessage());} | |||
} | |||
/**获取所有电机的状态,为true表示正在转,反之,为false。*/ | |||
public boolean[] getAllMotorStatus(){ | |||
//一共有14个电机 | |||
int length = 14; | |||
boolean[] result = new boolean[length]; | |||
try { | |||
BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get("通道1开关"); | |||
if (!plcaddress.address.isEmpty() && !ExecuteTheRecipe.isTimeOut) { | |||
int startAddress = ModbusRTUServer.GetAddress(plcaddress.address); | |||
ModbusRTUServer.get().ReadShorts(PLCAddress, startAddress, length, val -> { | |||
for (int i = 0; i < length; i++) { | |||
result[i] = val[i] > 0 ? true : false; | |||
} | |||
}); | |||
} | |||
}catch (Exception ex){ | |||
ToastUtils.error("GetAllMotorStatus Exception:" + ex.getMessage()); | |||
}finally { | |||
return result; | |||
} | |||
} | |||
/**复位心跳*/ | |||
public void clrHeartbeat(String name,IWriteCallBack callBack){ | |||
try { | |||
if (ConfigName.getInstance().PLC_Address.containsKey(name)) { | |||
BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); | |||
if (!plcaddress.address.isEmpty()/* && !ExecuteTheRecipe.isTimeOut*/) { | |||
int address = ModbusRTUServer.GetAddress(plcaddress.address); | |||
ModbusRTUServer.get().WriteShort(PLCAddress , address ,(short) 0 , callBack); | |||
} | |||
} | |||
} catch (Exception ex) { | |||
ToastUtils.error("ClrHeartbeat Exception:" + ex.getMessage()); | |||
} | |||
} | |||
/**读取是否超时*/ | |||
public boolean isTimeOut(String name){ | |||
final boolean[] result = {true}; | |||
try{ | |||
if (ConfigName.getInstance().PLC_Address.containsKey(name)) { | |||
BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); | |||
if (!plcaddress.address.isEmpty() /*&& ConfigName.getInstance().SerialIsConnect*/) { | |||
ModbusRTUServer.get().ReadBools(PLCAddress, plcaddress.address, 1, val-> { | |||
result[0] =val[0]; | |||
}); | |||
} | |||
} | |||
}catch (Exception ex){ | |||
ToastUtils.error("Exception message:" + ex.getMessage()); | |||
}finally { | |||
return result[0]; | |||
} | |||
} | |||
//endregion | |||
/**字符串转换为GB2312编码,需要测试,可能不对*/ | |||
public short[] getGB2312(String str){ | |||
try{ | |||
byte[] bytes=str.getBytes("gb2312"); | |||
short[] result=new short[bytes.length/2]; | |||
ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN).asShortBuffer().get(result); | |||
return result; | |||
}catch (Exception e){ | |||
return null; | |||
} | |||
} | |||
} |
@@ -31,7 +31,8 @@ public class BPA_SILOS extends ModeBase { | |||
//校准时间 jValue/jTime = (1s 出多少g) | |||
public String jTime; | |||
//反转时间 | |||
/**反转时间*/ | |||
public String fTime; | |||
//是否启用算法补偿 0 不启用 1 启用 | |||
public int isenablebcsf; | |||
@@ -12,6 +12,11 @@ public class BPA_SYSTEMSET extends ModeBase{ | |||
* 2 PLC端口 | |||
* 3 门店id | |||
* 4 设备id | |||
* 20 串口波特率 | |||
* 21 串口数据位 | |||
* 22 串口校验位 | |||
* 23 串口停止位 | |||
* | |||
*/ | |||
public int type; | |||
//值 | |||
@@ -0,0 +1,632 @@ | |||
package com.bonait.bnframework.common.modbus; | |||
import com.bonait.bnframework.business.ConfigData; | |||
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.common.helper.MessageLog; | |||
import com.licheedev.modbus4android.ModbusCallback; | |||
import com.licheedev.modbus4android.ModbusParam; | |||
import com.licheedev.modbus4android.ModbusRespException; | |||
import com.licheedev.modbus4android.param.SerialParam; | |||
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.UnsupportedEncodingException; | |||
import java.nio.ByteBuffer; | |||
import java.util.Arrays; | |||
import java.util.concurrent.ExecutionException; | |||
public class ModbusRTUServer { | |||
//region 单例模式 | |||
private static volatile ModbusRTUServer instance = null; | |||
public static ModbusRTUServer get() { | |||
ModbusRTUServer manager = instance; | |||
if (manager == null) { | |||
synchronized (ModbusRTUServer.class) { | |||
manager = instance; | |||
if (manager == null) { | |||
manager = new ModbusRTUServer(); | |||
instance = manager; | |||
} | |||
} | |||
} | |||
return manager; | |||
} | |||
private ModbusRTUServer() { | |||
} | |||
//endregion | |||
static ModbusParam param; | |||
/**适用于三菱PLC,只有X,Y,M,D区*/ | |||
public static int GetAddress(String address){ | |||
if (address == null) return -1; | |||
address = address.toUpperCase().trim(); | |||
try { | |||
if (address.length() < 2) return Integer.parseInt(address); | |||
String res = address.substring(1); | |||
if (res == null) return -1; | |||
int startAddress=Integer.parseInt(res) ; | |||
//如果是M区地址。 | |||
if (address.contains("M")) { | |||
return startAddress + 4000; | |||
} else if (address.contains("D")) { | |||
return startAddress; | |||
}else if(address.contains("X")){ | |||
return Integer.parseInt(res,8); | |||
}else if(address.contains("Y")){ | |||
return Integer.parseInt(res,8)+300; | |||
}else{ | |||
return Integer.parseInt(address); | |||
} | |||
} catch (Exception e) { | |||
return -1; | |||
} | |||
} | |||
/** 连接PLC*/ | |||
public void ConnectPLC() | |||
{ | |||
int baudRate=ConfigName.getInstance().SerialBaudRate; | |||
int dataBits=ConfigName.getInstance().SerialDataBits; | |||
int parity=ConfigName.getInstance().SerialParity; | |||
int stopBits=ConfigName.getInstance().SerialStopBits; | |||
//String com="COM0"; | |||
param = SerialParam.create("/dev/ttyCOM0", baudRate) // 串口地址和波特率 | |||
.setDataBits(dataBits) // 数据位 | |||
.setParity(parity) // 校验位 | |||
.setStopBits(stopBits) // 停止位 | |||
.setTimeout(3000).setRetries(0); // 不重试 | |||
ModbusTcpHelper.get().init(param, new ModbusCallback<ModbusMaster>() { | |||
@Override | |||
public void onSuccess(ModbusMaster modbusMaster) { | |||
//ToastUtils.info("串口 ["+com+"] 连接成功"); | |||
//MessageLog.ShowInfo("串口 ["+com+"] 连接成功"); | |||
ConfigName.getInstance().SerialIsConnect = true; | |||
ConfigData.getInstance().PLC_Init(); | |||
} | |||
@Override | |||
public void onFailure(Throwable tr) { | |||
ConfigName.getInstance().SerialIsConnect = false; | |||
//ToastUtils.info("串口 ["+com+"] 连接失败:" + tr.getMessage()); | |||
//MessageLog.ShowError("串口 ["+com+"] 连接失败:" + tr.getMessage()); | |||
} | |||
@Override | |||
public void onFinally() { | |||
} | |||
}); | |||
} | |||
//region 数据类型转换 | |||
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; | |||
} | |||
//endregion | |||
//region 读取及写入方法 | |||
/**写入字符串*/ | |||
public void WriteString(int slaveAddress,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(slaveAddress, add, send); | |||
if (callback != null) | |||
callback.onSuccess(); | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} | |||
} | |||
/**写入字符串*/ | |||
public void WriteString(int slaveAddress,int Address, short[] values, IWriteCallBack callback) { | |||
if (slaveAddress<0) return; | |||
if (Address < 0) return; | |||
if (values ==null || values.length==0) return; | |||
try { | |||
ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, values); | |||
if (callback != null) | |||
callback.onSuccess(); | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("WriteString onFailure,Address=" + Address + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("WriteString onFailure,Address=" + Address + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("WriteString onFailure,Address=" + Address + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("WriteString onFailure,Address=" + Address + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("WriteString onFailure,Address=" + Address + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} | |||
} | |||
/**根据地址批量读取16位寄存器*/ | |||
public void ReadShorts(int slaveAddress,int Address, int length, IReadCallBack<short[]> callback) { | |||
//int add = GetAddress(Address); | |||
if (Address < 0) return; | |||
try { | |||
ReadHoldingRegistersResponse res = ModbusTcpHelper.get() | |||
.syncReadHoldingRegisters(slaveAddress, Address, length); | |||
short[] data = res.getShortData(); | |||
if (data.length == length) { | |||
if (callback != null) callback.onSuccess(data); | |||
} | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} | |||
} | |||
public void ReadBools(int slaveAddress,String Address, int length, IReadCallBack<boolean[]> callback) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
try { | |||
ReadCoilsResponse res = ModbusTcpHelper.get() | |||
.syncReadCoil(slaveAddress, add, length); | |||
boolean[] data = res.getBooleanData(); | |||
boolean[] result = Arrays.copyOfRange(data, 0, length); | |||
if (result.length == length) { | |||
if (callback != null) callback.onSuccess(result); | |||
} | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
}catch (Exception e){ | |||
MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} | |||
} | |||
public void ReadFloats(int slaveAddress,int Address, int length, IReadCallBack<float[]> callback) { | |||
//int add = GetAddress(Address); | |||
if (Address < 0) return; | |||
try { | |||
ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(slaveAddress, Address, 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); | |||
} | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} | |||
} | |||
public void ReadInts(int slaveAddress,int Address, int length,DataFormat dataFormat, IReadCallBack<int[]> callback) { | |||
//int add = GetAddress(Address); | |||
if (Address < 0) return; | |||
try { | |||
ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(slaveAddress, Address, 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]; | |||
} | |||
tempValues[i] = BytesToInt(tempData, dataFormat); | |||
} | |||
}else | |||
{ | |||
MessageLog.ShowError("ReadInt onFailure,Address=" ); | |||
} | |||
if (callback != null) callback.onSuccess(tempValues); | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); | |||
} | |||
} | |||
public void WriteShort(int slaveAddress,int Address, short Value, IWriteCallBack callback) { | |||
//int add = GetAddress(Address); | |||
if (Address < 0) return; | |||
short[] send = new short[1]; | |||
send[0] = Value; | |||
try { | |||
ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send); | |||
if (callback != null) | |||
callback.onSuccess(); | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} | |||
} | |||
public void WriteShorts(int slaveAddress,int Address, short[] Value, IWriteCallBack callback) { | |||
//int add = GetAddress(Address); | |||
if (Address < 0) return; | |||
try { | |||
ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, Value); | |||
if (callback != null) | |||
callback.onSuccess(); | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} | |||
} | |||
public void WriteBool(int slaveAddress,int Address, boolean Value, IWriteCallBack callback) { | |||
//int add = GetAddress(Address); | |||
if (Address < 0) return; | |||
try { | |||
ModbusTcpHelper.get().syncWriteCoil(slaveAddress, Address, Value); | |||
if (callback != null) | |||
callback.onSuccess(); | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} | |||
} | |||
public void WriteBools(int slaveAddress,int Address, boolean[] Value, IWriteCallBack callback) { | |||
//int add = GetAddress(Address); | |||
if (Address < 0) return; | |||
try { | |||
ModbusTcpHelper.get().syncWriteCoils(slaveAddress, Address, Value); | |||
if (callback != null) | |||
callback.onSuccess(); | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} | |||
} | |||
public void WriteFloat(int slaveAddress,int Address, float Value, IWriteCallBack callback) { | |||
//int add = GetAddress(Address); | |||
if (Address < 0) return; | |||
int intBits = Float.floatToRawIntBits(Value); | |||
short[] send = IntToShorts(intBits); | |||
try { | |||
ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send); | |||
if (callback != null) callback.onSuccess(); | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} | |||
} | |||
public void WriteInt(int slaveAddress,int Address, int Value, IWriteCallBack callback) { | |||
//int add = GetAddress(Address); | |||
if (Address < 0) return; | |||
short[] send = IntToShorts(Value); | |||
try { | |||
ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send); | |||
if (callback != null) callback.onSuccess(); | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
if (callback != null) callback.onFailure(e.toString()); | |||
} | |||
} | |||
public void WriteShort(int slaveAddress,int Address, short Value) { | |||
//int add = GetAddress(Address); | |||
if (Address < 0) return; | |||
short[] send = new short[1]; | |||
send[0] = Value; | |||
try { | |||
ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send); | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} | |||
} | |||
public void WriteBool(int slaveAddress,int Address, boolean Value) { | |||
//int add = GetAddress(Address); | |||
if (Address < 0) return; | |||
try { | |||
ModbusTcpHelper.get().syncWriteCoil(slaveAddress, Address, Value); | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} | |||
} | |||
public void WriteFloat(int slaveAddress,int Address, float Value) { | |||
//int add = GetAddress(Address); | |||
if (Address < 0) return; | |||
int intBits = Float.floatToRawIntBits(Value); | |||
short[] send = new short[]{(short) ((intBits >> 16) & 0xffff), (short) (intBits & 0xffff)}; | |||
try { | |||
ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send); | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} | |||
} | |||
public void WriteInt(int slaveAddress,int Address, int Value) { | |||
//int add = GetAddress(Address); | |||
if (Address < 0) return; | |||
short[] send = IntToShorts(Value); | |||
try { | |||
ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send); | |||
} catch (InterruptedException e) { | |||
MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ExecutionException e) { | |||
MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ModbusTransportException e) { | |||
MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ModbusInitException e) { | |||
MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} catch (ModbusRespException e) { | |||
MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); | |||
} | |||
} | |||
//endregion | |||
} |
@@ -25,6 +25,7 @@ import android.widget.TextView; | |||
import com.bonait.bnframework.R; | |||
import com.bonait.bnframework.business.ConfigData; | |||
import com.bonait.bnframework.business.ExecuteTheRecipe; | |||
import com.bonait.bnframework.business.deviceControl.seasonBar.ScaleDevice; | |||
import com.bonait.bnframework.common.base.BaseFragment; | |||
import com.bonait.bnframework.common.constant.ConfigName; | |||
import com.bonait.bnframework.common.constant.DataBus; | |||
@@ -39,13 +40,11 @@ import com.bonait.bnframework.common.db.mode.BPA_SUBORDER; | |||
import com.bonait.bnframework.common.db.res.ResGoodProperty; | |||
import com.bonait.bnframework.common.db.res.ResGoodsMake; | |||
import com.bonait.bnframework.common.db.res.SilosLsjyMode; | |||
import com.bonait.bnframework.common.db.res.UserLogEnum; | |||
import com.bonait.bnframework.common.helper.I.IRun; | |||
import com.bonait.bnframework.common.helper.I.IRunT; | |||
import com.bonait.bnframework.common.helper.I.IThread; | |||
import com.bonait.bnframework.common.helper.I.IWriteCallBack; | |||
import com.bonait.bnframework.common.helper.I.MyClickListener; | |||
import com.bonait.bnframework.common.helper.MessageLog; | |||
import com.bonait.bnframework.common.helper.ThreadManager; | |||
import com.bonait.bnframework.common.linktab.LinkMode; | |||
import com.bonait.bnframework.common.linktab.TopItemDecoration; | |||
@@ -397,8 +396,9 @@ public class MakeGoodFragment extends BaseFragment { | |||
Initdata(); | |||
break; | |||
case R.id.cheng_clear://称重清零 | |||
ExecuteTheRecipe.WritePLC("重量清零", true, new IWriteCallBack() { | |||
@Override | |||
//ExecuteTheRecipe.WritePLC("重量清零", true, new IWriteCallBack() { | |||
ScaleDevice.get().tare(new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
ToastUtils.info("清零成功!"); | |||
} | |||
@@ -2,34 +2,22 @@ package com.bonait.bnframework.modules.home.fragment.from; | |||
import static com.bonait.bnframework.MainApplication.getContext; | |||
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.os.Bundle; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import androidx.recyclerview.widget.RecyclerView; | |||
import com.bonait.bnframework.R; | |||
import com.bonait.bnframework.business.ExecuteTheRecipe; | |||
import com.bonait.bnframework.common.base.BaseActivity; | |||
import com.bonait.bnframework.common.base.BaseFragment; | |||
import com.bonait.bnframework.common.constant.ConfigName; | |||
import com.bonait.bnframework.common.constant.DataBus; | |||
import com.bonait.bnframework.common.db.res.StatusMode; | |||
import com.bonait.bnframework.common.view.MyLayoutManager; | |||
import com.bonait.bnframework.modules.home.adapter.devstatus_adapter; | |||
import com.bonait.bnframework.modules.home.fragment.GuanLifragment; | |||
import com.bonait.bnframework.modules.home.fragment.from.fragment.Jcsjgl_sxgl_fragment; | |||
import com.bonait.bnframework.modules.home.fragment.from.fragment.Jcsjgl_wl_fragment; | |||
import com.qmuiteam.qmui.arch.QMUIFragment; | |||
import com.qmuiteam.qmui.arch.QMUIFragmentPagerAdapter; | |||
import com.qmuiteam.qmui.widget.QMUITopBarLayout; | |||
import com.qmuiteam.qmui.widget.QMUIViewPager; | |||
import com.qmuiteam.qmui.widget.tab.QMUITabSegment; | |||
import java.util.ArrayList; | |||
@@ -84,77 +72,27 @@ public class RealTimeActivity extends BaseActivity { | |||
public void Initdata() | |||
{ | |||
try{ | |||
if (!ConfigName.getInstance().versionSelectionEnum.equals("配料吧台")) | |||
{ | |||
if (ConfigName.getInstance().versionSelectionEnum.equals("味魔方")){ | |||
DataBus.getInstance().statusModes=new ArrayList<>(); | |||
DataBus.getInstance().statusModes.add(new StatusMode("出料口光电",R.mipmap.gd1,R.mipmap.gd2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("果糖电机(左)",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("清洗池浮球",R.mipmap.fq1,R.mipmap.fq2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("果糖电机(右)",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("果糖液位检测(左)",R.mipmap.fq1,R.mipmap.fq2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("果糖液位检测(右)",R.mipmap.fq1,R.mipmap.fq2,false)); | |||
//16 | |||
DataBus.getInstance().statusModes.add(new StatusMode("果糖加热(左)",R.mipmap.lcjr1,R.mipmap.lcjr2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("果糖加热(右)",R.mipmap.lcjr1,R.mipmap.lcjr2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("清洗池加热",R.mipmap.lcjr1,R.mipmap.lcjr2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("三色灯(红)",R.mipmap.ssd1,R.mipmap.ssd2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("三色灯(黄)",R.mipmap.ssd1,R.mipmap.ssd2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("三色灯(绿)",R.mipmap.ssd1,R.mipmap.ssd2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("通道一开关",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("通道二开关",R.mipmap.csf1,R.mipmap.csf2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("通道三开关",R.mipmap.csf1,R.mipmap.csf2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("通道四开关",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("蠕动泵(一)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("蠕动泵(二)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("蠕动泵(三)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("蠕动泵(四)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("蠕动泵(五)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("隔膜泵(一)",R.mipmap.lxl1,R.mipmap.lxl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("隔膜泵(二)",R.mipmap.lxl1,R.mipmap.lxl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("隔膜泵(三)",R.mipmap.lxl1,R.mipmap.lxl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("隔膜泵(四)",R.mipmap.lxl1,R.mipmap.lxl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("隔膜泵(五)",R.mipmap.lxl1,R.mipmap.lxl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("通道五开关",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("通道六开关",R.mipmap.csf1,R.mipmap.csf2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("通道七开关",R.mipmap.csf1,R.mipmap.csf2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("通道八开关",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("果糖泵(左)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("果糖泵(右)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("清洗剂泵",R.mipmap.lxl1,R.mipmap.lxl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("通道九开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("通道十开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("通道十一开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("通道十二开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("通道十三开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("通道十四开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("排水阀开",R.mipmap.csf1,R.mipmap.csf2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("排水阀关",R.mipmap.csf1,R.mipmap.csf2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("进水阀",R.mipmap.jsf1,R.mipmap.jsf2,false)); | |||
}else | |||
{ | |||
DataBus.getInstance().statusModes=new ArrayList<>(); | |||
DataBus.getInstance().statusModes.add(new StatusMode("出料口按钮",R.mipmap.gd1,R.mipmap.gd2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("清洗池浮球",R.mipmap.fq1,R.mipmap.fq2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵正转(一)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵正转(二)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵正转(三)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵正转(四)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵正转(五)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵正转(六)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵反转(一)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵反转(二)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵反转(三)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵反转(四)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵反转(五)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵反转(六)",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("粉料电机(一)",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("粉料电机(二)",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("粉料电机(三)",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("酱油泵",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("醋泵",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("猪油泵",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("牛油泵",R.mipmap.rdl1,R.mipmap.rdl2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("水池进水阀",R.mipmap.jsf1,R.mipmap.jsf2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("水池排水阀",R.mipmap.csf1,R.mipmap.csf2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("猪油管道保温",R.mipmap.lcjr1,R.mipmap.lcjr2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("牛油管道保温",R.mipmap.lcjr1,R.mipmap.lcjr2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("水池加热",R.mipmap.lcjr1,R.mipmap.lcjr2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("三色灯(绿)",R.mipmap.ssd1,R.mipmap.ssd2,false)); | |||
DataBus.getInstance().statusModes.add(new StatusMode("三色灯(红)",R.mipmap.ssd1,R.mipmap.ssd2,false)); | |||
} | |||
Run(); | |||
@@ -186,53 +124,22 @@ public class RealTimeActivity extends BaseActivity { | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
while (ConfigName.getInstance().PlcIsConnect) { | |||
//while (ConfigName.getInstance().SerialIsConnect) { | |||
while (!ExecuteTheRecipe.isTimeOut) { | |||
try { | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
if (!ConfigName.getInstance().versionSelectionEnum.equals("配料吧台")) | |||
{ | |||
//64位 | |||
//1.出口 0-15 | |||
SetStatus(0,ExecuteTheRecipe.getConcurrentHash(0)); | |||
SetStatus(1,ExecuteTheRecipe.getConcurrentHash(1)); | |||
SetStatus(2,ExecuteTheRecipe.getConcurrentHash(2)); | |||
SetStatus(3,ExecuteTheRecipe.getConcurrentHash(3)); | |||
SetStatus(4,ExecuteTheRecipe.getConcurrentHash(4)); | |||
SetStatus(5,ExecuteTheRecipe.getConcurrentHash(5)); | |||
//3. | |||
for(int i=0;i<6;i++)//25 | |||
{ | |||
SetStatus(6+i,ExecuteTheRecipe.getConcurrentHash(16+i)); | |||
} | |||
for(int i=0;i<16;i++)//25 | |||
{ | |||
SetStatus(12+i,ExecuteTheRecipe.getConcurrentHash(32+i)); | |||
} | |||
adapter.refresh(); | |||
}else | |||
{ | |||
//64位 | |||
//1.出口 0-15 | |||
SetStatus(0,ExecuteTheRecipe.getConcurrentHash(0)); | |||
SetStatus(1,ExecuteTheRecipe.getConcurrentHash(1)); | |||
//3. | |||
for(int i=0;i<10;i++)//25 | |||
{ | |||
SetStatus(2+i,ExecuteTheRecipe.getConcurrentHash(16+i)); | |||
} | |||
for(int i=0;i<16;i++)//25 | |||
{ | |||
SetStatus(12+i,ExecuteTheRecipe.getConcurrentHash(32+i)); | |||
} | |||
adapter.refresh(); | |||
String sysName=ConfigName.getInstance().versionSelectionEnum; | |||
switch (sysName){ | |||
case "味魔方": | |||
for (int i=0;i<14;i++){ | |||
SetStatus(i,ExecuteTheRecipe.getConcurrentHash(i)); | |||
} | |||
break; | |||
} | |||
adapter.refresh(); | |||
} catch (Exception e) { | |||
} | |||
} | |||
@@ -51,6 +51,17 @@ public class SystemParameterActivity extends BaseActivity { | |||
EditText edittext3; | |||
@BindView(R.id.edittext4) | |||
EditText edittext4; | |||
@BindView(R.id.serialBaudRate) | |||
Spinner serialBaudRate; | |||
@BindView(R.id.serialDataBits) | |||
Spinner serialDataBits; | |||
@BindView(R.id.serialParity) | |||
Spinner serialParity; | |||
@BindView(R.id.serialStopBits) | |||
Spinner serialStopBits; | |||
@BindView(R.id.environment) | |||
Spinner environment; | |||
@@ -63,6 +74,11 @@ public class SystemParameterActivity extends BaseActivity { | |||
Map<String, Integer> material_map = new LinkedHashMap<>(); | |||
Map<String, Integer> material_map_vis = new LinkedHashMap<>(); | |||
Map<String, Integer> baudRate_map = new LinkedHashMap<>(); | |||
Map<String, Integer> dataBits_map = new LinkedHashMap<>(); | |||
Map<String, Integer> parity_map = new LinkedHashMap<>(); | |||
Map<String, Integer> stop_Bits = new LinkedHashMap<>(); | |||
/** | |||
* 系统设置参数 | |||
*/ | |||
@@ -75,8 +91,13 @@ public class SystemParameterActivity extends BaseActivity { | |||
context=getContext(); | |||
initTopBar(); | |||
initFragment(); | |||
initData(); | |||
initSelect(); | |||
try { | |||
initData(); | |||
initSelect(); | |||
}catch (Exception e){ | |||
} | |||
} | |||
private void initTopBar() { | |||
@@ -104,6 +125,20 @@ public class SystemParameterActivity extends BaseActivity { | |||
material_map.put("测试环境", 1); | |||
material_map.put("正式环境", 2); | |||
baudRate_map.put("9600",0); | |||
baudRate_map.put("19200",1); | |||
baudRate_map.put("115200",2); | |||
dataBits_map.put("7",0); | |||
dataBits_map.put("8",1); | |||
parity_map.put("0",0); | |||
parity_map.put("1",1); | |||
parity_map.put("2",2); | |||
stop_Bits.put("1",0); | |||
stop_Bits.put("2",1); | |||
for (int i = 0; i < ConfigName.getInstance().versionSelectionValues.length; i++) { | |||
material_map_vis.put(ConfigName.getInstance().versionSelectionValues[i], i); | |||
} | |||
@@ -117,6 +152,23 @@ public class SystemParameterActivity extends BaseActivity { | |||
adapter1.setDropDownViewResource(R.layout.spinner_dropdown_item); | |||
versionselection.setAdapter(adapter1); | |||
ArrayAdapter<String> adapter2 = new ArrayAdapter<>(context, R.layout.spinner_text_item, new ArrayList<>(baudRate_map.keySet())); | |||
adapter2.setDropDownViewResource(R.layout.spinner_dropdown_item); | |||
serialBaudRate.setAdapter(adapter2); | |||
ArrayAdapter<String> adapter3 = new ArrayAdapter<>(context, R.layout.spinner_text_item, new ArrayList<>(dataBits_map.keySet())); | |||
adapter3.setDropDownViewResource(R.layout.spinner_dropdown_item); | |||
serialDataBits.setAdapter(adapter3); | |||
ArrayAdapter<String> adapter4 = new ArrayAdapter<>(context, R.layout.spinner_text_item, new ArrayList<>(parity_map.keySet())); | |||
adapter4.setDropDownViewResource(R.layout.spinner_dropdown_item); | |||
serialParity.setAdapter(adapter4); | |||
ArrayAdapter<String> adapter5 = new ArrayAdapter<>(context, R.layout.spinner_text_item, new ArrayList<>(stop_Bits.keySet())); | |||
adapter5.setDropDownViewResource(R.layout.spinner_dropdown_item); | |||
serialStopBits.setAdapter(adapter5); | |||
bpa_systemsets = QueryDB.GetSystemsetALL(); | |||
for (BPA_SYSTEMSET item : bpa_systemsets) { | |||
@@ -145,7 +197,22 @@ public class SystemParameterActivity extends BaseActivity { | |||
ConfigName.getInstance().DeviceAutoKey = item.value; | |||
edittext4.setText(item.value); | |||
break; | |||
case 20: | |||
ConfigName.getInstance().SerialBaudRate = Integer.parseInt(item.value); | |||
serialBaudRate.setSelection(baudRate_map.get(item.value)); | |||
break; | |||
case 21: | |||
ConfigName.getInstance().SerialDataBits = Integer.parseInt(item.value); | |||
serialDataBits.setSelection(dataBits_map.get(item.value)); | |||
break; | |||
case 22: | |||
ConfigName.getInstance().SerialParity = Integer.parseInt(item.value); | |||
serialParity.setSelection(parity_map.get(item.value)); | |||
break; | |||
case 23: | |||
ConfigName.getInstance().SerialStopBits = Integer.parseInt(item.value); | |||
serialStopBits.setSelection(stop_Bits.get(item.value)); | |||
break; | |||
} | |||
} | |||
} | |||
@@ -200,6 +267,9 @@ public class SystemParameterActivity extends BaseActivity { | |||
set_vis.deviceID = ConfigName.getInstance().DeviceId; | |||
set_vis.userID = ConfigName.getInstance().user.userID; | |||
QueryDB.AddSystemset(set_vis); | |||
saveSerialParam(); | |||
if (isgb) { | |||
ConfigData.getInstance().RevertPLCProcess(); | |||
} | |||
@@ -210,6 +280,37 @@ public class SystemParameterActivity extends BaseActivity { | |||
} | |||
//-------------------------配置viewPager与fragment关联----------------------------// | |||
/**保存串口设置参数*/ | |||
private void saveSerialParam(){ | |||
BPA_SYSTEMSET set_baudrate = new BPA_SYSTEMSET(); | |||
set_baudrate.type = 20; | |||
set_baudrate.value =serialBaudRate.getSelectedItem().toString(); | |||
set_baudrate.deviceID = ConfigName.getInstance().DeviceId; | |||
set_baudrate.userID = ConfigName.getInstance().user.userID; | |||
QueryDB.AddSystemset(set_baudrate); | |||
BPA_SYSTEMSET set_dataBits = new BPA_SYSTEMSET(); | |||
set_dataBits.type = 21; | |||
set_dataBits.value = serialDataBits.getSelectedItem().toString(); | |||
set_dataBits.deviceID = ConfigName.getInstance().DeviceId; | |||
set_dataBits.userID = ConfigName.getInstance().user.userID; | |||
QueryDB.AddSystemset(set_dataBits); | |||
BPA_SYSTEMSET set_parity = new BPA_SYSTEMSET(); | |||
set_parity.type = 22; | |||
set_parity.value =serialParity.getSelectedItem().toString(); | |||
set_parity.deviceID = ConfigName.getInstance().DeviceId; | |||
set_parity.userID = ConfigName.getInstance().user.userID; | |||
QueryDB.AddSystemset(set_parity); | |||
BPA_SYSTEMSET set_stopBits = new BPA_SYSTEMSET(); | |||
set_stopBits.type = 23; | |||
set_stopBits.value = serialStopBits.getSelectedItem().toString(); | |||
set_stopBits.deviceID = ConfigName.getInstance().DeviceId; | |||
set_stopBits.userID = ConfigName.getInstance().user.userID; | |||
QueryDB.AddSystemset(set_stopBits); | |||
} | |||
@Override | |||
public void onDestroy() { | |||
super.onDestroy(); | |||
@@ -2,7 +2,6 @@ package com.bonait.bnframework.modules.home.fragment.mode; | |||
import android.app.Activity; | |||
import android.content.Context; | |||
import android.os.Bundle; | |||
import android.os.Handler; | |||
import android.os.Message; | |||
import android.os.SystemClock; | |||
@@ -15,29 +14,19 @@ import android.widget.EditText; | |||
import android.widget.LinearLayout; | |||
import android.widget.TextView; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import com.bonait.bnframework.R; | |||
import com.bonait.bnframework.business.ExecuteTheRecipe; | |||
import com.bonait.bnframework.common.base.BaseFragment; | |||
import com.bonait.bnframework.business.devicesControl.PLCControl; | |||
import com.bonait.bnframework.common.constant.ConfigName; | |||
import com.bonait.bnframework.common.constant.DataBus; | |||
import com.bonait.bnframework.common.db.QueryDB; | |||
import com.bonait.bnframework.common.db.res.SilosLsjyMode; | |||
import com.bonait.bnframework.common.db.res.lcMode; | |||
import com.bonait.bnframework.common.helper.I.IRun; | |||
import com.bonait.bnframework.common.helper.I.IWriteCallBack; | |||
import com.bonait.bnframework.common.utils.ToastUtils; | |||
import com.bonait.bnframework.modules.home.fragment.from.LogActivity; | |||
import com.bonait.bnframework.modules.home.fragment.from.PlcControlActivity; | |||
import com.bonait.bnframework.modules.home.fragment.from.RealTimeActivity; | |||
import com.orhanobut.logger.Logger; | |||
import com.qmuiteam.qmui.arch.QMUIFragment; | |||
import com.suke.widget.SwitchButton; | |||
import java.util.List; | |||
import butterknife.BindView; | |||
import butterknife.ButterKnife; | |||
import butterknife.OnClick; | |||
@@ -379,7 +368,8 @@ public class Silos_item_jiaoyan_fragment extends LinearLayout { | |||
* 电子秤清零 | |||
*/ | |||
public void dzcql() { | |||
ExecuteTheRecipe.WritePLC("重量清零", true, new IWriteCallBack() { | |||
//ExecuteTheRecipe.WritePLC("重量清零", true, new IWriteCallBack() { | |||
PLCControl.get().tare(new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
ToastUtils.info("清零成功!"); | |||
@@ -1,5 +1,6 @@ | |||
package com.bonait.bnframework.modules.home.fragment.mode; | |||
import android.annotation.SuppressLint; | |||
import android.content.Context; | |||
import android.content.DialogInterface; | |||
import android.os.Handler; | |||
@@ -15,7 +16,6 @@ import android.widget.Chronometer; | |||
import android.widget.EditText; | |||
import android.widget.ImageView; | |||
import android.widget.LinearLayout; | |||
import android.widget.ListView; | |||
import android.widget.RelativeLayout; | |||
import android.widget.Spinner; | |||
import android.widget.TextView; | |||
@@ -23,31 +23,22 @@ import android.widget.TextView; | |||
import androidx.annotation.Nullable; | |||
import com.bonait.bnframework.R; | |||
import com.bonait.bnframework.business.ConfigData; | |||
import com.bonait.bnframework.business.ExecuteTheRecipe; | |||
import com.bonait.bnframework.common.constant.ConfigName; | |||
import com.bonait.bnframework.business.devicesControl.PLCControl; | |||
import com.bonait.bnframework.common.db.QueryDB; | |||
import com.bonait.bnframework.common.db.mode.BPA_GOODS; | |||
import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPENAME; | |||
import com.bonait.bnframework.common.db.mode.BPA_GOODSTYPE; | |||
import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; | |||
import com.bonait.bnframework.common.db.mode.BPA_SILOS; | |||
import com.bonait.bnframework.common.db.mode.BPA_SILOSANDMATERIAL; | |||
import com.bonait.bnframework.common.db.res.ResGoodsRecipe; | |||
import com.bonait.bnframework.common.db.res.lcMode; | |||
import com.bonait.bnframework.common.helper.I.IWriteCallBack; | |||
import com.bonait.bnframework.common.helper.I.MyClickListener; | |||
import com.bonait.bnframework.common.utils.ToastUtils; | |||
import com.bonait.bnframework.modules.home.adapter.goodpf_apapter; | |||
import com.qmuiteam.qmui.widget.dialog.QMUIDialog; | |||
import com.suke.widget.SwitchButton; | |||
import java.math.BigDecimal; | |||
import java.text.DecimalFormat; | |||
import java.util.ArrayList; | |||
import java.util.LinkedHashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import butterknife.BindView; | |||
import butterknife.ButterKnife; | |||
@@ -111,6 +102,8 @@ public class add_silos_ck extends LinearLayout { | |||
@BindView(R.id.jishiqi) | |||
RelativeLayout jishiqi;// | |||
@BindView(R.id.menu_silo) | |||
RelativeLayout menu_silo; | |||
ArrayList<BPA_MATERIAL> materials = new ArrayList<>(); | |||
@@ -165,6 +158,7 @@ public class add_silos_ck extends LinearLayout { | |||
boolean ismanguan = false; | |||
@SuppressLint("ClickableViewAccessibility") | |||
private void initEvent() { | |||
buchongyuanliao.setOnClickListener(new OnClickListener() { | |||
@Override | |||
@@ -223,13 +217,16 @@ public class add_silos_ck extends LinearLayout { | |||
if (ismanguan == false) { | |||
ismanguan = true; | |||
StartTime(); | |||
ExecuteTheRecipe.WritePLC("手自切换", false, null); | |||
//ExecuteTheRecipe.WritePLC("手自切换", false, null); | |||
int time = lcMode.bValue <= 0 ? 10 : lcMode.bValue;//默认10秒 | |||
ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, true, null); | |||
//ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, true, null); | |||
PLCControl.get().openMotor(lcMode.num,null); | |||
new Handler().postDelayed(new Runnable() { | |||
@Override | |||
public void run() { | |||
ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, false, null); | |||
//ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, false, null); | |||
PLCControl.get().closeMotor(lcMode.num,null); | |||
ToastUtils.info("满管成功!!!"); | |||
ismanguan = false; | |||
StopTime(); | |||
@@ -345,19 +342,22 @@ public class add_silos_ck extends LinearLayout { | |||
public boolean onTouch(View view, MotionEvent motionEvent) { | |||
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { | |||
Log.e("鼠标", "按下: "); | |||
ExecuteTheRecipe.WritePLC("手自切换", false, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, true, null); | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
} | |||
}); | |||
// ExecuteTheRecipe.WritePLC("手自切换", false, new IWriteCallBack() { | |||
// @Override | |||
// public void onSuccess() { | |||
// ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, true, null); | |||
// } | |||
// | |||
// @Override | |||
// public void onFailure(String ErrorMsg) { | |||
// } | |||
// }); | |||
ExecuteTheRecipe.isAutoMode=false; | |||
PLCControl.get().openMotor(lcMode.num,null); | |||
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { | |||
Log.e("鼠标", "松开: "); | |||
ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, false, null); | |||
//ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, false, null); | |||
PLCControl.get().closeMotor(lcMode.num,null); | |||
} | |||
return false; | |||
} | |||
@@ -437,6 +437,7 @@ public class add_silos_ck extends LinearLayout { | |||
*/ | |||
public void StartTime() { | |||
jishiqi.setVisibility(View.VISIBLE); | |||
menu_silo.setVisibility(View.GONE); | |||
runtime.setBase(SystemClock.elapsedRealtime()); | |||
runtime.start(); | |||
@@ -447,6 +448,9 @@ public class add_silos_ck extends LinearLayout { | |||
*/ | |||
public int StopTime() { | |||
jishiqi.setVisibility(View.GONE); | |||
menu_silo.setVisibility(View.VISIBLE); | |||
long elapsedMillis = SystemClock.elapsedRealtime() - runtime.getBase(); | |||
runtime.stop(); | |||
@@ -188,7 +188,7 @@ public class fragment_plc_control extends LinearLayout { | |||
@Override | |||
public void onCheckedChanged(SwitchButton view, boolean isChecked) { | |||
boolean ischick= control_switch.isChecked(); | |||
ExecuteTheRecipe.WritePLC(model.name,ischick,null); | |||
ExecuteTheRecipe.WritePLCForRTU(model.name,ischick,null); | |||
ToastUtils.info("写入地址:"+model.address+"成功!状态:"+(ischick?"打开":"关闭")); | |||
} | |||
}); | |||
@@ -223,19 +223,22 @@ public class fragment_plc_control extends LinearLayout { | |||
return; | |||
} | |||
if(model.address.startsWith("VW")) | |||
{ | |||
Short val=Short.parseShort(text); | |||
ExecuteTheRecipe.WritePLC(model.name,val,null); | |||
}else if(model.address.startsWith("VD")) | |||
{ | |||
int val=Integer.parseInt(text); | |||
ExecuteTheRecipe.WritePLC(model.name,val,null); | |||
}else | |||
{ | |||
Short val=Short.parseShort(text); | |||
ExecuteTheRecipe.WritePLC(model.name,val,null); | |||
} | |||
// if(model.address.startsWith("VW")) | |||
// { | |||
// Short val=Short.parseShort(text); | |||
// ExecuteTheRecipe.WritePLC(model.name,val,null); | |||
// }else if(model.address.startsWith("VD")) | |||
// { | |||
// int val=Integer.parseInt(text); | |||
// ExecuteTheRecipe.WritePLC(model.name,val,null); | |||
// }else | |||
// { | |||
// Short val=Short.parseShort(text); | |||
// ExecuteTheRecipe.WritePLC(model.name,val,null); | |||
// } | |||
ExecuteTheRecipe.WritePLCForRTU(model.name,text,null); | |||
//TODO:修改手动写入操作代码。 | |||
ToastUtils.info("写入地址:"+model.address+"成功!"); | |||
break; | |||
@@ -28,6 +28,7 @@ import androidx.fragment.app.FragmentManager; | |||
import com.bonait.bnframework.R; | |||
import com.bonait.bnframework.business.ExecuteTheRecipe; | |||
import com.bonait.bnframework.business.deviceControl.seasonBar.ScaleDevice; | |||
import com.bonait.bnframework.common.constant.ConfigName; | |||
import com.bonait.bnframework.common.db.QueryDB; | |||
import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; | |||
@@ -119,12 +120,15 @@ public class silos_jiaoyan extends LinearLayout { | |||
//endregion | |||
//region 物料校准变量 | |||
/**物料校准--校准时间*/ | |||
@BindView(R.id.wljz1) | |||
EditText wljz1; | |||
/**物料校准--反转时间*/ | |||
@BindView(R.id.wljz2) | |||
EditText wljz2; | |||
/**物料校准--校准重量*/ | |||
@BindView(R.id.wljz3) | |||
EditText wljz3; | |||
@@ -146,6 +150,26 @@ public class silos_jiaoyan extends LinearLayout { | |||
EditText bcjz_clsj; | |||
//endregion | |||
//region 酱料校准的控件 | |||
/**酱料校准下限*/ | |||
@BindView(R.id.txt_jljz_lowLimit) | |||
EditText txt_jljz_lowLimit; | |||
/**酱料校准上限*/ | |||
@BindView(R.id.txt_jljz_highLimit) | |||
EditText txt_jljz_highLimit; | |||
/**酱料校准频率*/ | |||
@BindView(R.id.txt_jljz_adjFreq) | |||
EditText txt_jljz_adjFreq; | |||
/**开始酱料校准*/ | |||
@BindView(R.id.btn_jljz_startAdj) | |||
Button btn_jljz_startAdj; | |||
//endregion | |||
public silos_jiaoyan(Context context, @Nullable AttributeSet attrs) { | |||
super(context, attrs); | |||
root= LayoutInflater.from(context).inflate(R.layout.silos_jiaoyan_item, this); | |||
@@ -159,6 +183,9 @@ public class silos_jiaoyan extends LinearLayout { | |||
TextView text_wlkz; | |||
@BindView(R.id.text_mgkz) | |||
TextView text_mgkz; | |||
@BindView(R.id.text_mgkz1) | |||
TextView text_mgkz1; | |||
@BindView(R.id.text_jlkz) | |||
TextView text_jlkz; | |||
@BindView(R.id.text_bckz) | |||
@@ -168,8 +195,6 @@ public class silos_jiaoyan extends LinearLayout { | |||
TextView text_jlkz1; | |||
@BindView(R.id.text_bckz1) | |||
TextView text_bckz1; | |||
/** | |||
* 初始化数据 | |||
*/ | |||
@@ -178,24 +203,23 @@ public class silos_jiaoyan extends LinearLayout { | |||
title_bc.setText(lcMode.num+" "+lcMode.materialName); | |||
if(lcMode.name.equals("外置仓")) | |||
{ | |||
text_wlkz.setVisibility(View.GONE); | |||
text_mgkz1.setVisibility(View.GONE); | |||
text_jlkz.setVisibility(View.VISIBLE); | |||
text_bckz.setVisibility(View.VISIBLE); | |||
text_bckz.setVisibility(View.GONE); | |||
text_jlkz1.setVisibility(View.VISIBLE); | |||
text_bckz1.setVisibility(View.VISIBLE); | |||
text_bckz1.setVisibility(View.GONE); | |||
text_wljz2.setVisibility(View.GONE); | |||
wljz2.setVisibility(View.GONE); | |||
}else | |||
{ | |||
text_wlkz.setVisibility(View.VISIBLE); | |||
text_mgkz1.setVisibility(View.VISIBLE); | |||
text_jlkz.setVisibility(View.GONE); | |||
text_bckz.setVisibility(View.GONE); | |||
text_jlkz1.setVisibility(View.GONE); | |||
text_bckz1.setVisibility(View.GONE); | |||
text_wljz2.setVisibility(View.GONE); | |||
wljz2.setVisibility(View.GONE); | |||
} | |||
} | |||
@@ -205,17 +229,17 @@ public class silos_jiaoyan extends LinearLayout { | |||
close_from.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
// new Thread(new Runnable() { | |||
// @Override | |||
// public void run() { | |||
// try { | |||
// ExecuteTheRecipe.WritePLC("通道" + lcMode.num + "校准开关", false, null); | |||
// ExecuteTheRecipe.WritePLC("手自切换", true, null); | |||
// } catch (Exception e) { | |||
// | |||
// } | |||
// } | |||
// }).start(); | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
ExecuteTheRecipe.WritePLC("通道" + lcMode.num + "校准开关", false, null); | |||
ExecuteTheRecipe.WritePLC("手自切换", true, null); | |||
} catch (Exception e) { | |||
} | |||
} | |||
}).start(); | |||
if (mListener != null) { | |||
mListener.clickListenerNew(v,0,null); | |||
} | |||
@@ -274,7 +298,13 @@ public class silos_jiaoyan extends LinearLayout { | |||
activity=ac; | |||
this.lcMode=_lcMode; | |||
initData(); | |||
InitView("物料校准"); | |||
//InitView("物料校准"); | |||
if (lcMode.name.equals("外置仓")){ | |||
InitView("酱料校准"); | |||
}else{ | |||
InitView("物料校准"); | |||
} | |||
Run(); | |||
} | |||
@@ -407,10 +437,6 @@ public class silos_jiaoyan extends LinearLayout { | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
for (int i=1;i<=20;i++) | |||
{ | |||
ExecuteTheRecipe.WritePLC("通道"+i+"校准开关",false,null); | |||
} | |||
ExecuteTheRecipe.WritePLC("通道" + lcMode.num + "校准开关", true, null); | |||
if(activity!=null) | |||
{ | |||
@@ -474,7 +500,7 @@ public class silos_jiaoyan extends LinearLayout { | |||
R.id.chuliao1, R.id.chuliao2, R.id.chuliao3, | |||
R.id.click_mgjz, R.id.click_mgjz_save, | |||
R.id.click_wljz, R.id.click_wljz_save, | |||
R.id.click_bcjz_save, | |||
R.id.click_bcjz_save,R.id.btn_jljz_startAdj, | |||
}) | |||
public void onViewClicked(View view) { | |||
switch (view.getId()) { | |||
@@ -513,6 +539,9 @@ public class silos_jiaoyan extends LinearLayout { | |||
case R.id.click_bcjz_save://补偿校准 保存参数 | |||
SaveBCJZ(); | |||
break; | |||
case R.id.btn_jljz_startAdj: | |||
JLJZ(); | |||
break; | |||
} | |||
} | |||
//endregion | |||
@@ -523,8 +552,9 @@ public class silos_jiaoyan extends LinearLayout { | |||
* 电子秤清零 | |||
*/ | |||
public void dzcql() { | |||
ExecuteTheRecipe.WritePLC("重量清零", true, new IWriteCallBack() { | |||
@Override | |||
//ExecuteTheRecipe.WritePLC("重量清零", true, new IWriteCallBack() { | |||
ScaleDevice.get().tare(new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
ToastUtils.info("清零成功!"); | |||
} | |||
@@ -556,7 +586,7 @@ public class silos_jiaoyan extends LinearLayout { | |||
ToastUtils.warning("出料重量不能为空!"); | |||
return; | |||
} | |||
double zl = 0; | |||
double zl = 0;//需求重量。 | |||
try { | |||
zl = Double.parseDouble(zltext); | |||
} catch (Exception e) { | |||
@@ -568,37 +598,221 @@ public class silos_jiaoyan extends LinearLayout { | |||
return; | |||
} | |||
if (ConfigName.getInstance().versionSelectionEnum.equals("奶茶机")) | |||
{ | |||
if (!ExecuteTheRecipe.IsCup) { | |||
ToastUtils.warning("出料口没有检测到器皿!"); | |||
return; | |||
} | |||
} | |||
// if (ConfigName.getInstance().versionSelectionEnum.equals("奶茶机")) | |||
// { | |||
// if (!ExecuteTheRecipe.IsCup) { | |||
// ToastUtils.warning("出料口没有检测到器皿!"); | |||
// return; | |||
// } | |||
// } | |||
//short kkk = (short) ((int) (zl * 10)); | |||
short kkk = (short) ((int) (zl * 10)); | |||
final int[] delayTime=new int[]{0}; | |||
if (TypeName.equals("酱料校准")){ | |||
delayTime[0]=(int)(ExecuteTheRecipe.getDelayTimeByLCID(lcMode.id,zl)*1000); | |||
}else{ | |||
delayTime[0] =(int)(Double.parseDouble(lcMode.jTime)/Double.parseDouble(lcMode.jValue)*zl*1000); | |||
} | |||
if (delayTime[0]<=0){ | |||
ToastUtils.error("Simulation Fail,the open motor time must greater than 0"); | |||
return; | |||
} | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
ExecuteTheRecipe.WritePLC("配料完成", false, null); | |||
ExecuteTheRecipe.WritePLC("手自切换", true, null); | |||
int otherG=lcMode.silosmargin-(kkk/10); | |||
QueryDB.UpdateYL(lcMode.id,otherG>=0?otherG:0); | |||
ExecuteTheRecipe.WritePLC("需求值" + lcMode.num, kkk, new IWriteCallBack() { | |||
// ExecuteTheRecipe.WritePLC("配料完成", false, null); | |||
// ExecuteTheRecipe.WritePLC("手自切换", true, null); | |||
ExecuteTheRecipe.isAutoMode=false; | |||
PLCControl.get().openMotorAndClose(lcMode.num, delayTime[0], new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
ExecuteTheRecipe.WritePLC("配料启动", true, null); | |||
ToastUtils.warning("启动成功......"); | |||
ToastUtils.success("Start Simulation Success......"); | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
ToastUtils.error("Start Simulation Failure:"+ ErrorMsg); | |||
} | |||
}); | |||
} catch (Exception e) { | |||
ToastUtils.error("Simulation Open:"+ e.getMessage()); | |||
} | |||
} | |||
}).start(); | |||
ToastUtils.info("Start Simulation......"); | |||
} | |||
//endregion | |||
//region 酱料校准 | |||
/**酱料校准--校准成功自动保存*/ | |||
private void JLJZ(){ | |||
//region 校验及转换数据 | |||
String highLimit=txt_jljz_highLimit.getText().toString().trim(); | |||
String lowLimit=txt_jljz_lowLimit.getText().toString().trim(); | |||
String text_adjFreq=txt_jljz_adjFreq.getText().toString().trim(); | |||
if (lowLimit.isEmpty() || lowLimit.equals("")){ | |||
ToastUtils.warning("校准范围下限不能为空!"); | |||
return; | |||
} | |||
if (highLimit.isEmpty() || highLimit.equals("")){ | |||
ToastUtils.warning("校准范围上限不能为空!"); | |||
return; | |||
} | |||
if (text_adjFreq.isEmpty() || text_adjFreq.equals("")){ | |||
ToastUtils.warning("校准频率不能为空!"); | |||
return; | |||
} | |||
final double weightLowLimit; | |||
final double weightHighLimit; | |||
final int adjFreq; | |||
try { | |||
weightLowLimit=Double.parseDouble(lowLimit); | |||
}catch (Exception e){ | |||
ToastUtils.error("校准下限异常!" + e.getMessage()); | |||
return; | |||
} | |||
try { | |||
weightHighLimit=Double.parseDouble(highLimit); | |||
}catch (Exception e){ | |||
ToastUtils.error("校准上限异常!" + e.getMessage()); | |||
return; | |||
} | |||
try { | |||
adjFreq=Integer.parseInt(text_adjFreq); | |||
}catch (Exception e){ | |||
ToastUtils.error("校准频率异常!" + e.getMessage()); | |||
return; | |||
} | |||
if (weightLowLimit<0 || (weightLowLimit>=weightHighLimit)){ | |||
ToastUtils.error("校准范围值异常,下限应大于0,且小于上限值!"); | |||
return; | |||
} | |||
//endregion | |||
btn_jljz_startAdj.setEnabled(false); | |||
btn_jljz_startAdj.setText("正在校准..."); | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
ExecuteTheRecipe.isAutoMode=false; | |||
final double[] currentWeight=new double[]{0}; | |||
currentWeight[0]=ExecuteTheRecipe.OutletWeigh/10; | |||
//出料时间及出料重量对比表。 | |||
//HashMap<Double,Double> outMaterialMap=new HashMap<Double, Double>(); | |||
WeightedObservedPoints points=new WeightedObservedPoints(); | |||
long startTime=System.currentTimeMillis(); | |||
ToastUtils.info("开始酱料校准,时间较长,请耐心等待。"); | |||
while (currentWeight[0]<=weightHighLimit){ | |||
// PLCControl.get().openMotorAndClose(lcMode.num, adjFreq * 1000, new IWriteCallBack() { | |||
// @Override | |||
// public void onSuccess() { | |||
// currentWeight[0]=ExecuteTheRecipe.OutletWeigh/10; | |||
// if (currentWeight[0]>=weightLowLimit){ | |||
// //出料时间 | |||
// long outTime=System.currentTimeMillis()-startTime; | |||
// double time=((double)outTime)/1000; | |||
// outMaterialMap.put(time,currentWeight[0]); | |||
// } | |||
// } | |||
// @Override | |||
// public void onFailure(String ErrorMsg) { | |||
// //ToastUtils.error("酱料校准开关电机错误,校准失败"); | |||
// } | |||
// }); | |||
PLCControl.get().openMotor(lcMode.num, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
try { | |||
Thread.sleep(adjFreq*1000); | |||
PLCControl.get().closeMotor(lcMode.num, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
currentWeight[0]=ExecuteTheRecipe.OutletWeigh/10.0; | |||
if (currentWeight[0]>=weightLowLimit){ | |||
//出料时间 | |||
long outTime=System.currentTimeMillis()-startTime; | |||
double time=((double)outTime)/1000; | |||
//outMaterialMap.put(time,currentWeight[0]); | |||
//方程式里,x是重量,Y才是时间 | |||
points.add(currentWeight[0],time); | |||
} | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
} | |||
}); | |||
} catch (Exception e) { | |||
ToastUtils.error("酱料校准错误 :"+e.getMessage()); | |||
} | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
} | |||
}); | |||
} | |||
//没出错就保存。 | |||
//String result= jzDataToString(outMaterialMap); | |||
activity.runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
new QMUIDialog.MessageDialogBuilder(activity).setTitle("确定要保存该酱料校准结果吗?") | |||
.setCanceledOnTouchOutside(false) | |||
.addAction("确认", new QMUIDialogAction.ActionListener() { | |||
@Override | |||
public void onClick(QMUIDialog dialog, int index) { | |||
//Toast.makeText(activity.getApplicationContext(), "确认", Toast.LENGTH_SHORT).show(); | |||
//region 生成公式 | |||
//公式多项式阶数 | |||
int degree=3; | |||
// 创建 PolynomialCurveFitter 对象,并进行多项式回归拟合 | |||
PolynomialCurveFitter fitter = PolynomialCurveFitter.create(degree); | |||
double[] coefficients = fitter.fit(points.toList()); | |||
// 打印回归方程的系数 | |||
// for (int i = 0; i < coefficients.length; i++) { | |||
// System.out.print(coefficients[i] + " "); | |||
// } | |||
//endregion | |||
dialog.dismiss(); | |||
//lcMode.bcsfValue=result; | |||
QueryDB.UpdateSilosBcsfValue(lcMode.id,String.valueOf(weightLowLimit),String.valueOf(weightHighLimit),String.valueOf(adjFreq)); | |||
//QueryDB.UpdateSilosBcsfValue(lcMode.id, result); | |||
QueryDB.UpdateSilosBcsfValue(lcMode.id, Arrays.toString(coefficients)); | |||
//ToastUtils.success("酱料校准结果保存成功!"); | |||
MessageLog.ShowUserMessage(UserLogEnum.角色操作日志,lcMode.num+"仓位酱料校准结果保存成功。"); | |||
} | |||
}).addAction("取消", new QMUIDialogAction.ActionListener() { | |||
@Override | |||
public void onClick(QMUIDialog dialog, int index) { | |||
//Toast.makeText(activity.getApplicationContext(), "取消", Toast.LENGTH_SHORT).show(); | |||
dialog.dismiss(); | |||
} | |||
}).create(AlertDialogUtils.mCurrentDialogStyle).show(); | |||
} | |||
}); | |||
//ToastUtils.success("酱料校准结束,数据已保存。"); | |||
}catch (Exception ex){ | |||
ToastUtils.error("酱料校准失败:"+ex.getMessage()); | |||
}finally { | |||
activity.runOnUiThread(()->{ | |||
btn_jljz_startAdj.setEnabled(true); | |||
btn_jljz_startAdj.setText("开始校准"); | |||
}); | |||
} | |||
} | |||
}).start(); | |||
@@ -631,20 +845,13 @@ public class silos_jiaoyan extends LinearLayout { | |||
ToastUtils.error("时间异常!" + e.getMessage()); | |||
return; | |||
} | |||
double zhongl= 0; | |||
try { | |||
zhongl=Double.parseDouble(zl); | |||
Double.parseDouble(zl); | |||
} catch (Exception e) { | |||
ToastUtils.error("校准重量获取异常!" + e.getMessage()); | |||
return; | |||
} | |||
if (zhongl <= 0) { | |||
ToastUtils.warning("校准重量至少大于0g!"); | |||
ToastUtils.error("重量异常!" + e.getMessage()); | |||
return; | |||
} | |||
if (!ConfigName.getInstance().versionSelectionEnum.equals("奶茶机")) { | |||
if (ftime.equals("")) { | |||
ToastUtils.warning("反转基准时间不能为空!"); | |||
@@ -656,17 +863,17 @@ public class silos_jiaoyan extends LinearLayout { | |||
ToastUtils.error("时间异常!" + e.getMessage()); | |||
return; | |||
} | |||
ExecuteTheRecipe.WritePLC("反转时间", (short) ftime_1, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
ToastUtils.info("反转时间保存成功!"); | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
ToastUtils.error("反转时间保存失败!"); | |||
} | |||
}); | |||
// ExecuteTheRecipe.WritePLC("反转时间", (short) ftime_1, new IWriteCallBack() { | |||
// @Override | |||
// public void onSuccess() { | |||
// ToastUtils.info("反转时间保存成功!"); | |||
// } | |||
// | |||
// @Override | |||
// public void onFailure(String ErrorMsg) { | |||
// ToastUtils.error("反转时间保存失败!"); | |||
// } | |||
// }); | |||
} | |||
lcMode.fTime=ftime; | |||
lcMode.jTime=stime; | |||
@@ -678,55 +885,71 @@ public class silos_jiaoyan extends LinearLayout { | |||
QueryDB.UpdateSilosJZTime(item.id, stime, ftime); | |||
} | |||
QueryDB.UpdateJYZ(lcMode.id, zl); | |||
ExecuteTheRecipe.WritePLC("基准时间", (short) stime_1, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
ToastUtils.info("校准基准时间保存成功!"); | |||
} | |||
ToastUtils.success("物料校准时间保存成功!"); | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
ToastUtils.error("校准基准时间保存失败!"); | |||
} | |||
}); | |||
int kkk= lcMode.num; | |||
ExecuteTheRecipe.WritePLC("校准值" + kkk, (short) (short) ((int) (zhongl * 10)), null); | |||
// ExecuteTheRecipe.WritePLC("基准时间", (short) stime_1, new IWriteCallBack() { | |||
// @Override | |||
// public void onSuccess() { | |||
// ToastUtils.info("校准基准时间保存成功!"); | |||
// } | |||
// | |||
// @Override | |||
// public void onFailure(String ErrorMsg) { | |||
// ToastUtils.error("校准基准时间保存失败!"); | |||
// } | |||
// }); | |||
} | |||
//endregion | |||
//region 物料校准 | |||
public void WLJZ() { | |||
//判断是否为果糖->判断温度 | |||
if (ConfigName.getInstance().versionSelectionEnum.equals("奶茶机")) { | |||
if (lcMode.num == 11) { | |||
if (ExecuteTheRecipe.SugarTempLeft < ExecuteTheRecipe.SugarTempLeft_SZ) { | |||
ToastUtils.warning("果糖左仓温度未达到设置值,不允许校准..."); | |||
return; | |||
} | |||
} else if (lcMode.num == 12) { | |||
if (ExecuteTheRecipe.SugarTempRight < ExecuteTheRecipe.SugarTempRight_SZ) { | |||
ToastUtils.warning("果糖右仓温度未达到设置值,不允许校准..."); | |||
return; | |||
} | |||
} | |||
//TODO:重写物料校准。 | |||
//region 物料校准--可提取为内部方法 | |||
String stime = wljz1.getText().toString(); | |||
String ftime = wljz2.getText().toString(); | |||
if (stime.equals("")) { | |||
ToastUtils.warning("校准基准时间不能为空!"); | |||
return; | |||
} | |||
final int[] stime_1 = {0}; | |||
try { | |||
stime_1[0] = (int) Math.round((Double.parseDouble(stime))); | |||
} catch (Exception e) { | |||
ToastUtils.error("时间异常!" + e.getMessage()); | |||
return; | |||
} | |||
//endregion | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
try { | |||
ExecuteTheRecipe.WritePLC("校准完成", false, null); | |||
ExecuteTheRecipe.WritePLC("手自切换", false, null); | |||
ExecuteTheRecipe.WritePLC("通道校准", true, new IWriteCallBack() { | |||
ExecuteTheRecipe.isAutoMode=false; | |||
PLCControl.get().openMotor(lcMode.num, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
ToastUtils.info("启动通道校准成功!"); | |||
new Handler(Looper.getMainLooper()).postDelayed(()->{ | |||
PLCControl.get().closeMotor(lcMode.num, new IWriteCallBack() { | |||
@Override | |||
public void onSuccess() { | |||
ToastUtils.info("通道校准完成--请确认重量!"); | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
ToastUtils.error("通道校准---关闭通道失败!"); | |||
} | |||
}); | |||
},stime_1[0]*1000); | |||
} | |||
@Override | |||
public void onFailure(String ErrorMsg) { | |||
ToastUtils.error("启动通道校准失败!"); | |||
ToastUtils.error("通道校准---开启通道失败!"); | |||
} | |||
}); | |||
} catch (Exception e) { | |||
@@ -832,4 +1055,30 @@ public class silos_jiaoyan extends LinearLayout { | |||
} | |||
//endregion | |||
//region 数据校验 | |||
/**物料校准参数校验*/ | |||
private void validateForWLJZ(){ | |||
} | |||
//endregion | |||
/**键值都为Double的HashMap转换为字符串,提供给酱料校准使用。*/ | |||
private String jzDataToString(Map<Double,Double> hashMap){ | |||
String result=""; | |||
if (hashMap.isEmpty()){ | |||
result= ""; | |||
} | |||
StringBuilder stringBuilder=new StringBuilder(); | |||
for (Map.Entry<Double,Double> entry:hashMap.entrySet()){ | |||
stringBuilder.append(entry.getKey()).append(",").append(entry.getValue()).append("|"); | |||
} | |||
if (stringBuilder.length()>0){ | |||
stringBuilder.setLength(stringBuilder.length()-1); | |||
result=stringBuilder.toString(); | |||
} | |||
return result; | |||
} | |||
} |
@@ -32,7 +32,7 @@ | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_gravity="center" | |||
android:layout_margin="5dp"> | |||
android:layout_margin="5dp" android:visibility="gone"> | |||
<com.qmuiteam.qmui.widget.textview.QMUILinkTextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
@@ -69,7 +69,67 @@ | |||
android:textSize="12dp" | |||
android:text="0"/> | |||
</TableRow> | |||
<!--#region 串口参数设置--> | |||
<TableRow | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_gravity="center" | |||
android:layout_margin="5dp"> | |||
<com.qmuiteam.qmui.widget.textview.QMUILinkTextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:gravity="right" | |||
android:text="@string/serialBaudRate" /> | |||
<Spinner | |||
android:id="@+id/serialBaudRate" | |||
style="@style/commonSpinnerStyle" | |||
android:layout_width="80dp" | |||
android:layout_height="24dp" | |||
android:layout_centerVertical="true" /> | |||
<com.qmuiteam.qmui.widget.textview.QMUILinkTextView | |||
android:layout_marginLeft="@dimen/dp_10" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:gravity="right" | |||
android:text="@string/serialDataBits" /> | |||
<Spinner | |||
android:id="@+id/serialDataBits" | |||
style="@style/commonSpinnerStyle" | |||
android:layout_width="80dp" | |||
android:layout_height="24dp" | |||
android:layout_centerVertical="true" /> | |||
</TableRow> | |||
<TableRow | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_gravity="center" | |||
android:layout_margin="5dp"> | |||
<com.qmuiteam.qmui.widget.textview.QMUILinkTextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:gravity="right" | |||
android:text="@string/serialParity" /> | |||
<Spinner | |||
android:id="@+id/serialParity" | |||
style="@style/commonSpinnerStyle" | |||
android:layout_width="80dp" | |||
android:layout_height="24dp" | |||
android:layout_centerVertical="true" /> | |||
<com.qmuiteam.qmui.widget.textview.QMUILinkTextView | |||
android:layout_marginLeft="@dimen/dp_10" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:gravity="right" | |||
android:text="@string/serialStopBits" /> | |||
<Spinner | |||
android:id="@+id/serialStopBits" | |||
style="@style/commonSpinnerStyle" | |||
android:layout_width="80dp" | |||
android:layout_height="24dp" | |||
android:layout_centerVertical="true" /> | |||
</TableRow> | |||
<!--#endregion--> | |||
<!-- Table2--> | |||
<TableRow | |||
android:layout_width="wrap_content" | |||
@@ -136,22 +136,6 @@ | |||
android:textColor="@color/green_primary" | |||
android:textSize="@dimen/TitleSize" /> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_margin="5dp" | |||
android:text="水箱:" | |||
android:textSize="@dimen/TitleSize" /> | |||
<TextView | |||
android:id="@+id/wendu1" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_margin="5dp" | |||
android:text="89.9°C" | |||
android:textColor="@color/green_primary" | |||
android:textSize="@dimen/TitleSize" /> | |||
<TextView | |||
android:id="@+id/cheng_clear" | |||
android:layout_width="wrap_content" | |||
@@ -72,7 +72,7 @@ | |||
</LinearLayout> | |||
</RelativeLayout> | |||
<RelativeLayout | |||
<RelativeLayout android:visibility="gone" | |||
android:id="@+id/wdsz" | |||
android:layout_width="0dp" | |||
android:layout_height="match_parent" | |||
@@ -9,6 +9,7 @@ | |||
android:clickable="true"> | |||
<RelativeLayout | |||
android:id="@+id/menu_silo" | |||
android:layout_centerInParent="true" | |||
android:layout_margin="20dp" | |||
android:layout_width="400dp" | |||
@@ -148,6 +149,7 @@ | |||
android:textSize="18sp"/> | |||
<Button | |||
android:visibility="gone" | |||
android:layout_marginTop="@dimen/dp_10" | |||
android:id="@+id/control_huishou" | |||
android:layout_width="60dp" | |||
@@ -340,6 +342,7 @@ | |||
android:layout_width="400dp" | |||
android:layout_height="400dp" | |||
android:orientation="horizontal" | |||
android:focusable="true" | |||
android:background="@drawable/common_bg_with_radius_and_border"> | |||
<LinearLayout | |||
android:layout_centerInParent="true" | |||
@@ -721,9 +721,9 @@ | |||
android:layout_centerInParent="true" | |||
android:fontFamily="sans-serif-medium" | |||
android:text="128.0g" | |||
android:textColor="@color/white" | |||
android:textSize="20dp" | |||
android:textStyle="bold|italic" | |||
android:textColor="@color/white"/> | |||
android:textStyle="bold|italic" /> | |||
</RelativeLayout> | |||
<RelativeLayout | |||
android:layout_marginTop="10dp" | |||
@@ -485,6 +485,7 @@ | |||
android:textAlignment="center" | |||
android:textSize="16dp"/> | |||
<EditText | |||
android:id="@+id/txt_jljz_lowLimit" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_centerInParent="true" | |||
@@ -508,6 +509,7 @@ | |||
android:background="@color/color3"/> | |||
</RelativeLayout> | |||
<EditText | |||
android:id="@+id/txt_jljz_highLimit" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_centerInParent="true" | |||
@@ -531,11 +533,12 @@ | |||
android:textSize="16dp" | |||
/> | |||
<EditText | |||
android:id="@+id/txt_jljz_adjFreq" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_centerInParent="true" | |||
android:background="@drawable/input_bj" | |||
android:digits="0123456789." | |||
android:digits="0123456789" | |||
android:hint="请输入" | |||
android:inputType="text" | |||
android:maxLines="1" | |||
@@ -545,6 +548,7 @@ | |||
android:layout_marginBottom="10dp" | |||
/> | |||
<Button | |||
android:id="@+id/btn_jljz_startAdj" | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:layout_centerHorizontal="true" | |||
@@ -646,20 +650,20 @@ | |||
/> | |||
</LinearLayout> | |||
<RelativeLayout | |||
android:focusable="true" | |||
android:clickable="true" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:background="#BE000000"> | |||
<TextView | |||
android:layout_centerInParent="true" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="研发中..." | |||
android:textSize="40dp" | |||
android:textColor="#DA1CD7"></TextView> | |||
</RelativeLayout> | |||
<!-- <RelativeLayout--> | |||
<!-- android:focusable="true"--> | |||
<!-- android:clickable="true"--> | |||
<!-- android:layout_width="match_parent"--> | |||
<!-- android:layout_height="match_parent"--> | |||
<!-- android:background="#BE000000">--> | |||
<!-- <TextView--> | |||
<!-- android:layout_centerInParent="true"--> | |||
<!-- android:layout_width="wrap_content"--> | |||
<!-- android:layout_height="wrap_content"--> | |||
<!-- android:text="研发中..."--> | |||
<!-- android:textSize="40dp"--> | |||
<!-- android:textColor="#DA1CD7"></TextView>--> | |||
<!-- </RelativeLayout>--> | |||
</RelativeLayout> | |||
</LinearLayout> | |||
@@ -0,0 +1,44 @@ | |||
<resources> | |||
<string name="app_name">菠萝智慧吧</string> | |||
<string name="file_normal">normal</string> | |||
<string name="file_all">all files</string> | |||
<string name="empty_data">empty data</string> | |||
<string name="not_available">sd card not avaliable</string> | |||
<string name="already_select">selected:%s</string> | |||
<string name="file_select_res">确定%s</string> | |||
<string name="file_select_max">最多选择%d个文件</string> | |||
<string name="file_select_res1">Save locally%s</string> | |||
<string name="welcome_use">Welcome!</string> | |||
<string name="user_account">Please enter username</string> | |||
<string name="user_password">Please enter password</string> | |||
<string name="remember_pwd">Remember you</string> | |||
<string name="forget_pwd">Forget password?</string> | |||
<string name="login">Login</string> | |||
<string name="menu_func">Function</string> | |||
<string name="menu_func_siloManagement">SilosManage</string> | |||
<string name="menu_func_RecipeManagement">RecipeManage</string> | |||
<string name="menu_func_LogManagement">LogManage</string> | |||
<string name="menu_func_BaseDataManagement">BaseDataManage</string> | |||
<string name="menu_func_RealTimeMonitorManagement">RealTimeMonitorManage</string> | |||
<string name="app_initing">Software initialization in progress, please wait...</string> | |||
<string name="func_one_button_full_pipe">Full Pipe</string> | |||
<string name="func_one_button_full_tank">Set Full Tank</string> | |||
<string name="func_one_button_clean">Clean Pipe</string> | |||
<string name="func_one_button_setup">Set Silo Info</string> | |||
<string name="func_msg_one">Click on the silo icon to configure or control the silo</string> | |||
<string name="func_msg_two">A warning will be triggered when the material in the silo falls below the minimum level.</string> | |||
<string name="serialBaudRate">SerialBaudRate:</string> | |||
<string name="serialDataBits">SerialDataBits:</string> | |||
<string name="serialParity">SerialParity:</string> | |||
<string name="serialStopBits">SerialStopBits:</string> | |||
</resources> |
@@ -9,13 +9,38 @@ | |||
<string name="file_select_max">最多选择%d个文件</string> | |||
<string name="file_select_res1">保存本地%s</string> | |||
<!-- TODO: Remove or change this placeholder text --> | |||
<string name="welcome_use">欢迎使用</string> | |||
<string name="user_account">请输入用户名</string> | |||
<string name="user_password">请输入密码</string> | |||
<string name="remember_pwd">记住密码</string> | |||
<string name="forget_pwd">忘记密码?</string> | |||
<string name="login">登录</string> | |||
<!--#region 菜单--> | |||
<!--#region 菜单——功能 --> | |||
<string name="menu_func">功能</string> | |||
<string name="menu_func_siloManagement">料仓管理(绑定物料)</string> | |||
<string name="menu_func_RecipeManagement">配方管理</string> | |||
<string name="menu_func_LogManagement">日志管理</string> | |||
<string name="menu_func_BaseDataManagement">基础数据管理</string> | |||
<string name="menu_func_RealTimeMonitorManagement">实时监控管理</string> | |||
<!--#endregion--> | |||
<!-- TODO: 系统设置 --> | |||
<!-- TODO: 物料表格设置 --> | |||
<!--#endregion--> | |||
<string name="serialBaudRate">串口波特率:</string> | |||
<string name="serialDataBits">串口数据位:</string> | |||
<string name="serialParity">串口校验位:</string> | |||
<string name="serialStopBits">串口停止位:</string> | |||
<string name="app_initing">软件初始化加载中,请稍候...</string> | |||
<string name="func_one_button_full_pipe">一键满管</string> | |||
<string name="func_one_button_full_tank">一键加满</string> | |||
<string name="func_one_button_clean">一键清洗</string> | |||
<string name="func_one_button_setup">一键设置</string> | |||
<string name="func_msg_one">点击料仓图形设置或控制料仓</string> | |||
<string name="func_msg_two">料仓物料低于最低值会警示</string> | |||
</resources> |