@@ -160,4 +160,8 @@ dependencies { | |||
// implementation files('libs\\org.eclipse.paho.client.mqttv3-1.2.5.jar') | |||
//S7系列 PLC读取 | |||
implementation 'com.github.s7connector:s7connector:2.0' | |||
} |
@@ -30,7 +30,6 @@ import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback; | |||
import com.bonait.bnframework.common.image.utils.LocalCacheUtils; | |||
import com.bonait.bnframework.common.message.MessageManager; | |||
import com.bonait.bnframework.common.modbus.ModbusTcpHelper; | |||
import com.bonait.bnframework.common.modbus.ModbusTcpMainHelper; | |||
import com.bonait.bnframework.common.modbus.ModbusTcpServer; | |||
import com.bonait.bnframework.common.model.ResAPI; | |||
import com.bonait.bnframework.common.model.mode.ActionJsonMode; | |||
@@ -1155,12 +1154,6 @@ public class ConfigData { | |||
public void ColsePLC() { | |||
ModbusTcpHelper.get().release();//释放modbus | |||
ConfigName.getInstance().PlcIsConnect = false; | |||
if(ConfigName.getInstance().versionSelectionEnum.contains("一拖")) | |||
{ | |||
ModbusTcpMainHelper.get().release();//释放modbus | |||
ConfigName.getInstance().PlcMainIsConnect = false; | |||
} | |||
} | |||
/** | |||
@@ -1170,14 +1163,6 @@ public class ConfigData { | |||
//PLC连接成功,启动数据监听 | |||
ExecuteTheRecipe.Listening(); | |||
} | |||
/** | |||
* PLC主控初始化完成时,需要注册的服务 | |||
*/ | |||
public void MainPLC_Init() { | |||
//PLC连接成功,启动数据监听 | |||
ExecuteTheRecipe.MainListening(); | |||
} | |||
//endregion | |||
} | |||
@@ -26,8 +26,6 @@ import com.bonait.bnframework.common.helper.I.IMessageLogNotify; | |||
import com.bonait.bnframework.common.helper.MessageLog; | |||
import com.bonait.bnframework.common.helper.SdCart; | |||
import com.bonait.bnframework.common.modbus.ModbusTcpHelper; | |||
import com.bonait.bnframework.common.modbus.ModbusTcpMainHelper; | |||
import com.bonait.bnframework.common.modbus.ModbusTcpMainServer; | |||
import com.bonait.bnframework.common.notification.MainNotification; | |||
import com.bonait.bnframework.common.utils.AppUtils; | |||
import com.bonait.bnframework.common.utils.NetworkUtils; | |||
@@ -259,14 +257,14 @@ public class MainInit { | |||
{ | |||
if(msg.contains("主设备")) | |||
{ | |||
ModbusTcpMainHelper.get().release();//释放modbus | |||
ConfigName.getInstance().PlcMainIsConnect=false; | |||
BPA_ALERTLOG log = new BPA_ALERTLOG(); | |||
log.userID = ConfigName.getInstance().user.userID; | |||
log.type=4; | |||
log.text = msg+"主程序断开PLC,准备重连机制..."; | |||
QueryDB.AddAlertlog(log); | |||
Log.e("主控PLC", "主控PLC: 连接断开"); | |||
// ModbusTcpMainHelper.get().release();//释放modbus | |||
// ConfigName.getInstance().PlcMainIsConnect=false; | |||
// BPA_ALERTLOG log = new BPA_ALERTLOG(); | |||
// log.userID = ConfigName.getInstance().user.userID; | |||
// log.type=4; | |||
// log.text = msg+"主程序断开PLC,准备重连机制..."; | |||
// QueryDB.AddAlertlog(log); | |||
// Log.e("主控PLC", "主控PLC: 连接断开"); | |||
}else if(msg.contains("PLC设备")) | |||
{ | |||
@@ -48,7 +48,7 @@ public class ConfigName { | |||
public Context dishesCon; | |||
public Context Home; | |||
public Application app; | |||
public boolean IsPortraitScreen=true;//是否竖屏 | |||
public boolean IsPortraitScreen = true;//是否竖屏 | |||
//endregion | |||
//region SD卡路径设置 | |||
@@ -413,6 +413,7 @@ public class ConfigName { | |||
public List<ProcessT> Process_燃气大炒 = new ArrayList<ProcessT>() {{ | |||
add(new ProcessT("搅拌", Arrays.asList("搅拌速度", "等待(秒)"))); | |||
add(new ProcessT("打火", Arrays.asList("打火动作", "等待(秒)"))); | |||
add(new ProcessT("位置", Arrays.asList("位置动作", "等待(秒)"))); | |||
add(new ProcessT("约束条件", Arrays.asList("一环功率", "二环功率", "三环功率", "四环功率", "温度设定", "锅内重量", "等待(秒)"))); | |||
add(new ProcessT("主料", Arrays.asList("主料名称", "一环功率", "二环功率", "三环功率", "四环功率", "温度设定", "锅内重量", "烹饪(秒)"))); | |||
add(new ProcessT("物料", Arrays.asList())); | |||
@@ -420,32 +421,6 @@ public class ConfigName { | |||
add(new ProcessT("出菜", Arrays.asList("等待(秒)"))); | |||
add(new ProcessT("清洗", Arrays.asList("等待(秒)"))); | |||
}}; | |||
/** | |||
* 主控地址列表 | |||
*/ | |||
public ConcurrentHashMap<String, Integer> MainPlcAddress = new ConcurrentHashMap<String, Integer>() {{ | |||
put("炒锅空闲状态",1); //实时 | |||
put("炒锅出餐完成",2); | |||
put("炒锅投主料完成",3);//准备就绪,开始烹饪 | |||
put("炒锅请求投辅料",4); | |||
put("商品数据验证",5); | |||
put("投料机构状态",6); //实时 | |||
put("心跳",7); //实时 | |||
put("炒菜完成请求出餐",8); | |||
put("炒锅出餐减速到位",9); //实时 | |||
put("炒锅请求投主料",10); | |||
put("强制结束任务完成",11);//炒锅反馈强制结束任务完成 | |||
put("机器人准备就绪",51);//修改就绪信号 | |||
put("机器人放辅料完成",52); | |||
put("机器人到达炒锅出餐位",53); | |||
put("商品下发",54); | |||
put("机器人急停",55);//true 异常 false 正常 | |||
put("机器人投放主料完成",56); | |||
put("强制结束任务",57); | |||
put("商品信息",0); | |||
}}; | |||
/** | |||
* 根据名称获取变量 | |||
@@ -457,8 +432,8 @@ public class ConfigName { | |||
String data = ""; | |||
if (item.equals("打火动作")) { | |||
data = "自动打火、手动打火"; | |||
} else if (item.equals("投料动作")) { | |||
data = "投出等待三秒、直接投出、手动投料"; | |||
} else if (item.equals("位置动作")) { | |||
data = "炒菜位、倒菜位、清洗位"; | |||
} | |||
return data; | |||
} | |||
@@ -503,15 +478,15 @@ public class ConfigName { | |||
/** | |||
* 最大火力级别 | |||
*/ | |||
public String HuoLi="八档"; | |||
public String HuoLi = "八档"; | |||
/** | |||
* 最大温度:默认温度 | |||
*/ | |||
public int MaxTemp=200; | |||
public int MaxTemp = 200; | |||
/** | |||
* 是否打开火力 | |||
*/ | |||
public boolean IsOpenHuoLi=false; | |||
public boolean IsOpenHuoLi = false; | |||
//endregion | |||
/** | |||
* 炒锅状态上报信息 | |||
@@ -651,7 +626,7 @@ public class ConfigName { | |||
/** | |||
* 料仓显示物料 | |||
*/ | |||
public ConcurrentHashMap<Integer,String > SilosDisplayMaterial = new ConcurrentHashMap<Integer,String >() {{ | |||
public ConcurrentHashMap<Integer, String> SilosDisplayMaterial = new ConcurrentHashMap<Integer, String>() {{ | |||
put(1, "未设置"); | |||
put(2, "未设置"); | |||
put(3, "未设置"); | |||
@@ -1,43 +0,0 @@ | |||
package com.bonait.bnframework.common.modbus; | |||
import com.licheedev.modbus4android.ModbusWorker; | |||
import com.serotonin.modbus4j.ModbusMaster; | |||
public class ModbusTcpMainHelper extends ModbusWorker { | |||
private static volatile ModbusTcpMainHelper instance = null; | |||
public static ModbusTcpMainHelper get() { | |||
ModbusTcpMainHelper manager = instance; | |||
if (manager == null) { | |||
synchronized (ModbusTcpMainHelper.class) { | |||
manager = instance; | |||
if (manager == null) { | |||
manager = new ModbusTcpMainHelper(); | |||
instance = manager; | |||
} | |||
} | |||
} | |||
return manager; | |||
} | |||
private ModbusTcpMainHelper() { | |||
} | |||
/** | |||
* 释放整个ModbusManager,单例会被置null | |||
*/ | |||
public synchronized void release() { | |||
super.release(); | |||
instance = null; | |||
} | |||
/** | |||
* 获取 | |||
* @return | |||
*/ | |||
public synchronized ModbusMaster getModbusMaster() | |||
{ | |||
return super.getModbusMaster(); | |||
} | |||
} |
@@ -1,723 +0,0 @@ | |||
package com.bonait.bnframework.common.modbus; | |||
import android.util.Log; | |||
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.bonait.bnframework.common.utils.ToastUtils; | |||
import com.licheedev.modbus4android.ModbusCallback; | |||
import com.licheedev.modbus4android.ModbusParam; | |||
import com.licheedev.modbus4android.ModbusRespException; | |||
import com.licheedev.modbus4android.param.TcpParam; | |||
import com.serotonin.modbus4j.ModbusMaster; | |||
import com.serotonin.modbus4j.exception.ModbusInitException; | |||
import com.serotonin.modbus4j.exception.ModbusTransportException; | |||
import com.serotonin.modbus4j.msg.ReadCoilsResponse; | |||
import com.serotonin.modbus4j.msg.ReadHoldingRegistersResponse; | |||
import java.io.IOException; | |||
import java.io.InputStreamReader; | |||
import java.io.LineNumberReader; | |||
import java.io.UnsupportedEncodingException; | |||
import java.nio.ByteBuffer; | |||
import java.util.Arrays; | |||
import java.util.concurrent.ExecutionException; | |||
/** | |||
* 主控Tcp服务 | |||
*/ | |||
public class ModbusTcpMainServer { | |||
private static volatile ModbusTcpMainServer instance = null; | |||
public static ModbusTcpMainServer get() { | |||
ModbusTcpMainServer manager = instance; | |||
if (manager == null) { | |||
synchronized (ModbusTcpMainServer.class) { | |||
manager = instance; | |||
if (manager == null) { | |||
manager = new ModbusTcpMainServer(); | |||
instance = manager; | |||
} | |||
} | |||
} | |||
return manager; | |||
} | |||
private ModbusTcpMainServer() { | |||
} | |||
static ModbusParam param; | |||
private int GetAddress(String address) { | |||
if (address == null) return -1; | |||
if (address.length() > 0) { | |||
address = address.trim(); | |||
// if (address.toUpperCase().contains("M") && address.length() >= 4) { | |||
// String[] res = address.substring(1).split("[.]"); | |||
// if (res != null && res.length == 2) { | |||
// try { | |||
// int firstAdd = Integer.parseInt(res[0]); | |||
// int endAdd = Integer.parseInt(res[1]); | |||
// if (endAdd >= 0 && endAdd <= 7) { | |||
// return (firstAdd * 8) + 320 + endAdd; | |||
// } | |||
// } catch (NumberFormatException e) { | |||
// return -1; | |||
// } | |||
// } | |||
// } else if (address.toUpperCase().contains("I") && address.length() >= 4) { | |||
// String[] res = address.substring(1).split("[.]"); | |||
// if (res != null && res.length == 2) { | |||
// try { | |||
// int firstAdd = Integer.parseInt(res[0]); | |||
// int endAdd = Integer.parseInt(res[1]); | |||
// if (endAdd >= 0 && endAdd <= 7) { | |||
// return (firstAdd * 8) + endAdd; | |||
// } | |||
// } catch (NumberFormatException e) { | |||
// return -1; | |||
// } | |||
// } | |||
// } else if ((address.toUpperCase().contains("VW") || address.toUpperCase().contains("VD")) && address.length() >= 3) { | |||
// String res = address.substring(2); | |||
// if (res != null) { | |||
// try { | |||
// int tempAdd = Integer.parseInt(res); | |||
// return (tempAdd / 2) + 100; | |||
// } catch (NumberFormatException e) { | |||
// return -1; | |||
// } | |||
// } | |||
// } else { | |||
// try { | |||
// return Integer.parseInt(address); | |||
// } catch (NumberFormatException e) { | |||
// return -1; | |||
// } | |||
// } | |||
try { | |||
return Integer.parseInt(address); | |||
} catch (NumberFormatException e) { | |||
return -1; | |||
} | |||
} | |||
return -1; | |||
} | |||
/** | |||
* 获取布尔位地址信息 | |||
* 列:M2.5 = getBitSingleAdd("M",2,5); | |||
* | |||
* @param Prefix 地址标头 | |||
* @param startAdd 起始地址编号 | |||
* @param num 要获取的第几位数量 | |||
* @return | |||
*/ | |||
public String getBitSingleAdd(String Prefix, int startAdd, int num) { | |||
if (num > 0) { | |||
int FirstAdd = num / 8; | |||
int EndAdd = num % 8; | |||
if (EndAdd == 0) { | |||
FirstAdd--; | |||
EndAdd = 7; | |||
} else { | |||
EndAdd--; | |||
} | |||
return Prefix + FirstAdd + startAdd + "." + EndAdd; | |||
} | |||
return ""; | |||
} | |||
/** | |||
* Ping PLC地址是否通畅 | |||
* @param address | |||
* @param pingTimes ping的次数 | |||
* @param timeOut 超时时间 10 | |||
* @return | |||
*/ | |||
public static boolean ping2(String address, int pingTimes, int timeOut) { | |||
Process process = null; | |||
try { | |||
process = Runtime.getRuntime().exec( "ping " + "-c " + pingTimes + " -w " + timeOut+ " "+address); | |||
InputStreamReader r = new InputStreamReader(process.getInputStream()); | |||
LineNumberReader returnData = new LineNumberReader(r); | |||
String returnMsg=""; | |||
String line = ""; | |||
while ((line = returnData.readLine()) != null) { | |||
System.out.println(line); | |||
returnMsg += line; | |||
} | |||
if(returnMsg.indexOf("100% packet loss")!=-1){ | |||
System.out.println("与 " +address +" 连接不畅通."); | |||
//ToastUtils.info("与 " +address +" 连接不畅通."); | |||
return false; | |||
} else{ | |||
System.out.println("与 " +address +" 连接畅通."); | |||
//ToastUtils.info("与 " +address +" 连接不畅通."); | |||
return true; | |||
} | |||
} catch (IOException e) { | |||
// e.printStackTrace(); | |||
} | |||
return false; | |||
} | |||
/** | |||
* 连接PLC | |||
*/ | |||
public static void ConnectPLC() | |||
{ | |||
String host=ConfigName.getInstance().MainAddress; | |||
int port=ConfigName.getInstance().MainPost; | |||
param = TcpParam.create(host, port) | |||
.setTimeout(1000) | |||
.setRetries(0) | |||
.setEncapsulated(false) | |||
.setKeepAlive(true); | |||
ModbusTcpMainHelper.get().init(param, new ModbusCallback<ModbusMaster>() { | |||
@Override | |||
public void onSuccess(ModbusMaster modbusMaster) { | |||
ToastUtils.info("设备 " + ConfigName.getInstance().MainAddress + " 连接成功"); | |||
MessageLog.ShowInfo("设备 " + ConfigName.getInstance().MainAddress + " 连接成功"); | |||
ConfigName.getInstance().PlcMainIsConnect = true; | |||
ConfigData.getInstance().MainPLC_Init(); | |||
Log.e("主控PLC", "主控PLC: 连接成功"); | |||
} | |||
@Override | |||
public void onFailure(Throwable tr) { | |||
ConfigName.getInstance().PlcMainIsConnect = false; | |||
ToastUtils.info("设备 " + ConfigName.getInstance().MainAddress + " 连接失败:" + tr.getMessage()); | |||
MessageLog.ShowError("主设备 " + ConfigName.getInstance().MainAddress + " 连接失败:" + tr.getMessage()); | |||
Log.e("主控PLC", "主控PLC: 连接断开"); | |||
} | |||
@Override | |||
public void onFinally() { | |||
} | |||
}); | |||
} | |||
private Float BytesToFloat(byte[] buffers, DataFormat df) { | |||
if (buffers.length == 4) { | |||
byte[] bytes = new byte[4]; | |||
if (df == DataFormat.ABCD) { | |||
bytes[0] = buffers[3]; | |||
bytes[1] = buffers[2]; | |||
bytes[2] = buffers[1]; | |||
bytes[3] = buffers[0]; | |||
} else if (df == DataFormat.CDAB) { | |||
bytes[0] = buffers[1]; | |||
bytes[1] = buffers[0]; | |||
bytes[2] = buffers[3]; | |||
bytes[3] = buffers[2]; | |||
} else if (df == DataFormat.BADC) { | |||
bytes[0] = buffers[2]; | |||
bytes[1] = buffers[3]; | |||
bytes[2] = buffers[0]; | |||
bytes[3] = buffers[1]; | |||
} else if (df == DataFormat.DCBA) { | |||
bytes[0] = buffers[0]; | |||
bytes[1] = buffers[1]; | |||
bytes[2] = buffers[2]; | |||
bytes[3] = buffers[3]; | |||
} | |||
return ByteBuffer.wrap(bytes).getFloat(); | |||
} | |||
return 0.0f; | |||
} | |||
private Integer BytesToInt(byte[] buffers, DataFormat df) { | |||
if (buffers.length == 4) { | |||
byte[] bytes = new byte[4]; | |||
if (df == DataFormat.ABCD) { | |||
bytes[0] = buffers[3]; | |||
bytes[1] = buffers[2]; | |||
bytes[2] = buffers[1]; | |||
bytes[3] = buffers[0]; | |||
} else if (df == DataFormat.CDAB) { | |||
bytes[0] = buffers[1]; | |||
bytes[1] = buffers[0]; | |||
bytes[2] = buffers[3]; | |||
bytes[3] = buffers[2]; | |||
} else if (df == DataFormat.BADC) { | |||
bytes[0] = buffers[2]; | |||
bytes[1] = buffers[3]; | |||
bytes[2] = buffers[0]; | |||
bytes[3] = buffers[1]; | |||
} else if (df == DataFormat.DCBA) { | |||
bytes[0] = buffers[0]; | |||
bytes[1] = buffers[1]; | |||
bytes[2] = buffers[2]; | |||
bytes[3] = buffers[3]; | |||
} | |||
return ByteBuffer.wrap(bytes).getInt(); | |||
} | |||
return 0; | |||
} | |||
private byte[] IntToByte(int number) { | |||
int temp = number; | |||
byte[] b = new byte[4]; | |||
for (int i = 0; i < b.length; i++) { | |||
b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位 | |||
temp = temp >> 8; // 向右移8位 | |||
} | |||
return b; | |||
} | |||
private short[] IntToShorts(int value) { | |||
short[] res = new short[2]; | |||
int temp = value; | |||
byte[] b = new byte[4]; | |||
for (int i = 0; i < b.length; i++) { | |||
b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位 | |||
temp = temp >> 8; // 向右移8位 | |||
} | |||
for (int i = 0; i < res.length; i++) { | |||
short s0 = (short) (b[i * 2] & 0xff);// 最低位 | |||
short s1 = (short) (b[i * 2 + 1] & 0xff); | |||
s1 <<= 8; | |||
res[i] = (short) (s0 | s1); | |||
} | |||
return res; | |||
} | |||
public static String GetString(short[] src, int start, int len) throws UnsupportedEncodingException { | |||
short[] temp = new short[len]; | |||
for (int i = 0; i < len; i++) { | |||
temp[i] = src[i + start]; | |||
} | |||
byte[] bytesTemp = shorts2Bytes(temp); | |||
for (int i = 0; i < bytesTemp.length; i++) { | |||
byte b = bytesTemp[i]; | |||
} | |||
String str = new String(bytesTemp, "UTF-8"); | |||
return str; | |||
} | |||
public static byte[] shorts2Bytes(short[] data) { | |||
byte[] byteValue = new byte[data.length * 2]; | |||
for (int i = 0; i < data.length; i++) { | |||
byteValue[i * 2] = (byte) (data[i] & 0xff); | |||
byteValue[i * 2 + 1] = (byte) ((data[i] & 0xff00) >> 8); | |||
} | |||
return byteValue; | |||
} | |||
/*** | |||
*读取实时状态 | |||
* @param Address the address | |||
* @param length 读取的长度 3 | |||
* @param callback 读取成功的回调 | |||
*/ | |||
public void ReadStatus(String Address, int length, IReadCallBack<byte[]> callback) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
try { | |||
ReadHoldingRegistersResponse res = ModbusTcpMainHelper.get().syncReadHoldingRegisters(1, add, length); | |||
byte[] data = res.getData(); | |||
byte[] tempData = new byte[6]; | |||
tempData[0] = data[1]; | |||
tempData[1] = data[0]; | |||
if (callback != null) callback.onSuccess(tempData); | |||
} 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()); | |||
} | |||
} | |||
/*** | |||
*读取扫码数据 | |||
* @param Address the address | |||
* @param length 读取的长度 | |||
* @param callback 读取成功的回调 | |||
*/ | |||
public void ReadString(String Address, int length, IReadCallBack<String> callback) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
try { | |||
ReadHoldingRegistersResponse res = ModbusTcpMainHelper.get().syncReadHoldingRegisters(1, add, length); | |||
byte[] data = res.getData(); | |||
byte[] data1 = Arrays.copyOfRange(data, 0, length); | |||
//36 GUID 18 Number | |||
String id = ""; | |||
try { | |||
byte[] tempdata = new byte[length]; | |||
for (int i = 0; i < data1.length; i++) { | |||
if (i % 2 == 0) { | |||
tempdata[i + 1] = data1[i]; | |||
} else { | |||
tempdata[i - 1] = data1[i]; | |||
} | |||
} | |||
id = new String(tempdata, "UTF-8").trim(); | |||
} catch (UnsupportedEncodingException ex) { | |||
} | |||
if (callback != null) callback.onSuccess(id); | |||
} 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 WriteString(String Address, int length, IWriteCallBack callback) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
short[] send = new short[length]; | |||
for (short item : send) { | |||
item = 0; | |||
} | |||
try { | |||
ModbusTcpMainHelper.get().syncWriteRegisters(1, 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 ReadShort(String Address, int length, IReadCallBack<short[]> callback) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
try { | |||
ReadHoldingRegistersResponse res = ModbusTcpMainHelper.get().syncReadHoldingRegisters(1, add, 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 ReadBool(String Address, int length, IReadCallBack<boolean[]> callback) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
try { | |||
ReadCoilsResponse res = ModbusTcpMainHelper.get().syncReadCoil(1, add, length); | |||
boolean[] data = res.getBooleanData(); | |||
boolean[] result = Arrays.copyOfRange(data, 0, length); | |||
if (result.length == length) { | |||
if (callback != null) callback.onSuccess(result); | |||
} | |||
} 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()); | |||
} | |||
} | |||
public void ReadFloat(String Address, int length, IReadCallBack<float[]> callback) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
try { | |||
ReadHoldingRegistersResponse res = ModbusTcpMainHelper.get().syncReadHoldingRegisters(1, add, length); | |||
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.ABCD); | |||
} | |||
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 ReadInt(String Address, int length, IReadCallBack<int[]> callback) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
try { | |||
ReadHoldingRegistersResponse res = ModbusTcpMainHelper.get().syncReadHoldingRegisters(1, add, length * 2); | |||
byte[] data = res.getData(); | |||
int[] tempValues = new int[length]; | |||
if(data.length>=4) | |||
{ | |||
for (int i = 0; i < length; i++) { | |||
byte[] tempData = new byte[4]; | |||
for (int m = 0; m < 4; m++) { | |||
tempData[m] = data[i * 4 + m]; | |||
} | |||
// Integer a1 = tempValues[i] = BytesToInt(tempData, DataFormat.ABCD); | |||
// Integer a2 = tempValues[i] = BytesToInt(tempData, DataFormat.BADC); | |||
// Integer a3 = tempValues[i] = BytesToInt(tempData, DataFormat.CDAB); | |||
// Integer a4 = tempValues[i] = BytesToInt(tempData, DataFormat.DCBA); | |||
tempValues[i] = BytesToInt(tempData, DataFormat.BADC); | |||
} | |||
}else | |||
{ | |||
MessageLog.ShowError("ReadInt onFailure,Address=" ); | |||
} | |||
if (callback != null) callback.onSuccess(tempValues); | |||
} 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(String Address, short Value, IWriteCallBack callback) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
short[] send = new short[1]; | |||
send[0] = Value; | |||
try { | |||
ModbusTcpMainHelper.get().syncWriteRegisters(1, add, 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 WriteBool(String Address, boolean Value, IWriteCallBack callback) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
try { | |||
ModbusTcpMainHelper.get().syncWriteCoil(1, add, 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(String Address, float Value, IWriteCallBack callback) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
int intBits = Float.floatToRawIntBits(Value); | |||
short[] send = new short[]{(short) ((intBits >> 16) & 0xffff), (short) (intBits & 0xffff)}; | |||
try { | |||
ModbusTcpMainHelper.get().syncWriteRegisters(1, add, 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(String Address, int Value, IWriteCallBack callback) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
short[] send = IntToShorts(Value); | |||
try { | |||
ModbusTcpMainHelper.get().syncWriteRegisters(1, add, 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(String Address, short Value) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
short[] send = new short[1]; | |||
send[0] = Value; | |||
try { | |||
ModbusTcpMainHelper.get().syncWriteRegisters(1, add, 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(String Address, boolean Value) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
try { | |||
ModbusTcpMainHelper.get().syncWriteCoil(1, add, 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(String Address, float Value) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
int intBits = Float.floatToRawIntBits(Value); | |||
short[] send = new short[]{(short) ((intBits >> 16) & 0xffff), (short) (intBits & 0xffff)}; | |||
try { | |||
ModbusTcpMainHelper.get().syncWriteRegisters(1, add, 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(String Address, int Value) { | |||
int add = GetAddress(Address); | |||
if (add < 0) return; | |||
short[] send = IntToShorts(Value); | |||
try { | |||
ModbusTcpMainHelper.get().syncWriteRegisters(1, add, 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()); | |||
} | |||
} | |||
} |
@@ -0,0 +1,15 @@ | |||
package com.bonait.bnframework.common.modbus.S7; | |||
import com.bonait.bnframework.common.modbus.S7.mode.MyGunData; | |||
import java.io.IOException; | |||
public interface IS7ConnHelper { | |||
void initConnect() throws IOException; | |||
Object readPlcData(Integer dbNum, Class<?> clazz, int offSet); | |||
MyGunData readTheDbData(Integer dbNum, MyGunData clazz, int offSet); | |||
void writePlcData(Integer dbNum, MyGunData clazz, int offSet); | |||
//DB,DB号,偏移量,Byte数组 | |||
void writePlcByte(byte[] bytes); | |||
} |
@@ -0,0 +1,136 @@ | |||
package com.bonait.bnframework.common.modbus.S7; | |||
import android.util.Log; | |||
import com.bonait.bnframework.common.modbus.S7.mode.MyGunData; | |||
import com.bonait.bnframework.common.modbus.S7.mode.MyS7Entity; | |||
import com.github.s7connector.api.DaveArea; | |||
import com.github.s7connector.api.S7Connector; | |||
import com.github.s7connector.api.S7Serializer; | |||
import com.github.s7connector.api.factory.S7ConnectorFactory; | |||
import com.github.s7connector.api.factory.S7SerializerFactory; | |||
import java.io.IOException; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* S7系列读取 | |||
*/ | |||
public class S7ConnHelper implements IS7ConnHelper { | |||
/** | |||
* ip | |||
*/ | |||
public String Ip = "192.168.0.12"; | |||
/** | |||
* 端口 | |||
*/ | |||
public Integer Port = 102; | |||
public S7Connector s7Connector; | |||
public S7Serializer s7Serializer; | |||
public MyS7Entity myDbData; //S7数据返回 | |||
private List<MyS7Entity> myDbDatas = new ArrayList<MyS7Entity>(); | |||
public Boolean isConnected = false; | |||
private Boolean heart = false; | |||
public Map<String,Object> myMap = new HashMap<>(); | |||
@Override | |||
public void initConnect() throws IOException { | |||
if (this.s7Connector == null) { | |||
this.s7Connector = S7ConnectorFactory.buildTCPConnector() | |||
.withHost(Ip) | |||
.withPort(Port) | |||
.withRack(0)//机架号 | |||
.withSlot(1)//插槽号 | |||
.build(); | |||
this.s7Serializer = S7SerializerFactory.buildSerializer(s7Connector); | |||
this.isConnected = true; | |||
} | |||
} | |||
/** | |||
* @param dbNum DB号 | |||
* @param clazz 变量 | |||
* @param offSet 偏移量 | |||
*/ | |||
@Override | |||
public Object readPlcData(Integer dbNum, Class<?> clazz, int offSet) { | |||
//第一个参数:DaveArea.DB 表示读取PLC的地址区域为DB | |||
//第二个参数:DB块地址,若plc中是DB1000,则填1000 | |||
//第三个参数:数据长度 | |||
//第四个参数:偏移量 | |||
if (this.isConnected = true) { | |||
this.myDbData = (MyS7Entity) this.s7Serializer.dispense(clazz, dbNum, offSet); | |||
//心跳 | |||
if (heart == false) { | |||
this.myDbData.heartBeat = 10; | |||
heart = true; | |||
} else if (heart == true) { | |||
this.myDbData.heartBeat = 20; | |||
heart = false; | |||
} | |||
try { | |||
this.s7Serializer.store(this.myDbData, dbNum, offSet); | |||
} | |||
//断线重连 | |||
catch (Exception ex) { | |||
Show("断线重连" + ex.getMessage()); | |||
this.isConnected = false; | |||
try { | |||
this.s7Connector.close(); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
} | |||
this.s7Connector = null; | |||
this.s7Serializer = null; | |||
try { | |||
this.initConnect(); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
this.myDbData = (MyS7Entity) this.s7Serializer.dispense(clazz, dbNum, offSet); | |||
// if (myDbDatas.size() < 30) { | |||
// myDbDatas.add(myDbData); | |||
// } else { | |||
// myDbDatas.remove(0); | |||
// } | |||
} | |||
return myDbData; | |||
} | |||
@Override | |||
public MyGunData readTheDbData(Integer dbNum, MyGunData clazz, int offSet) { | |||
MyGunData myData = this.s7Serializer.dispense(clazz.getClass(), dbNum, offSet); | |||
return myData; | |||
} | |||
@Override | |||
public void writePlcData(Integer dbNum, MyGunData clazz, int offSet) { | |||
this.s7Serializer.store(clazz, dbNum, 0); | |||
} | |||
/** | |||
* DB,DB号,偏移量,Byte数组 | |||
* @param bytes | |||
*/ | |||
@Override | |||
public void writePlcByte(byte[] bytes) { | |||
this.s7Connector.write(DaveArea.DB, 31, 0, bytes); | |||
} | |||
/** | |||
* 显示日志 | |||
*/ | |||
public void Show(String message) { | |||
Log.e("S7帮助类", message); | |||
} | |||
} |
@@ -0,0 +1,107 @@ | |||
package com.bonait.bnframework.common.modbus.S7; | |||
import android.util.Log; | |||
import com.bonait.bnframework.common.modbus.S7.mode.MyS7Entity; | |||
import java.io.IOException; | |||
import java.lang.reflect.Field; | |||
import java.sql.Timestamp; | |||
import java.util.Date; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
public class S7Listenner { | |||
public S7ConnHelper s7ConnHelper; | |||
Boolean last = false; | |||
Boolean trigIn = false; | |||
Boolean trigQ = false; | |||
public void Conn() throws IOException { | |||
s7ConnHelper.initConnect(); | |||
Show("初始化成功!!"); | |||
} | |||
//S7 | |||
public void Listen(){ | |||
try { | |||
s7ConnHelper.readPlcData(1, MyS7Entity.class, 0); | |||
Map<String, Object> myMap = new HashMap<>(); | |||
Field[] fields = s7ConnHelper.myDbData.getClass().getFields(); | |||
for (Field f :fields | |||
) { | |||
//log.info(f.getType().toString()); | |||
if (f.get(s7ConnHelper.myDbData) instanceof Double){ | |||
String format = String.format("%.3f", f.get(s7ConnHelper.myDbData)); | |||
myMap.put(f.getName(),format); | |||
} | |||
else { | |||
myMap.put(f.getName(),f.get(s7ConnHelper.myDbData)); | |||
} | |||
} | |||
s7ConnHelper.myMap=myMap; | |||
java.util.Date date = new Date();//获得当前时间 | |||
Timestamp t = new Timestamp(date.getTime());//将时间转换成Timestamp类型,这样便可以存入到Mysql数据库中 | |||
for (String key: s7ConnHelper.myMap.keySet() | |||
) { | |||
System.out.println(key); | |||
} | |||
// System.out.println("==============="); | |||
// for (Object v: s7ConnHelper.getMyMap().values() | |||
// ) { | |||
// System.out.println(v); | |||
// } | |||
} | |||
catch (Exception ex){ | |||
Show(ex.getMessage()+"====="); | |||
s7ConnHelper.s7Connector=null; | |||
s7ConnHelper.s7Serializer=null; | |||
try { | |||
s7ConnHelper.initConnect(); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
// java.util.Date date = new Date();//获得当前时间 | |||
// Timestamp t = new Timestamp(date.getTime());//将时间转换成Timestamp类型,这样便可以存入到Mysql数据库中 | |||
// for (int i = 0 ; i<s7ConnHelper.getActualDatas().size();i++ ){ | |||
// String myScale = s7ConnHelper.getActualDatas().get(i).getScale(); | |||
// Double scale = Double.parseDouble(myScale); | |||
// Double value =scale * s7ConnHelper.getMyDbDataList().get(i); | |||
// s7ConnHelper.getActualDatas().get(i).setValue(String.format("%.2f",value)); | |||
// s7ConnHelper.getActualDatas().get(i).setCreateTime(t); | |||
// } | |||
// | |||
// for (ActualData actualData: s7ConnHelper.getActualDatas() | |||
// ) { | |||
// log.info(actualData.toString()); | |||
// } | |||
//写入变量,OK | |||
// MyGunData myGunData = new MyGunData(); | |||
// myDbData.setVar1(1); | |||
// myDbData.setVar2(2); | |||
// myDbData.setVar3(3); | |||
// s7ConnHelper.writePlcData(24,myDbData,0); | |||
} | |||
/** | |||
* 显示日志 | |||
*/ | |||
public void Show(String message) { | |||
Log.e("S7帮助类", message); | |||
} | |||
} |
@@ -0,0 +1,29 @@ | |||
package com.bonait.bnframework.common.modbus.S7.mode; | |||
import com.github.s7connector.api.annotation.S7Variable; | |||
import com.github.s7connector.impl.utils.S7Type; | |||
public class MyGunData { | |||
@S7Variable(byteOffset = 0, type = S7Type.WORD) | |||
public Integer var1; | |||
@S7Variable(byteOffset = 2, type = S7Type.WORD) | |||
public Integer var2; | |||
@S7Variable(byteOffset = 4, type = S7Type.WORD) | |||
public Integer var3; | |||
@S7Variable(byteOffset = 6, type = S7Type.WORD) | |||
public Integer var4; | |||
@S7Variable(byteOffset = 8, type = S7Type.WORD) | |||
public Integer var5; | |||
@S7Variable(byteOffset = 10, type = S7Type.WORD) | |||
public Integer var6; | |||
@S7Variable(byteOffset = 12, type = S7Type.WORD) | |||
public Integer var7; | |||
@S7Variable(byteOffset = 14, type = S7Type.WORD) | |||
public Integer var8; | |||
@S7Variable(byteOffset = 16, type = S7Type.WORD) | |||
public Integer var9; | |||
@S7Variable(byteOffset = 18, type = S7Type.WORD) | |||
public Integer var10; | |||
// @S7Variable(type = S7Type.STRING, byteOffset = 2, bitOffset=0, size=10) | |||
// public String bbb; | |||
} |
@@ -0,0 +1,123 @@ | |||
package com.bonait.bnframework.common.modbus.S7.mode; | |||
import com.github.s7connector.api.annotation.S7Variable; | |||
import com.github.s7connector.impl.utils.S7Type; | |||
public class MyS7Entity { | |||
// @TableId(type = IdType.AUTO) | |||
// private Integer id; | |||
// | |||
// public static final Integer dbNum = 30; | |||
// //@Value("${myS7Db.offSet}") | |||
// public static final Integer offSet = 42; | |||
// | |||
// @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
// @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") | |||
// private Date createTime; | |||
// @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |||
// @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8") | |||
// private Date insertTime; | |||
//必须为public 否则报错 | |||
@S7Variable(byteOffset = 0, type = S7Type.REAL) | |||
public Double aBLineVoltage_PLC; | |||
@S7Variable(byteOffset = 4, type = S7Type.REAL) | |||
public Double bCLineVoltage_PLC; | |||
@S7Variable(byteOffset = 8, type = S7Type.REAL) | |||
public Double aCLineVoltage_PLC; | |||
@S7Variable(byteOffset = 12, type = S7Type.REAL) | |||
public Double aPhaseVoltage_PLC; | |||
@S7Variable(byteOffset = 16, type = S7Type.REAL) | |||
public Double bPhaseVoltage_PLC; | |||
@S7Variable(byteOffset = 20, type = S7Type.REAL) | |||
public Double cPhaseVoltage_PLC; | |||
@S7Variable(byteOffset = 24, type = S7Type.REAL) | |||
public Double aPhaseCurrent_PLC; | |||
@S7Variable(byteOffset = 28, type = S7Type.REAL) | |||
public Double bPhaseCurrent_PLC; | |||
@S7Variable(byteOffset = 32, type = S7Type.REAL) | |||
public Double cPhaseCurrent_PLC; | |||
@S7Variable(byteOffset = 36, type = S7Type.REAL) | |||
public Double allActivePower_PLC; | |||
@S7Variable(byteOffset = 40, type = S7Type.REAL) | |||
public Double aActivePower_PLC; | |||
@S7Variable(byteOffset = 44, type = S7Type.REAL) | |||
public Double bActivePower_PLC; | |||
@S7Variable(byteOffset = 48, type = S7Type.REAL) | |||
public Double cActivePower_PLC; | |||
@S7Variable(byteOffset = 52, type = S7Type.REAL) | |||
public Double allReactivePower_PLC; | |||
@S7Variable(byteOffset = 56, type = S7Type.REAL) | |||
public Double aReactivePower_PLC; | |||
@S7Variable(byteOffset = 60, type = S7Type.REAL) | |||
public Double bReactivePower_PLC; | |||
@S7Variable(byteOffset = 64, type = S7Type.REAL) | |||
public Double cReactivePower_PLC; | |||
@S7Variable(byteOffset = 68, type = S7Type.REAL) | |||
public Double allPowerFactor_PLC; | |||
@S7Variable(byteOffset = 72, type = S7Type.REAL) | |||
public Double aPowerFactor_PLC; | |||
@S7Variable(byteOffset = 76, type = S7Type.REAL) | |||
public Double bPowerFactor_PLC; | |||
@S7Variable(byteOffset = 80, type = S7Type.REAL) | |||
public Double cPowerFactor_PLC; | |||
@S7Variable(byteOffset = 84, type = S7Type.REAL) | |||
public Double aBLineVoltage_Power; | |||
@S7Variable(byteOffset = 88, type = S7Type.REAL) | |||
public Double bCLineVoltage_Power; | |||
@S7Variable(byteOffset = 92, type = S7Type.REAL) | |||
public Double aCLineVoltage_Power; | |||
@S7Variable(byteOffset = 96, type = S7Type.REAL) | |||
public Double aPhaseVoltage_Power; | |||
@S7Variable(byteOffset = 100, type = S7Type.REAL) | |||
public Double bPhaseVoltage_Power; | |||
@S7Variable(byteOffset = 104, type = S7Type.REAL) | |||
public Double cPhaseVoltage_Power; | |||
@S7Variable(byteOffset = 108, type = S7Type.REAL) | |||
public Double aPhaseCurrent_Power; | |||
@S7Variable(byteOffset = 112, type = S7Type.REAL) | |||
public Double bPhaseCurrent_Power; | |||
@S7Variable(byteOffset = 116, type = S7Type.REAL) | |||
public Double cPhaseCurrent_Power; | |||
@S7Variable(byteOffset = 120, type = S7Type.REAL) | |||
public Double allActivePower_Power; | |||
@S7Variable(byteOffset = 124, type = S7Type.REAL) | |||
public Double aActivePower_Power; | |||
@S7Variable(byteOffset = 128, type = S7Type.REAL) | |||
public Double bActivePower_Power; | |||
@S7Variable(byteOffset = 132, type = S7Type.REAL) | |||
public Double cActivePower_Power; | |||
@S7Variable(byteOffset = 136, type = S7Type.REAL) | |||
public Double allReactivePower_Power; | |||
@S7Variable(byteOffset = 140, type = S7Type.REAL) | |||
public Double aReactivePower_Power; | |||
@S7Variable(byteOffset = 144, type = S7Type.REAL) | |||
public Double bReactivePower_Power; | |||
@S7Variable(byteOffset = 148, type = S7Type.REAL) | |||
public Double cReactivePower_Power; | |||
@S7Variable(byteOffset = 152, type = S7Type.REAL) | |||
public Double allPowerFactor_Power; | |||
@S7Variable(byteOffset = 156, type = S7Type.REAL) | |||
public Double aPowerFactor_Power; | |||
@S7Variable(byteOffset = 160, type = S7Type.REAL) | |||
public Double bPowerFactor_Power; | |||
@S7Variable(byteOffset = 164, type = S7Type.REAL) | |||
public Double cPowerFactor_Power; | |||
@S7Variable(byteOffset = 168, type = S7Type.REAL) | |||
public Double testAlarm; | |||
@S7Variable(byteOffset = 404, type = S7Type.WORD) | |||
public Integer heartBeat; | |||
@S7Variable(byteOffset = 606,size = 130, type = S7Type.STRING) | |||
public String var100; | |||
@S7Variable(byteOffset = 738,size = 130, type = S7Type.STRING) | |||
public String var101; | |||
/** | |||
@S7Variable(byteOffset=0, type= S7Type.REAL) public double var1; | |||
@S7Variable(byteOffset=4, type= S7Type.REAL) public double var2; | |||
@S7Variable(byteOffset=8, type= S7Type.REAL) public double var3; | |||
@S7Variable(byteOffset=144, type= S7Type.BOOL) public boolean STATE_P1; | |||
@S7Variable(byteOffset=144, type= S7Type.BOOL,bitOffset = 1) public boolean STATE_P1; | |||
*/ | |||
} |
@@ -0,0 +1,11 @@ | |||
package com.bonait.bnframework.common.modbus.S7.mode; | |||
import com.github.s7connector.api.annotation.S7Variable; | |||
import com.github.s7connector.impl.utils.S7Type; | |||
public class MyS7WriteEntity { | |||
@S7Variable(byteOffset = 606,size = 130, type = S7Type.STRING) | |||
public String var100; | |||
@S7Variable(byteOffset = 738,size = 130, type = S7Type.STRING) | |||
public String var101; | |||
} |
@@ -10,7 +10,6 @@ import com.bonait.bnframework.common.constant.DataBus; | |||
import com.bonait.bnframework.common.helper.I.IThread; | |||
import com.bonait.bnframework.common.helper.MessageLog; | |||
import com.bonait.bnframework.common.helper.ThreadManager; | |||
import com.bonait.bnframework.common.modbus.ModbusTcpMainServer; | |||
import com.bonait.bnframework.common.modbus.ModbusTcpServer; | |||
import com.bonait.bnframework.common.utils.NetworkUtils; | |||
import com.google.android.material.bottomnavigation.BottomNavigationView; | |||
@@ -205,28 +204,6 @@ public class BottomNavigation2Activity extends BaseActivity { | |||
ConfigName.getInstance().PlcIsConnect = false; | |||
} | |||
} | |||
if(ConfigName.getInstance().versionSelectionEnum.contains("一拖")) | |||
{ | |||
if (ConfigName.getInstance().PlcMainIsConnect) { | |||
//ping 不通 | |||
boolean status = ModbusTcpMainServer.ping2(ConfigName.getInstance().MainAddress, 1, 1); | |||
if (!status) //ping 不通 连接 | |||
{ | |||
MessageLog.ShowInfo("主控PLC状态断开,尝试连接..."); | |||
ConfigName.getInstance().PlcMainIsConnect = false; | |||
} | |||
} else { | |||
boolean status = ModbusTcpMainServer.ping2(ConfigName.getInstance().MainAddress, 1, 1); | |||
if (status) { | |||
MessageLog.ShowInfo("设备 " + ConfigName.getInstance().MainAddress + " 主控PLC通讯正常,准备连接!"); | |||
ModbusTcpMainServer.ConnectPLC(); | |||
} else { | |||
MessageLog.ShowInfo("主控PLC状态断开,尝试连接..."); | |||
ConfigName.getInstance().PlcMainIsConnect = false; | |||
} | |||
} | |||
} | |||
Thread.sleep(10000); | |||
} catch (Exception e) { | |||
Log.i("PLC", "PLC重连接失败!" + e.getMessage()); | |||
@@ -28,7 +28,6 @@ import com.bonait.bnframework.common.helper.MessageLog; | |||
import com.bonait.bnframework.common.helper.ThreadManager; | |||
import com.bonait.bnframework.common.message.MessageLooper; | |||
import com.bonait.bnframework.common.message.MessageManager; | |||
import com.bonait.bnframework.common.modbus.ModbusTcpMainServer; | |||
import com.bonait.bnframework.common.modbus.ModbusTcpServer; | |||
import com.bonait.bnframework.common.utils.NetworkUtils; | |||
import com.bonait.bnframework.common.utils.ToastUtils; | |||
@@ -303,27 +302,6 @@ public class BottomNavigationNewActivity extends BaseActivity { | |||
ConfigName.getInstance().PlcIsConnect = false; | |||
} | |||
} | |||
if (ConfigName.getInstance().versionSelectionEnum.contains("一拖")) { | |||
if (ConfigName.getInstance().PlcMainIsConnect) { | |||
//ping 不通 | |||
boolean status = ModbusTcpMainServer.ping2(ConfigName.getInstance().MainAddress, 1, 1); | |||
if (!status) //ping 不通 连接 | |||
{ | |||
MessageLog.ShowInfo("主控PLC状态断开,尝试连接..."); | |||
ConfigName.getInstance().PlcMainIsConnect = false; | |||
} | |||
} else { | |||
boolean status = ModbusTcpMainServer.ping2(ConfigName.getInstance().MainAddress, 1, 1); | |||
if (status) { | |||
MessageLog.ShowInfo("设备 " + ConfigName.getInstance().MainAddress + " 主控PLC通讯正常,准备连接!"); | |||
ModbusTcpMainServer.ConnectPLC(); | |||
} else { | |||
MessageLog.ShowInfo("主控PLC状态断开,尝试连接..."); | |||
ConfigName.getInstance().PlcMainIsConnect = false; | |||
} | |||
} | |||
} | |||
Thread.sleep(10000); | |||
} catch (Exception e) { | |||
Log.i("PLC", "PLC重连接失败!" + e.getMessage()); | |||
@@ -416,10 +394,6 @@ public class BottomNavigationNewActivity extends BaseActivity { | |||
ToastUtils.info("客官,当前菜品已强制结束!!!"); | |||
//初始化 | |||
ExecuteTheRecipe.BottomClick("初始化"); | |||
if (ConfigName.getInstance().versionSelectionEnum.contains("一拖"))//通知任务结束 | |||
{ | |||
ExecuteTheRecipe.WriteMainPLC("强制结束任务完成", true, null);//复位 | |||
} | |||
ExecuteTheRecipe.StopForcedEnd(); | |||
} | |||
} | |||
@@ -623,10 +623,6 @@ public class Home1Fragment extends BaseFragment { | |||
ToastUtils.info("客官,当前菜品已强制结束!!!"); | |||
//初始化 | |||
ExecuteTheRecipe.BottomClick("初始化"); | |||
if (ConfigName.getInstance().versionSelectionEnum.contains("一拖"))//通知任务结束 | |||
{ | |||
ExecuteTheRecipe.WriteMainPLC("强制结束任务完成", true, null);//复位 | |||
} | |||
ExecuteTheRecipe.StopForcedEnd(); | |||
} | |||
} | |||
@@ -922,7 +918,6 @@ public class Home1Fragment extends BaseFragment { | |||
* @param view | |||
*/ | |||
@OnClick({R.id.xzcp, R.id.startbutton, R.id.qdjb | |||
, R.id.yaoqian, R.id.tingyao | |||
, R.id.ydw, R.id.dcw, R.id.clw, R.id.qxw, R.id.ccw1, R.id.ccw2, R.id.ccw3 | |||
, R.id.chushihua, R.id.jiting}) | |||
public void onViewClicked(View view) { | |||
@@ -971,18 +966,6 @@ public class Home1Fragment extends BaseFragment { | |||
} | |||
ExecuteTheRecipe.BottomClick("炒锅清洗"); | |||
break; | |||
case R.id.yaoqian: | |||
if (!IsMake(true)) { | |||
return; | |||
} | |||
ExecuteTheRecipe.Write_PLC_YaoQian(MyStatus.Start); | |||
break; | |||
case R.id.tingyao: | |||
if (!IsMake(true)) { | |||
return; | |||
} | |||
ExecuteTheRecipe.Write_PLC_YaoQian(MyStatus.Stop); | |||
break; | |||
case R.id.ydw://R.id.ydw, R.id.dcw, R.id.clw,R.id.qxw,R.id.ccw1,R.id.ccw2,R.id.ccw3 | |||
if (!IsMake(true)) { | |||
return; | |||
@@ -46,12 +46,6 @@ import butterknife.OnClick; | |||
public class HomeFragmentSBKZ extends BaseFragment { | |||
//region 变量 | |||
@BindView(R.id.touliao_k) | |||
LinearLayout touliao_k; | |||
@BindView(R.id.touliao_m) | |||
LinearLayout touliao_m; | |||
@BindView(R.id.plcstatus1) | |||
ImageView plcstatus1; | |||
@@ -108,18 +102,6 @@ public class HomeFragmentSBKZ extends BaseFragment { | |||
@BindView(R.id.xiguoshui) | |||
imagebuttom3 xiguoshui; | |||
@BindView(R.id.touliao1) | |||
imagebuttom3 touliao1; | |||
@BindView(R.id.touliao2) | |||
imagebuttom3 touliao2; | |||
@BindView(R.id.touliao3) | |||
imagebuttom3 touliao3; | |||
@BindView(R.id.touliao4) | |||
imagebuttom3 touliao4; | |||
@BindView(R.id.yeliao1) | |||
imagebuttom3 yeliao1; | |||
@BindView(R.id.yeliao2) | |||
@@ -197,11 +179,6 @@ public class HomeFragmentSBKZ extends BaseFragment { | |||
guokoucaoxiang_dc.mListener = myClickListener; | |||
guokoucaoxiang_qx.mListener = myClickListener; | |||
touliao1.mListener = myClickListener; | |||
touliao2.mListener = myClickListener; | |||
touliao3.mListener = myClickListener; | |||
touliao4.mListener = myClickListener; | |||
chushui.SetOnTounch(new View.OnTouchListener() { | |||
@Override | |||
public boolean onTouch(View view, MotionEvent motionEvent) { | |||
@@ -304,16 +281,7 @@ public class HomeFragmentSBKZ extends BaseFragment { | |||
private void initData() { | |||
SetStirFrySpeed(SpeedEnum.停, false); | |||
RefreshLiquidSilo(); | |||
if (ConfigName.getInstance().versionSelectionEnum.equals("大炒版本") || ConfigName.getInstance().versionSelectionEnum.contains("一拖")) { | |||
touliao_k.setVisibility(View.GONE); | |||
touliao_m.setVisibility(View.GONE); | |||
device_image.setImageResource(R.mipmap.device00); | |||
} else { | |||
touliao_k.setVisibility(View.VISIBLE); | |||
touliao_m.setVisibility(View.VISIBLE); | |||
device_image.setImageResource(R.mipmap.device1); | |||
} | |||
device_image.setImageResource(R.mipmap.device1); | |||
} | |||
/** | |||
@@ -424,18 +392,6 @@ public class HomeFragmentSBKZ extends BaseFragment { | |||
case R.id.guokoucaoxiang_qx: | |||
SetMouthFacing(MouthFacingEnum.清洗位); | |||
break; | |||
case R.id.touliao1: | |||
MainDish(1); | |||
break; | |||
case R.id.touliao2: | |||
MainDish(2); | |||
break; | |||
case R.id.touliao3: | |||
MainDish(3); | |||
break; | |||
case R.id.touliao4: | |||
MainDish(4); | |||
break; | |||
case R.id.huoli: | |||
SetFire(hl); | |||
break; | |||
@@ -595,7 +551,6 @@ public class HomeFragmentSBKZ extends BaseFragment { | |||
*/ | |||
public void PumpWater(boolean isselectd) { | |||
ExecuteTheRecipe.WritePLC("炒锅抽水", isselectd, null); | |||
//ToastUtils.warning("锅内加水:" + (isselectd ? "打开" : "关闭")); | |||
} | |||
/** | |||
@@ -605,45 +560,6 @@ public class HomeFragmentSBKZ extends BaseFragment { | |||
*/ | |||
public void PotWashingWater(boolean isselectd) { | |||
ExecuteTheRecipe.WritePLC("炒锅放水", isselectd, null); | |||
//ToastUtils.warning("洗锅水枪:" + (isselectd ? "打开" : "关闭")); | |||
} | |||
public boolean isMake = false; | |||
/** | |||
* 投主菜品 | |||
* | |||
* @param num | |||
*/ | |||
public void MainDish(int num) { | |||
// Object sb = ExecuteTheRecipe.ReadPLC("平移轴在1号位"); | |||
// if (sb != null) { | |||
// if ((boolean) (sb)) { | |||
// | |||
// } else { | |||
// ToastUtils.warning("平移轴未复位!!!"); | |||
// } | |||
// } else { | |||
// ToastUtils.warning("PLC未连接!!!"); | |||
// } | |||
if (isMake == false) { | |||
isMake = true; | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
BPA_GOODSRECIPE data1 = Get位置("高速", "炒菜位1"); | |||
ExecuteTheRecipe.ExecuteOperationSteps(data1.processname, data1.processvalue); | |||
BPA_GOODSRECIPE data = Get主料(num); | |||
ExecuteTheRecipe.ExecuteOperationSteps(data.processname, data.processvalue); | |||
ToastUtils.warning("主料:" + num + "号仓投放"); | |||
isMake = false; | |||
} | |||
}).start(); | |||
}else | |||
{ | |||
ToastUtils.warning("请耐心等待上一次投料结束!!!"); | |||
} | |||
} | |||
/** | |||
@@ -675,36 +591,5 @@ public class HomeFragmentSBKZ extends BaseFragment { | |||
ExecuteTheRecipe.BottomClick("出菜"); | |||
ToastUtils.warning("出餐"); | |||
} | |||
/** | |||
* 获取主料 | |||
* | |||
* @param wz | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get主料(int wz) { | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType = 1; | |||
pf.processname = "主料"; | |||
pf.processms = "主料(未知," + wz + "号位,0,直接投出,0)"; | |||
pf.processvalue = "主料名称,未知|主料位置," + wz + "号位|主料重量,0|投料动作,直接投出|烹饪(秒),0"; | |||
return pf; | |||
} | |||
/** | |||
* 获取位置 | |||
* | |||
* @param sd | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get位置(String sd, String name) { | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType = 1; | |||
pf.processname = "位置"; | |||
pf.processms = "位置(" + sd + "," + name + ",0)"; | |||
pf.processvalue = "转动速度," + sd + "|位置动作," + name + "|延迟(秒),0"; | |||
return pf; | |||
} | |||
//endregion | |||
} |
@@ -68,11 +68,6 @@ public class DishTestActivity extends BaseActivity { | |||
@BindView(R.id.device_image) | |||
ImageView device_image; | |||
@BindView(R.id.touliao_k) | |||
LinearLayout touliao_k; | |||
@BindView(R.id.touliao_m) | |||
LinearLayout touliao_m; | |||
@BindView(R.id.topbar) | |||
QMUITopBarLayout mTopBar; | |||
@@ -104,18 +99,6 @@ public class DishTestActivity extends BaseActivity { | |||
// @BindView(R.id.chushui) | |||
// imagebuttom3 chushui; | |||
@BindView(R.id.touliao1) | |||
imagebuttom3 touliao1; | |||
@BindView(R.id.touliao2) | |||
imagebuttom3 touliao2; | |||
@BindView(R.id.touliao3) | |||
imagebuttom3 touliao3; | |||
@BindView(R.id.touliao4) | |||
imagebuttom3 touliao4; | |||
@BindView(R.id.yeliao1) | |||
imagebuttom3 yeliao1; | |||
@BindView(R.id.yeliao2) | |||
@@ -144,12 +127,6 @@ public class DishTestActivity extends BaseActivity { | |||
@BindView(R.id.zhixingzhong) | |||
RelativeLayout zhixingzhong;//执行中 | |||
@BindView(R.id.guoneichoushui) | |||
RelativeLayout guoneichoushui;//锅内抽水 | |||
@BindView(R.id.runtime_cs) | |||
Chronometer runtime_cs; | |||
@BindView(R.id.datatab_gxbz) | |||
ListView datatab_gxbz; | |||
@@ -245,10 +222,6 @@ public class DishTestActivity extends BaseActivity { | |||
//chushui.mListener = myClickListener; | |||
touliao1.mListener = myClickListener; | |||
touliao2.mListener = myClickListener; | |||
touliao3.mListener = myClickListener; | |||
touliao4.mListener = myClickListener; | |||
yeliao1.mListener = myClickListener; | |||
yeliao2.mListener = myClickListener; | |||
@@ -267,16 +240,7 @@ public class DishTestActivity extends BaseActivity { | |||
* 初始化显示数据 | |||
*/ | |||
private void initData() { | |||
if (ConfigName.getInstance().versionSelectionEnum.equals("大炒版本") || ConfigName.getInstance().versionSelectionEnum.contains("一拖")) { | |||
touliao_k.setVisibility(View.GONE); | |||
touliao_m.setVisibility(View.GONE); | |||
device_image.setImageResource(R.mipmap.device00); | |||
}else | |||
{ | |||
touliao_k.setVisibility(View.VISIBLE); | |||
touliao_m.setVisibility(View.VISIBLE); | |||
device_image.setImageResource(R.mipmap.device1); | |||
} | |||
device_image.setImageResource(R.mipmap.device00); | |||
DataBus.getInstance().ShowGoodName = ""; | |||
SetStirFrySpeed(SpeedEnum.停, false); | |||
@@ -380,22 +344,6 @@ public class DishTestActivity extends BaseActivity { | |||
case R.id.fanchaoshudu_t: | |||
SetStirFrySpeed(SpeedEnum.停, isclick); | |||
break; | |||
case R.id.chushui: | |||
PumpWater(true); | |||
break; | |||
case R.id.touliao1: | |||
MainDish(1); | |||
break; | |||
case R.id.touliao2: | |||
MainDish(2); | |||
break; | |||
case R.id.touliao3: | |||
MainDish(3); | |||
break; | |||
case R.id.touliao4: | |||
MainDish(4); | |||
break; | |||
case R.id.yeliao1: | |||
EditTextDialogBuilder(1); | |||
break; | |||
@@ -443,13 +391,10 @@ public class DishTestActivity extends BaseActivity { | |||
* | |||
* @param view | |||
*/ | |||
@OnClick({R.id.tingzhijiashui, R.id.click_cpmc, R.id.click_lhdata, R.id.click_savemncz | |||
@OnClick({ R.id.click_cpmc, R.id.click_lhdata, R.id.click_savemncz | |||
, R.id.click_lhdata_fh, R.id.goodname, R.id.close_from}) | |||
public void onViewClicked(View view) { | |||
switch (view.getId()) { | |||
case R.id.tingzhijiashui://停止加水 | |||
PumpWater(false); | |||
break; | |||
case R.id.click_cpmc://菜品名称保存 | |||
String data = caipinmingchen_text.getText().toString(); | |||
if (data.isEmpty()) { | |||
@@ -614,17 +559,17 @@ public class DishTestActivity extends BaseActivity { | |||
liaohedata.setVisibility(View.GONE); | |||
goodname.setText(DataBus.getInstance().ShowGoodName + ""); | |||
touliao1.setTag(liaohetext1 + "-按钮"); | |||
touliao1.Init(); | |||
touliao2.setTag(liaohetext2 + "-按钮"); | |||
touliao2.Init(); | |||
touliao3.setTag(liaohetext3 + "-按钮"); | |||
touliao3.Init(); | |||
touliao4.setTag(liaohetext4 + "-按钮"); | |||
touliao4.Init(); | |||
// touliao1.setTag(liaohetext1 + "-按钮"); | |||
// touliao1.Init(); | |||
// | |||
// touliao2.setTag(liaohetext2 + "-按钮"); | |||
// touliao2.Init(); | |||
// | |||
// touliao3.setTag(liaohetext3 + "-按钮"); | |||
// touliao3.Init(); | |||
// | |||
// touliao4.setTag(liaohetext4 + "-按钮"); | |||
// touliao4.Init(); | |||
break; | |||
} | |||
} | |||
@@ -750,45 +695,6 @@ public class DishTestActivity extends BaseActivity { | |||
} | |||
}); | |||
} | |||
/** | |||
* 启动定时器 | |||
*/ | |||
public void onRecordStart_CS() { | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
guoneichoushui.setVisibility(View.VISIBLE); | |||
runtime_cs.setBase(SystemClock.elapsedRealtime()); | |||
runtime_cs.start(); | |||
IsChouShui=true; | |||
} | |||
}); | |||
} | |||
/** | |||
* 停止计时器 | |||
*/ | |||
public void onRecordStop_CS() { | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
guoneichoushui.setVisibility(View.GONE); | |||
runtime_cs.stop(); | |||
long elapsedMillis = SystemClock.elapsedRealtime() - runtime_cs.getBase(); | |||
DataBus.getInstance().PumpWaterTimeOut = (int) (elapsedMillis / 1000); | |||
ClikTime = (int) ((SystemClock.elapsedRealtime() - runtime.getBase()) / 1000); | |||
if(IsChouShui) | |||
{ | |||
BPA_GOODSRECIPE data = Get加水(DataBus.getInstance().PumpWaterTimeOut); | |||
DataBus.getInstance().bpa_goodsrecipes.add(data); | |||
} | |||
IsChouShui=false; | |||
} | |||
}); | |||
} | |||
//endregion | |||
//region 公共方法 | |||
@@ -855,11 +761,9 @@ public class DishTestActivity extends BaseActivity { | |||
if (time_c > 0)//如果大于0,那么加一个延迟 | |||
{ | |||
DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); | |||
DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get延迟(time_c)); | |||
} | |||
String sdstr = Get速度(_speed); | |||
BPA_GOODSRECIPE data = Get搅拌(sdstr); | |||
BPA_GOODSRECIPE data = ExecuteTheRecipe.Get搅拌(_speed); | |||
DataBus.getInstance().bpa_goodsrecipes.add(data); | |||
ExecuteTheRecipe.ExecuteOperationSteps(data.processname, data.processvalue); | |||
@@ -870,57 +774,6 @@ public class DishTestActivity extends BaseActivity { | |||
} | |||
} | |||
/** | |||
* 投主菜品 | |||
* | |||
* @param num | |||
*/ | |||
public void MainDish(int num) { | |||
// Object sb = ExecuteTheRecipe.ReadPLC("平移轴在1号位"); | |||
// if (sb != null) { | |||
// if ((boolean) (sb)) { | |||
// | |||
// } else { | |||
// ToastUtils.warning("平移轴未复位!!!"); | |||
// } | |||
// } else { | |||
// ToastUtils.warning("PLC未连接!!!"); | |||
// } | |||
SetZhiXingZhong(true); | |||
int time = (int) ((SystemClock.elapsedRealtime() - runtime.getBase()) / 1000);//当前点击多少秒 | |||
int time_c = time - ClikTime; | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
BPA_GOODSRECIPE data1 = Get位置("高速", "炒菜位1"); | |||
//DataBus.getInstance().bpa_goodsrecipes.add(data1); | |||
ExecuteTheRecipe.ExecuteOperationSteps(data1.processname, data1.processvalue); | |||
BPA_GOODSRECIPE data = Get主料(num); | |||
ExecuteTheRecipe.ExecuteOperationSteps(data.processname, data.processvalue); | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
if (time_c > 0)//如果大于0,那么加一个延迟 | |||
{ | |||
DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); | |||
} | |||
DataBus.getInstance().bpa_goodsrecipes.add(data); | |||
ToastUtils.warning("主料:" + num + "号仓投放"); | |||
SetZhiXingZhong(false); | |||
//刷新工序 | |||
RefreshProcedure(); | |||
} | |||
}); | |||
} | |||
}).start(); | |||
} | |||
/** | |||
* 手动投主菜品 | |||
@@ -933,9 +786,9 @@ public class DishTestActivity extends BaseActivity { | |||
if (time_c > 0)//如果大于0,那么加一个延迟 | |||
{ | |||
DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); | |||
DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get延迟(time_c)); | |||
} | |||
DataBus.getInstance().bpa_goodsrecipes.add(Get手动主料()); | |||
DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get主料(0,0,0,0,0,0)); | |||
ExecuteTheRecipe.WritePLC("暂停开关", true, null); | |||
//刷新工序 | |||
RefreshProcedure(); | |||
@@ -972,11 +825,11 @@ public class DishTestActivity extends BaseActivity { | |||
public void run() { | |||
BPA_GOODSRECIPE data1 = Get位置("高速", "抽料位"); | |||
BPA_GOODSRECIPE data1 = ExecuteTheRecipe.Get位置("抽料位"); | |||
//DataBus.getInstance().bpa_goodsrecipes.add(data1); | |||
ExecuteTheRecipe.ExecuteOperationSteps(data1.processname, data1.processvalue); | |||
BPA_GOODSRECIPE cipe = GetSelectItemFromValue(name, yl); | |||
BPA_GOODSRECIPE cipe = ExecuteTheRecipe.Get物料(name, yl); | |||
ExecuteTheRecipe.ExecuteMaterialIssuance(cipe.processvalue); | |||
@@ -985,7 +838,7 @@ public class DishTestActivity extends BaseActivity { | |||
public void run() { | |||
if (time_c > 0)//如果大于0,那么加一个延迟 | |||
{ | |||
DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); | |||
DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get延迟(time_c)); | |||
} | |||
DataBus.getInstance().bpa_goodsrecipes.add(cipe); | |||
@@ -998,52 +851,6 @@ public class DishTestActivity extends BaseActivity { | |||
}).start(); | |||
} | |||
boolean IsChouShui=false; | |||
/** | |||
* 抽水 | |||
*/ | |||
public void PumpWater(boolean isselectd) { | |||
if (isselectd) { | |||
int time = (int) ((SystemClock.elapsedRealtime() - runtime.getBase()) / 1000);//当前点击多少秒 | |||
int time_c = time - ClikTime; | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
guoneichoushui.setVisibility(View.VISIBLE); | |||
} | |||
}); | |||
} | |||
}).start(); | |||
new Thread(new Runnable() { | |||
@Override | |||
public void run() { | |||
BPA_GOODSRECIPE data1 = Get位置("高速", "抽料位"); | |||
ExecuteTheRecipe.ExecuteOperationSteps(data1.processname, data1.processvalue); | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
if (time_c > 0)//如果大于0,那么加一个延迟 | |||
{ | |||
DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); | |||
} | |||
onRecordStart_CS(); | |||
} | |||
}); | |||
} | |||
}).start(); | |||
} else { | |||
onRecordStop_CS(); | |||
} | |||
ExecuteTheRecipe.WritePLC("炒锅抽水", isselectd, null); | |||
ToastUtils.warning("锅内加水:" + isselectd); | |||
//刷新工序 | |||
RefreshProcedure(); | |||
} | |||
/** | |||
* 设置火力 | |||
* | |||
@@ -1056,12 +863,12 @@ public class DishTestActivity extends BaseActivity { | |||
if (time_c > 0)//如果大于0,那么加一个延迟 | |||
{ | |||
DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); | |||
DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get延迟(time_c)); | |||
} | |||
String sdstr = Get挡位((int) data); | |||
BPA_GOODSRECIPE data1 = Get加热(sdstr); | |||
DataBus.getInstance().bpa_goodsrecipes.add(data1); | |||
// BPA_GOODSRECIPE data1 = ExecuteTheRecipe.Get加热(sdstr); | |||
// DataBus.getInstance().bpa_goodsrecipes.add(data1); | |||
ClikTime = time; | |||
ExecuteTheRecipe.Write_PLC_HuoLI((int) data); | |||
@@ -1075,9 +882,9 @@ public class DishTestActivity extends BaseActivity { | |||
public void AutomaticServing() { | |||
int time = (int) ((SystemClock.elapsedRealtime() - runtime.getBase()) / 1000);//当前点击多少秒 | |||
int time_c = time - ClikTime; | |||
BPA_GOODSRECIPE data = Get出菜(time_c); | |||
BPA_GOODSRECIPE data = ExecuteTheRecipe.Get出菜(time_c); | |||
DataBus.getInstance().bpa_goodsrecipes.add(data); | |||
BPA_GOODSRECIPE data2 = Get清洗(0); | |||
BPA_GOODSRECIPE data2 = ExecuteTheRecipe.Get清洗(0); | |||
DataBus.getInstance().bpa_goodsrecipes.add(data2); | |||
new Thread(new Runnable() { | |||
@Override | |||
@@ -1087,209 +894,6 @@ public class DishTestActivity extends BaseActivity { | |||
} | |||
}).start(); | |||
} | |||
/** | |||
* 获取延迟 | |||
* | |||
* @param time | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get延迟(int time) { | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType = 1; | |||
pf.processname = "延迟"; | |||
pf.processms = "延迟(" + time + ")"; | |||
pf.processvalue = "延迟(秒)," + time; | |||
return pf; | |||
} | |||
/** | |||
* 获取加水 | |||
* | |||
* @param time | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get加水(int time) { | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType = 1; | |||
pf.processname = "加水"; | |||
pf.processms = "加水(" + time + ")"; | |||
pf.processvalue = "时长(秒)," + time; | |||
return pf; | |||
} | |||
/** | |||
* 获取主料 | |||
* | |||
* @param wz | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get主料(int wz) { | |||
String ms = "未知"; | |||
if (wz == 1) { | |||
if (!liaohetext1.isEmpty()) { | |||
ms = liaohetext1; | |||
} | |||
} else if (wz == 2) { | |||
if (!liaohetext2.isEmpty()) { | |||
ms = liaohetext2; | |||
} | |||
} else if (wz == 3) { | |||
if (!liaohetext3.isEmpty()) { | |||
ms = liaohetext3; | |||
} | |||
} else if (wz == 4) { | |||
if (!liaohetext4.isEmpty()) { | |||
ms = liaohetext4; | |||
} | |||
} | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType = 1; | |||
pf.processname = "主料"; | |||
pf.processms = "主料(" + ms + "," + wz + "号位,0,直接投出,0)"; | |||
pf.processvalue = "主料名称," + ms + "|主料位置," + wz + "号位|主料重量,0|投料动作,直接投出|烹饪(秒),0"; | |||
return pf; | |||
} | |||
/** | |||
* 获取手动主料 | |||
* | |||
* @param | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get手动主料() { | |||
String ms = "未知"; | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType = 1; | |||
pf.processname = "主料"; | |||
pf.processms = "主料(" + ms + ",1号位,0,手动投料,0)"; | |||
pf.processvalue = "主料名称," + ms + "|主料位置,1号位|主料重量,0|投料动作,手动投料|烹饪(秒),0"; | |||
return pf; | |||
} | |||
/** | |||
* 获取位置 | |||
* | |||
* @param sd | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get位置(String sd, String name) { | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType = 1; | |||
pf.processname = "位置"; | |||
pf.processms = "位置(" + sd + "," + name + ",0)"; | |||
pf.processvalue = "转动速度," + sd + "|位置动作," + name + "|延迟(秒),0"; | |||
return pf; | |||
} | |||
/** | |||
* 获取搅拌 | |||
* | |||
* @param sd | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get搅拌(String sd) { | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType = 1; | |||
pf.processname = "搅拌"; | |||
pf.processms = "搅拌(" + sd + ",0)"; | |||
pf.processvalue = "搅拌速度," + sd + "|延迟(秒),0"; | |||
return pf; | |||
} | |||
/** | |||
* 获取加热 | |||
* | |||
* @param sd | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get加热(String sd) { | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType = 1; | |||
pf.processname = "加热"; | |||
pf.processms = "加热(" + sd + ",0)"; | |||
pf.processvalue = "加热功率," + sd + "|延迟(秒),0"; | |||
return pf; | |||
} | |||
/** | |||
* 获取出菜 | |||
* | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get出菜(int k) { | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType = 1; | |||
pf.processname = "出菜"; | |||
pf.processms = "出菜(" + k + ")"; | |||
pf.processvalue = "等待(秒)," + k; | |||
return pf; | |||
} | |||
/** | |||
* 获取清洗 | |||
* | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get清洗(int k) { | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType = 1; | |||
pf.processname = "清洗"; | |||
pf.processms = "清洗(" + k + ")"; | |||
pf.processvalue = "等待(秒)," + k; | |||
return pf; | |||
} | |||
/** | |||
* 获取选中行的变量 | |||
* | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE GetSelectItemFromValue(String name, String yl) { | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
try { | |||
// 延迟,100|延迟,100|延迟,100|延迟,100| | |||
String data = ""; | |||
String desc = ""; | |||
pf.materialType = 0; | |||
data += name + "," + yl + "|"; | |||
desc += yl + ","; | |||
pf.processname = "液体料"; | |||
pf.processms = "液体料" + "(" + desc.substring(0, desc.length() - 1) + ")"; | |||
pf.processvalue = data.substring(0, data.length() - 1); | |||
return pf; | |||
} catch (Exception ex) { | |||
return null; | |||
} | |||
} | |||
/** | |||
* 获取速度 | |||
* | |||
* @return | |||
*/ | |||
public String Get速度(int speed) { | |||
if (speed >= 0 && speed < 5) { | |||
return "停止"; | |||
} else if (speed >= 5 && speed < 15) { | |||
return "最低"; | |||
} else if (speed >= 15 && speed < 25) { | |||
return "低速"; | |||
} else if (speed >= 25 && speed < 35) { | |||
return "中速"; | |||
} else if (speed >= 35 && speed < 45) { | |||
return "高速"; | |||
} else if (speed >= 45 && speed < 55) { | |||
return "最高"; | |||
} else { | |||
return "极高"; | |||
} | |||
} | |||
/** | |||
* 获取挡位 | |||
* | |||
@@ -157,14 +157,14 @@ public class DiyMemoryActivity extends BaseActivity { | |||
if(time_c>0)//如果大于0,那么加一个延迟 | |||
{ | |||
DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); | |||
DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get延迟(time_c)); | |||
} | |||
String sdstr= Get挡位((int) data); | |||
BPA_GOODSRECIPE data1=Get加热(sdstr); | |||
DataBus.getInstance().bpa_goodsrecipes.add(data1); | |||
ClikTime=time; | |||
ExecuteTheRecipe.Write_PLC_HuoLI((int) data); | |||
// String sdstr= Get挡位((int) data); | |||
// BPA_GOODSRECIPE data1=ExecuteTheRecipe.Get加热(sdstr); | |||
// DataBus.getInstance().bpa_goodsrecipes.add(data1); | |||
// ClikTime=time; | |||
// ExecuteTheRecipe.Write_PLC_HuoLI((int) data); | |||
} | |||
} | |||
@@ -222,12 +222,11 @@ public class DiyMemoryActivity extends BaseActivity { | |||
{ | |||
if(time_c>0)//如果大于0,那么加一个延迟 | |||
{ | |||
DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); | |||
DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get延迟(time_c)); | |||
} | |||
int sd = (int) nifty_slider2.getValue(); | |||
String sdstr= Get速度(sd); | |||
BPA_GOODSRECIPE data=Get搅拌(sdstr); | |||
BPA_GOODSRECIPE data=ExecuteTheRecipe.Get搅拌(sd); | |||
DataBus.getInstance().bpa_goodsrecipes.add(data); | |||
ExecuteTheRecipe.WritePLC("搅拌速度", sd, new IWriteCallBack() { | |||
@Override | |||
@@ -262,18 +261,6 @@ public class DiyMemoryActivity extends BaseActivity { | |||
ExecuteTheRecipe.BottomClick("平移-去1号位"); | |||
} | |||
break; | |||
case R.id.touliao1://主料1 | |||
ClickZL(time,time_c,1); | |||
break; | |||
case R.id.touliao2://主料2 | |||
ClickZL(time,time_c,2); | |||
break; | |||
case R.id.touliao3://主料3 | |||
ClickZL(time,time_c,3); | |||
break; | |||
case R.id.touliao4://主料4 | |||
ClickZL(time,time_c,4); | |||
break; | |||
case R.id.ydw://原点位 | |||
ClickWZ(time,time_c,"原点位"); | |||
break; | |||
@@ -298,9 +285,9 @@ public class DiyMemoryActivity extends BaseActivity { | |||
case R.id.zidongchucan://自动出餐 | |||
if(isRunClick()) | |||
{ | |||
BPA_GOODSRECIPE data1=Get出菜(time_c); | |||
BPA_GOODSRECIPE data1=ExecuteTheRecipe.Get出菜(time_c); | |||
DataBus.getInstance().bpa_goodsrecipes.add(data1); | |||
BPA_GOODSRECIPE data2 = Get清洗(0); | |||
BPA_GOODSRECIPE data2 = ExecuteTheRecipe.Get清洗(0); | |||
DataBus.getInstance().bpa_goodsrecipes.add(data2); | |||
MakeRecipe(data1); | |||
ClikTime=time; | |||
@@ -335,49 +322,18 @@ public class DiyMemoryActivity extends BaseActivity { | |||
return true; | |||
} | |||
public void ClickZL(int time,int time_c,int num) | |||
{ | |||
// Object sb = ExecuteTheRecipe.ReadPLC("平移轴在1号位"); | |||
// if (sb != null) { | |||
// if ((boolean) (sb)) { | |||
// | |||
// } else { | |||
// ToastUtils.warning("平移轴未复位!!!"); | |||
// } | |||
// } else { | |||
// ToastUtils.warning("PLC未连接!!!"); | |||
// } | |||
if(isRunClick()) | |||
{ | |||
if(time_c>0)//如果大于0,那么加一个延迟 | |||
{ | |||
DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); | |||
} | |||
//控制去炒菜位 | |||
BPA_GOODSRECIPE data1=Get位置("高速","炒菜位1"); | |||
DataBus.getInstance().bpa_goodsrecipes.add(data1); | |||
BPA_GOODSRECIPE data=Get主料(num); | |||
DataBus.getInstance().bpa_goodsrecipes.add(data); | |||
MakeRecipe(data);//执行主料 | |||
ClikTime=time; | |||
} | |||
} | |||
public void ClickWZ(int time,int time_c,String name) | |||
{ | |||
if(isRunClick()) | |||
{ | |||
if(time_c>0)//如果大于0,那么加一个延迟 | |||
{ | |||
DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); | |||
DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get延迟(time_c)); | |||
} | |||
// int sd = (int) nifty_slider3.getValue(); | |||
// String sdstr= Get速度(sd); | |||
BPA_GOODSRECIPE data=Get位置("高速",name); | |||
BPA_GOODSRECIPE data=ExecuteTheRecipe.Get位置(name); | |||
DataBus.getInstance().bpa_goodsrecipes.add(data); | |||
MakeRecipe(data); | |||
ClikTime=time; | |||
@@ -393,23 +349,18 @@ public class DiyMemoryActivity extends BaseActivity { | |||
public void run() { | |||
if (recipe.materialType == 0)//正常物料 | |||
{ | |||
BPA_GOODSRECIPE data1=Get位置("高速","抽料位"); | |||
ExecuteTheRecipe.ExecuteOperationSteps(data1.processname,data1.processvalue); | |||
ExecuteTheRecipe.ExecuteMaterialIssuance(recipe.processvalue); | |||
} else if (recipe.materialType == 1)//工序模型 | |||
{ | |||
if(recipe.processname.equals("主料")) | |||
{ | |||
BPA_GOODSRECIPE data1=Get位置("高速","炒菜位1"); | |||
ExecuteTheRecipe.ExecuteOperationSteps(data1.processname,data1.processvalue); | |||
ExecuteTheRecipe.ExecuteOperationSteps(recipe.processname,recipe.processvalue); | |||
}else | |||
{ | |||
if(recipe.processname.equals("出菜")) | |||
{ | |||
ExecuteTheRecipe.ExecuteOperationSteps(recipe.processname,recipe.processvalue); | |||
BPA_GOODSRECIPE data2 = Get清洗(0); | |||
BPA_GOODSRECIPE data2 = ExecuteTheRecipe.Get清洗(0); | |||
ExecuteTheRecipe.ExecuteOperationSteps(data2.processname,data2.processvalue); | |||
}else | |||
{ | |||
@@ -466,106 +417,7 @@ public class DiyMemoryActivity extends BaseActivity { | |||
} | |||
} | |||
/** | |||
* 获取延迟 | |||
* @param time | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get延迟(int time) | |||
{ | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType=1; | |||
pf.processname="延迟"; | |||
pf.processms="延迟("+time+")"; | |||
pf.processvalue="延迟(秒),"+time; | |||
return pf; | |||
} | |||
/** | |||
* 获取清洗 | |||
* | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get清洗(int k) { | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType = 1; | |||
pf.processname = "清洗"; | |||
pf.processms = "清洗(" + k + ")"; | |||
pf.processvalue = "等待(秒)," + k; | |||
return pf; | |||
} | |||
/** | |||
* 获取主料 | |||
* @param wz | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get主料(int wz) | |||
{ | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType=1; | |||
pf.processname="主料"; | |||
pf.processms="主料(未知,"+wz+"号位,0,直接投出,0)"; | |||
pf.processvalue="主料名称,未知|主料位置,"+wz+"号位|主料重量,0|投料动作,直接投出|烹饪(秒),0"; | |||
return pf; | |||
} | |||
/** | |||
* 获取位置 | |||
* @param sd | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get位置(String sd,String name) | |||
{ | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType=1; | |||
pf.processname="位置"; | |||
pf.processms="位置("+sd+","+name+",0)"; | |||
pf.processvalue="转动速度,"+sd+"|位置动作,"+name+"|延迟(秒),0"; | |||
return pf; | |||
} | |||
/** | |||
* 获取搅拌 | |||
* @param sd | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get搅拌(String sd) | |||
{ | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType=1; | |||
pf.processname="搅拌"; | |||
pf.processms="搅拌("+sd+",0)"; | |||
pf.processvalue="搅拌速度,"+sd+"|延迟(秒),0"; | |||
return pf; | |||
} | |||
/** | |||
* 获取加热 | |||
* @param sd | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get加热(String sd) | |||
{ | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType=1; | |||
pf.processname="加热"; | |||
pf.processms="加热("+sd+",0)"; | |||
pf.processvalue="加热功率,"+sd+"|延迟(秒),0"; | |||
return pf; | |||
} | |||
/** | |||
* 获取出菜 | |||
* @return | |||
*/ | |||
public BPA_GOODSRECIPE Get出菜(int k) | |||
{ | |||
BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); | |||
pf.materialType=1; | |||
pf.processname="出菜"; | |||
pf.processms="出菜("+k+")"; | |||
pf.processvalue="等待(秒),"+k; | |||
return pf; | |||
} | |||
/** | |||
* 获取速度 | |||
@@ -154,7 +154,7 @@ public class SystemSystemsetFragment extends BaseFragment { | |||
break; | |||
case -100: | |||
ConfigName.getInstance().versionSelectionEnum = item.value; | |||
versionselection.setSelection(material_map_vis.get(item.value)); | |||
versionselection.setSelection(material_map_vis.get(item.value)==null?0:material_map_vis.get(item.value)); | |||
break; | |||
case -99: | |||
ConfigName.getInstance().Environment = item.value; | |||
@@ -226,103 +226,6 @@ | |||
android:layout_marginBottom="180dp" | |||
android:orientation="vertical" /> | |||
<!-- 投料 --> | |||
<LinearLayout | |||
android:id="@+id/touliao_k" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginLeft="40dp" | |||
android:layout_marginTop="140dp" | |||
android:orientation="horizontal"> | |||
<TextView | |||
android:layout_width="83dp" | |||
android:layout_height="wrap_content" | |||
android:text="④" | |||
android:textAlignment="center" | |||
android:textColor="@color/white" | |||
android:textSize="24dp" | |||
android:textStyle="bold" /> | |||
<TextView | |||
android:layout_width="83dp" | |||
android:layout_height="wrap_content" | |||
android:text="③" | |||
android:textAlignment="center" | |||
android:textColor="@color/white" | |||
android:textSize="24dp" | |||
android:textStyle="bold" /> | |||
<TextView | |||
android:layout_width="45dp" | |||
android:layout_height="wrap_content" | |||
android:text="②" | |||
android:textAlignment="center" | |||
android:textColor="@color/white" | |||
android:textSize="24dp" | |||
android:textStyle="bold" /> | |||
<TextView | |||
android:layout_width="45dp" | |||
android:layout_height="wrap_content" | |||
android:text="①" | |||
android:textAlignment="center" | |||
android:textColor="@color/white" | |||
android:textSize="24dp" | |||
android:textStyle="bold" /> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:id="@+id/touliao_m" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginLeft="40dp" | |||
android:layout_marginTop="175dp" | |||
android:orientation="horizontal"> | |||
<com.bonait.bnframework.modules.home.fragment.mode.imagebuttom3 | |||
android:id="@+id/touliao4" | |||
android:layout_width="83dp" | |||
android:layout_height="90dp" | |||
android:contentDescription="" | |||
android:tag="投料-按钮" | |||
app:imagesrc_ks="@mipmap/sb1" | |||
app:imagesrc_qt="@mipmap/sb2" | |||
app:imagesrc_tz="@mipmap/sb3" /> | |||
<com.bonait.bnframework.modules.home.fragment.mode.imagebuttom3 | |||
android:id="@+id/touliao3" | |||
android:layout_width="83dp" | |||
android:layout_height="90dp" | |||
android:contentDescription="" | |||
android:tag="投料-按钮" | |||
app:imagesrc_ks="@mipmap/sb1" | |||
app:imagesrc_qt="@mipmap/sb2" | |||
app:imagesrc_tz="@mipmap/sb3" /> | |||
<com.bonait.bnframework.modules.home.fragment.mode.imagebuttom3 | |||
android:id="@+id/touliao2" | |||
android:layout_width="45dp" | |||
android:layout_height="90dp" | |||
android:contentDescription="" | |||
android:tag="投料-按钮" | |||
app:imagesrc_ks="@mipmap/sb1" | |||
app:imagesrc_qt="@mipmap/sb2" | |||
app:imagesrc_tz="@mipmap/sb3" /> | |||
<com.bonait.bnframework.modules.home.fragment.mode.imagebuttom3 | |||
android:id="@+id/touliao1" | |||
android:layout_width="45dp" | |||
android:layout_height="90dp" | |||
android:contentDescription="" | |||
android:tag="投料-按钮" | |||
app:imagesrc_ks="@mipmap/sb1" | |||
app:imagesrc_qt="@mipmap/sb2" | |||
app:imagesrc_tz="@mipmap/sb3" /> | |||
</LinearLayout> | |||
<!-- 调料 --> | |||
<LinearLayout | |||
android:layout_width="wrap_content" | |||
@@ -373,15 +276,7 @@ | |||
android:layout_marginRight="30dp" | |||
android:orientation="vertical"> | |||
<!-- <com.bonait.bnframework.modules.home.fragment.mode.imagebuttom3--> | |||
<!-- android:id="@+id/chushui"--> | |||
<!-- android:layout_width="140dp"--> | |||
<!-- android:layout_height="80dp"--> | |||
<!-- android:contentDescription=""--> | |||
<!-- android:tag="水-按钮"--> | |||
<!-- app:imagesrc_ks="@mipmap/sb1"--> | |||
<!-- app:imagesrc_qt="@mipmap/sb2"--> | |||
<!-- app:imagesrc_tz="@mipmap/sb3" />--> | |||
<com.bonait.bnframework.modules.home.fragment.mode.imagebuttom3 | |||
android:id="@+id/yeliao4" | |||
android:layout_width="140dp" | |||
@@ -459,56 +354,7 @@ | |||
android:textSize="50dp"></TextView> | |||
</RelativeLayout> | |||
<!-- 不透明蒙版 加水--> | |||
<RelativeLayout | |||
android:id="@+id/guoneichoushui" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:background="#BD25323F" | |||
android:clickable="true" | |||
android:focusable="true" | |||
android:visibility="gone"> | |||
<LinearLayout | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_centerInParent="true" | |||
android:orientation="vertical"> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:fontFamily="@font/fz2" | |||
android:text="抽水中..." | |||
android:textColor="@color/white" | |||
android:textSize="50dp" /> | |||
<Chronometer | |||
android:id="@+id/runtime_cs" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_marginTop="10dp" | |||
android:textAlignment="center" | |||
android:textColor="#DA5A17" | |||
android:textSize="50dp" | |||
android:textStyle="bold|italic" /> | |||
<RelativeLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_marginTop="40dp"> | |||
<ImageView | |||
android:id="@+id/tingzhijiashui" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_centerHorizontal="true" | |||
android:src="@mipmap/tingzhijiashui" /> | |||
</RelativeLayout> | |||
</LinearLayout> | |||
</RelativeLayout> | |||
</RelativeLayout> | |||
<LinearLayout | |||
@@ -764,91 +764,6 @@ | |||
android:textSize="16dp" /> | |||
</LinearLayout> | |||
</RelativeLayout> | |||
<!-- 临时屏蔽要钱 --> | |||
<RelativeLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:visibility="gone"> | |||
<LinearLayout | |||
android:layout_width="wrap_content" | |||
android:layout_height="match_parent" | |||
android:layout_alignParentRight="true" | |||
android:layout_marginRight="@dimen/dp_10"> | |||
<LinearLayout | |||
android:id="@+id/yaoqian" | |||
android:layout_width="wrap_content" | |||
android:layout_height="match_parent"> | |||
<RelativeLayout | |||
android:layout_width="26dp" | |||
android:layout_height="match_parent"> | |||
<ImageView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_centerInParent="true" | |||
android:src="@mipmap/start" /> | |||
</RelativeLayout> | |||
<RelativeLayout | |||
android:layout_width="wrap_content" | |||
android:layout_height="match_parent"> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_centerVertical="true" | |||
android:text="摇芡" /> | |||
</RelativeLayout> | |||
</LinearLayout> | |||
<!--边框分割细线--> | |||
<RelativeLayout | |||
android:layout_width="wrap_content" | |||
android:layout_height="match_parent" | |||
android:layout_marginLeft="5dp" | |||
android:layout_marginRight="5dp"> | |||
<LinearLayout | |||
android:layout_width="1dp" | |||
android:layout_height="30dp" | |||
android:layout_centerInParent="true" | |||
android:background="@color/activity_background" /> | |||
</RelativeLayout> | |||
<LinearLayout | |||
android:id="@+id/tingyao" | |||
android:layout_width="wrap_content" | |||
android:layout_height="match_parent"> | |||
<RelativeLayout | |||
android:layout_width="26dp" | |||
android:layout_height="match_parent"> | |||
<ImageView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_centerInParent="true" | |||
android:src="@mipmap/stop" /> | |||
</RelativeLayout> | |||
<RelativeLayout | |||
android:layout_width="wrap_content" | |||
android:layout_height="match_parent"> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_centerVertical="true" | |||
android:text="停摇" /> | |||
</RelativeLayout> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</RelativeLayout> | |||
</LinearLayout> | |||
<!-- 监控 --> | |||
@@ -226,102 +226,6 @@ | |||
</RelativeLayout> | |||
</LinearLayout> | |||
<!-- 投料 --> | |||
<LinearLayout | |||
android:id="@+id/touliao_k" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginLeft="18dp" | |||
android:layout_marginTop="155dp" | |||
android:orientation="horizontal"> | |||
<TextView | |||
android:layout_width="83dp" | |||
android:layout_height="wrap_content" | |||
android:text="④" | |||
android:textAlignment="center" | |||
android:textColor="@color/white" | |||
android:textSize="24dp" | |||
android:textStyle="bold" /> | |||
<TextView | |||
android:layout_width="83dp" | |||
android:layout_height="wrap_content" | |||
android:text="③" | |||
android:textAlignment="center" | |||
android:textColor="@color/white" | |||
android:textSize="24dp" | |||
android:textStyle="bold" /> | |||
<TextView | |||
android:layout_width="45dp" | |||
android:layout_height="wrap_content" | |||
android:text="②" | |||
android:textAlignment="center" | |||
android:textColor="@color/white" | |||
android:textSize="24dp" | |||
android:textStyle="bold" /> | |||
<TextView | |||
android:layout_width="45dp" | |||
android:layout_height="wrap_content" | |||
android:text="①" | |||
android:textAlignment="center" | |||
android:textColor="@color/white" | |||
android:textSize="24dp" | |||
android:textStyle="bold" /> | |||
</LinearLayout> | |||
<LinearLayout | |||
android:id="@+id/touliao_m" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_marginLeft="18dp" | |||
android:layout_marginTop="190dp" | |||
android:orientation="horizontal"> | |||
<com.bonait.bnframework.modules.home.fragment.mode.imagebuttom3 | |||
android:id="@+id/touliao4" | |||
android:layout_width="83dp" | |||
android:layout_height="80dp" | |||
android:contentDescription="true" | |||
android:tag="投料-按钮" | |||
app:imagesrc_ks="@mipmap/sb1" | |||
app:imagesrc_qt="@mipmap/sb2" | |||
app:imagesrc_tz="@mipmap/sb3" /> | |||
<com.bonait.bnframework.modules.home.fragment.mode.imagebuttom3 | |||
android:id="@+id/touliao3" | |||
android:layout_width="83dp" | |||
android:layout_height="80dp" | |||
android:contentDescription="true" | |||
android:tag="投料-按钮" | |||
app:imagesrc_ks="@mipmap/sb1" | |||
app:imagesrc_qt="@mipmap/sb2" | |||
app:imagesrc_tz="@mipmap/sb3" /> | |||
<com.bonait.bnframework.modules.home.fragment.mode.imagebuttom3 | |||
android:id="@+id/touliao2" | |||
android:layout_width="45dp" | |||
android:layout_height="80dp" | |||
android:contentDescription="true" | |||
android:tag="投料-按钮" | |||
app:imagesrc_ks="@mipmap/sb1" | |||
app:imagesrc_qt="@mipmap/sb2" | |||
app:imagesrc_tz="@mipmap/sb3" /> | |||
<com.bonait.bnframework.modules.home.fragment.mode.imagebuttom3 | |||
android:id="@+id/touliao1" | |||
android:layout_width="45dp" | |||
android:layout_height="80dp" | |||
android:contentDescription="true" | |||
android:tag="投料-按钮" | |||
app:imagesrc_ks="@mipmap/sb1" | |||
app:imagesrc_qt="@mipmap/sb2" | |||
app:imagesrc_tz="@mipmap/sb3" /> | |||
</LinearLayout> | |||
<!-- 水 --> | |||
<LinearLayout | |||
android:layout_width="wrap_content" | |||