|
|
@@ -0,0 +1,291 @@ |
|
|
|
package com.bonait.bnframework.business; |
|
|
|
|
|
|
|
import com.bonait.bnframework.HBL.Communication.Modbus.ExceptionServer; |
|
|
|
import com.bonait.bnframework.common.constant.ConfigName; |
|
|
|
import com.bonait.bnframework.common.db.mode.Res_PLCADDRESS; |
|
|
|
import com.bonait.bnframework.modbus.WokModbusTcpServer; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Comparator; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
public class PlcReadHelper { |
|
|
|
public PlcReadHelper(){ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public List<Res_PLCADDRESS> PlcAddress_Wok= new ArrayList<Res_PLCADDRESS>() {{ |
|
|
|
|
|
|
|
//硬件设备 初始化 |
|
|
|
add(new Res_PLCADDRESS("硬件设备", "-------------", 0, 0)); |
|
|
|
add(new Res_PLCADDRESS("初始化", "M10.0", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("急停", "M10.1", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("复位", "M10.2", 1, 1)); |
|
|
|
|
|
|
|
//搅拌模型 |
|
|
|
add(new Res_PLCADDRESS("模型控制", "-------------", 0, 0)); |
|
|
|
add(new Res_PLCADDRESS("搅拌", "M10.3", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("搅拌速度", "VW102", 1, 1)); |
|
|
|
|
|
|
|
//翻转正转模型 |
|
|
|
add(new Res_PLCADDRESS("翻转正转", "M10.4", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("翻转反转", "M10.5", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("转动速度", "VW104", 1, 1)); |
|
|
|
|
|
|
|
|
|
|
|
//加热模型 |
|
|
|
add(new Res_PLCADDRESS("加热", "M10.6", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("加热功率", "VW100", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("温控开关", "M17.6", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("暂停开关", "M17.7", 1, 1)); |
|
|
|
|
|
|
|
|
|
|
|
//抽水放水 |
|
|
|
add(new Res_PLCADDRESS("炒锅抽水", "M10.7", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("炒锅放水", "M11.0", 1, 1)); |
|
|
|
|
|
|
|
|
|
|
|
//出菜模型 |
|
|
|
add(new Res_PLCADDRESS("出菜", "M11.5", 1, 1)); |
|
|
|
|
|
|
|
|
|
|
|
//位置动作 |
|
|
|
add(new Res_PLCADDRESS("原点位", "M11.4", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("倒菜位", "M12.7", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("抽料位", "M11.7", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("维护位", "M20.0", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("清洗位", "M13.0", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("炒菜位1", "M12.0", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("炒菜位高", "M12.1", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("炒菜位2", "M12.1", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("炒菜位低", "M12.2", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("炒菜位3", "M12.2", 1, 1)); |
|
|
|
|
|
|
|
add(new Res_PLCADDRESS("出餐启动", "M11.5", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("炒锅清洗", "M11.6", 1, 1)); |
|
|
|
|
|
|
|
//深度清洗功能 |
|
|
|
add(new Res_PLCADDRESS("深度清洗功能", "-------------", 0, 0)); |
|
|
|
add(new Res_PLCADDRESS("清洗抽水量", "VW122", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("清洗时间", "VW1150", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("倒水减速角度", "VW1152", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("深度清洗", "M13.6", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("编码器复位", "M13.7", 1, 1)); |
|
|
|
|
|
|
|
//液体料模型 |
|
|
|
add(new Res_PLCADDRESS("料仓校准", "-------------", 0, 0)); |
|
|
|
add(new Res_PLCADDRESS("校准时间", "VW112", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓1校准开关", "M12.3", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓1校准值", "VW114", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓2校准开关", "M12.4", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓2校准值", "VW116", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓3校准开关", "M12.5", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓3校准值", "VW118", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓4校准开关", "M13.5", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓4校准值", "VW120", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("开始校正", "M12.6", 1, 1)); |
|
|
|
|
|
|
|
add(new Res_PLCADDRESS("料仓自动", "-------------", 0, 0)); |
|
|
|
add(new Res_PLCADDRESS("料仓1需求值", "VW106", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓1下料", "M11.1", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓2需求值", "VW108", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓2下料", "M11.2", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓3需求值", "VW110", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓3下料", "M11.3", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓4需求值", "VW122", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓4下料", "M13.4", 1, 1)); |
|
|
|
|
|
|
|
add(new Res_PLCADDRESS("料仓手动", "-------------", 0, 0)); |
|
|
|
add(new Res_PLCADDRESS("料仓1手动开关", "M13.1", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓2手动开关", "M13.2", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓3手动开关", "M13.3", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("料仓4手动开关", "M10.7", 1, 1)); |
|
|
|
|
|
|
|
//上下限 |
|
|
|
add(new Res_PLCADDRESS("位置上下限", "-------------", 0, 0)); |
|
|
|
add(new Res_PLCADDRESS("原点位置下限", "VD150", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("原点位置上限", "VD154", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("洗锅位置下限", "VD158", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("洗锅位置上限", "VD162", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("倒菜位置下限", "VD166", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("倒菜位置上限", "VD170", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("抽调料位置下限", "VD174", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("抽调料位置上限", "VD178", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("1#炒制位置下限", "VD182", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("1#炒制位置上限", "VD186", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("2#炒制位置下限", "VD190", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("2#炒制位置上限", "VD194", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("3#炒制位置下限", "VD198", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("3#炒制位置上限", "VD202", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("炒锅工作范围下限", "VD206", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("炒锅工作范围上限", "VD210", 1, 1)); |
|
|
|
|
|
|
|
//反馈信号 |
|
|
|
add(new Res_PLCADDRESS("反馈信号", "-------------", 0, 0)); |
|
|
|
add(new Res_PLCADDRESS("初始化完成", "M40.0", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("设备急停", "M40.1", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("原点位反馈", "M40.2", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("抽料位反馈", "M40.3", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("炒菜位1反馈", "M40.4", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("炒菜位2反馈", "M40.5", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("炒菜位高反馈", "M40.5", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("炒菜位低反馈", "M40.6", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("炒菜位3反馈", "M40.6", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("倒菜位反馈", "M40.7", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("投料位反馈", "M41.0", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("清洗位反馈", "M41.1", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("料仓1下料完成", "M41.2", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("料仓2下料完成", "M41.3", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("料仓3下料完成", "M41.4", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("料仓4下料完成", "M42.0", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("炒锅清洗反馈", "M41.5", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("出餐启动反馈", "M41.6", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("炒锅倒菜减速位", "M41.7", 1, 0)); |
|
|
|
|
|
|
|
|
|
|
|
add(new Res_PLCADDRESS("倒菜完成", "M44.4", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("心跳位", "VW1000", 1, 1)); |
|
|
|
|
|
|
|
add(new Res_PLCADDRESS("温度模拟输入量", "-------------", 0, 0)); |
|
|
|
add(new Res_PLCADDRESS("温度模拟量上限", "VW1050", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("温度模拟量下限", "VW1052", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("温度模拟量", "VW1054", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("温度量程上限", "VD1060", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("温度量程下限", "VD1056", 1, 1)); |
|
|
|
|
|
|
|
add(new Res_PLCADDRESS("电流模拟输入量", "-------------", 0, 0)); |
|
|
|
add(new Res_PLCADDRESS("电流模拟量上限", "VW1070", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("电流模拟量下限", "VW1072", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("电流模拟量", "VW1074", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("电流量程上限", "VD1080", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("电流量程下限", "VD1076", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("电流报警设置", "VW1092", 1, 1)); |
|
|
|
add(new Res_PLCADDRESS("异常加热故障信息", "M42.1", 1, 1)); |
|
|
|
|
|
|
|
//检测信号 |
|
|
|
add(new Res_PLCADDRESS("监测信号", "-------------", 0, 0)); |
|
|
|
add(new Res_PLCADDRESS("当前锅底温度", "VD300", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("炒锅搅拌转速", "VD304", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("当前加热档位", "VD308", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("炒锅当前电压", "VD312", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("炒锅当前电流", "VD316", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("炒锅当前功率", "VD320", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("搅拌频率", "VW324", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("搅拌电机电流", "VW326", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("搅拌电机电压", "VW328", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("搅拌变频器温度", "VW330", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("翻转频率", "VW332", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("翻转电机电流", "VW334", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("翻转电机电压", "VW336", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("翻转变频器温度", "VW338", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("编码器当前位值", "VD340", 1, 0)); |
|
|
|
|
|
|
|
//状态上报 |
|
|
|
add(new Res_PLCADDRESS("状态上报", "-------------", 0, 0)); |
|
|
|
add(new Res_PLCADDRESS("搅拌电机", "VW350", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("翻转电机", "VW352", 1, 0)); |
|
|
|
add(new Res_PLCADDRESS("炒锅", "VW354", 1, 0)); |
|
|
|
|
|
|
|
}}; |
|
|
|
|
|
|
|
|
|
|
|
public LinkedHashMap<String,Object> PlcStatus=new LinkedHashMap<>(); |
|
|
|
LinkedHashMap<String,LinkedHashMap<Integer,List<ReadModel>>> addGroup =new LinkedHashMap<>(); |
|
|
|
public void Init(){ |
|
|
|
List<Res_PLCADDRESS> PlcAdd =PlcAddress_Wok.stream().filter(p->p.isread==1).collect(Collectors.toList()); |
|
|
|
if(PlcAdd!=null && PlcAdd.size()>0){ |
|
|
|
//地址转换对象 |
|
|
|
ExceptionServer es = new ExceptionServer(); |
|
|
|
|
|
|
|
//Bool数据类型分组 |
|
|
|
List<Res_PLCADDRESS> boolData = PlcAdd.stream().filter(p->p.address.toUpperCase().contains("M")).collect(Collectors.toList()); |
|
|
|
if(boolData!=null&&boolData.size()>0){ |
|
|
|
List<ReadModel> boolReadModel = new ArrayList<>(); |
|
|
|
boolData.forEach(item->{ boolReadModel.add(new ReadModel(item.name,item.address,es.GetAddress(item.address)));}); |
|
|
|
addGroup.put("M",groupBy(boolReadModel)); |
|
|
|
} |
|
|
|
|
|
|
|
//Short数据类型分组 |
|
|
|
List<Res_PLCADDRESS> shortData = PlcAdd.stream().filter(p->p.address.toUpperCase().contains("VW")).collect(Collectors.toList()); |
|
|
|
if(shortData!=null&&shortData.size()>0){ |
|
|
|
List<ReadModel> shortReadModel = new ArrayList<>(); |
|
|
|
shortData.forEach(item->{ shortReadModel.add(new ReadModel(item.name,item.address,es.GetAddress(item.address)));}); |
|
|
|
addGroup.put("VW",groupBy(shortReadModel)); |
|
|
|
} |
|
|
|
|
|
|
|
//int 数据类型分组 |
|
|
|
List<Res_PLCADDRESS> intData = PlcAdd.stream().filter(p->p.address.toUpperCase().contains("VD")).collect(Collectors.toList()); |
|
|
|
if(intData!=null&&intData.size()>0){ |
|
|
|
List<ReadModel> intReadModel = new ArrayList<>(); |
|
|
|
intData.forEach(item->{ intReadModel.add(new ReadModel(item.name,item.address,es.GetAddress(item.address)));}); |
|
|
|
addGroup.put("VD",groupBy(intReadModel)); |
|
|
|
} |
|
|
|
|
|
|
|
//float数据类型分组 |
|
|
|
List<Res_PLCADDRESS> floatData = PlcAdd.stream().filter(p->p.address.toUpperCase().contains("VR")).collect(Collectors.toList()); |
|
|
|
if(floatData!=null&&floatData.size()>0){ |
|
|
|
List<ReadModel> floatReadModel = new ArrayList<>(); |
|
|
|
floatData.forEach(item->{ floatReadModel.add(new ReadModel(item.name,item.address,es.GetAddress(item.address)));}); |
|
|
|
addGroup.put("VR",groupBy(floatReadModel)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void read(){ |
|
|
|
for(Map.Entry<String,LinkedHashMap<Integer,List<ReadModel>>> item:addGroup.entrySet()){ |
|
|
|
for(Map.Entry<Integer,List<ReadModel>> add:addGroup.get(item.getKey()).entrySet()){ |
|
|
|
if (item.getKey().startsWith("VD"))//int |
|
|
|
{ |
|
|
|
WokModbusTcpServer.get().ReadInt(add.getValue().get(0).plcAddress, add.getValue().size(), ints -> { |
|
|
|
for (int i = 0; i < ints.length; i++) { |
|
|
|
PlcStatus.put(add.getValue().get(i).name,ints[i]); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (item.getKey().startsWith("M"))//bool |
|
|
|
{ |
|
|
|
WokModbusTcpServer.get().ReadBool(add.getValue().get(0).plcAddress, add.getValue().size(), val -> { |
|
|
|
for (int i = 0; i < val.length; i++) { |
|
|
|
PlcStatus.put(add.getValue().get(i).name,val[i]); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (item.getKey().startsWith("VW"))//short |
|
|
|
{ |
|
|
|
WokModbusTcpServer.get().ReadShort(add.getValue().get(0).plcAddress, add.getValue().size(), val -> { |
|
|
|
for (int i = 0; i < val.length; i++) { |
|
|
|
PlcStatus.put(add.getValue().get(i).name,val[i]); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (item.getKey().startsWith("VR"))//float |
|
|
|
{ |
|
|
|
WokModbusTcpServer.get().ReadFloat(add.getValue().get(0).plcAddress, add.getValue().size(), val -> { |
|
|
|
for (int i = 0; i < val.length; i++) { |
|
|
|
PlcStatus.put(add.getValue().get(i).name,val[i]); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public LinkedHashMap<Integer,List<ReadModel>> groupBy(List<ReadModel> data){ |
|
|
|
if(data==null) return new LinkedHashMap<>(); |
|
|
|
Collections.sort(data, Comparator.comparingInt(ReadModel::getModbusAddress));//进行排序 |
|
|
|
LinkedHashMap<Integer,List<ReadModel>> result = new LinkedHashMap<>(); |
|
|
|
int groupNum=0; |
|
|
|
for(ReadModel value:data){ |
|
|
|
String addStr = value.plcAddress.toUpperCase(); |
|
|
|
int offset = addStr.contains("M")||addStr.contains("VW")?1:2; |
|
|
|
if(!result.containsKey(groupNum) || result.get(groupNum).get(result.get(groupNum).size()-1).getModbusAddress()+offset!=value.getModbusAddress()){ |
|
|
|
groupNum++; |
|
|
|
} |
|
|
|
if(!result.containsKey(groupNum))result.put(groupNum,new ArrayList<>()); |
|
|
|
result.get(groupNum).add(value); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
} |