|
|
@ -1,8 +1,10 @@
|
|
|
|
package com.ruoyi.business.service.impl;
|
|
|
|
package com.ruoyi.business.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import HslCommunication.Core.Transfer.DataFormat;
|
|
|
|
import HslCommunication.Core.Transfer.DataFormat;
|
|
|
|
|
|
|
|
import HslCommunication.Core.Types.OperateResult;
|
|
|
|
import HslCommunication.Core.Types.OperateResultExOne;
|
|
|
|
import HslCommunication.Core.Types.OperateResultExOne;
|
|
|
|
import HslCommunication.ModBus.ModbusTcpNet;
|
|
|
|
import HslCommunication.ModBus.ModbusTcpNet;
|
|
|
|
|
|
|
|
import HslCommunication.Profinet.AllenBradley.AllenBradleyNet;
|
|
|
|
import HslCommunication.Profinet.Melsec.MelsecA1ENet;
|
|
|
|
import HslCommunication.Profinet.Melsec.MelsecA1ENet;
|
|
|
|
import HslCommunication.Profinet.Melsec.MelsecFxSerialOverTcp;
|
|
|
|
import HslCommunication.Profinet.Melsec.MelsecFxSerialOverTcp;
|
|
|
|
import HslCommunication.Profinet.Melsec.MelsecHelper;
|
|
|
|
import HslCommunication.Profinet.Melsec.MelsecHelper;
|
|
|
@ -28,6 +30,13 @@ import com.ruoyi.tdengine.api.RemoteTdEngineService;
|
|
|
|
import com.ruoyi.tdengine.api.domain.AlterTagVo;
|
|
|
|
import com.ruoyi.tdengine.api.domain.AlterTagVo;
|
|
|
|
import com.ruoyi.tdengine.api.domain.TdField;
|
|
|
|
import com.ruoyi.tdengine.api.domain.TdField;
|
|
|
|
import com.ruoyi.tdengine.api.domain.TdTableVo;
|
|
|
|
import com.ruoyi.tdengine.api.domain.TdTableVo;
|
|
|
|
|
|
|
|
import org.apache.plc4x.java.PlcDriverManager;
|
|
|
|
|
|
|
|
import org.apache.plc4x.java.api.PlcConnection;
|
|
|
|
|
|
|
|
import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
|
|
|
|
|
|
|
|
import org.apache.plc4x.java.api.messages.PlcReadRequest;
|
|
|
|
|
|
|
|
import org.apache.plc4x.java.api.messages.PlcReadResponse;
|
|
|
|
|
|
|
|
import org.apache.plc4x.java.api.metadata.PlcConnectionMetadata;
|
|
|
|
|
|
|
|
import org.apache.plc4x.java.ethernetip.EtherNetIpPlcDriver;
|
|
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@ -41,6 +50,7 @@ import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* plc设备信息(PlcDevice)表服务实现类
|
|
|
|
* plc设备信息(PlcDevice)表服务实现类
|
|
|
@ -316,60 +326,70 @@ public class PlcDeviceServiceImpl implements PlcDeviceService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//link数据读取
|
|
|
|
//EtherNet协议数据读取
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String linkDataProcess() {
|
|
|
|
public String ehternetDataProcess() throws JsonProcessingException {
|
|
|
|
// List<PlcDevice> plcDevices = this.plcDeviceDao.queryPlcDevices(1);
|
|
|
|
// AllenBradleyNet plc = new AllenBradleyNet("127.0.0.1",44818);
|
|
|
|
// for (PlcDevice plcDevice : plcDevices) {
|
|
|
|
// OperateResult operateResult = plc.ConnectServer();
|
|
|
|
// int station = plcDevice.getStation();
|
|
|
|
// OperateResultExOne<String> f = plc.ReadString("F");
|
|
|
|
// byte a = (byte)station;
|
|
|
|
// String content = f.Content;
|
|
|
|
// int length = plcDevice.getLength();
|
|
|
|
// return null;
|
|
|
|
// short b = (short)length;
|
|
|
|
List<PlcDevice> plcDevices = this.plcDeviceDao.queryPlcDevices(4);
|
|
|
|
// // ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a);
|
|
|
|
for (PlcDevice plcDevice : plcDevices) {
|
|
|
|
// // tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB);
|
|
|
|
int station = plcDevice.getStation();
|
|
|
|
// MelsecA1ENet net = new MelsecA1ENet(plcDevice.getIp(),plcDevice.getPort1());
|
|
|
|
byte a = (byte)station;
|
|
|
|
// MelsecFxSerialOverTcp melsecFxSerialOverTcp = new MelsecFxSerialOverTcp();
|
|
|
|
int length = plcDevice.getLength();
|
|
|
|
// TdTableVo tdTableVo = new TdTableVo();
|
|
|
|
short b = (short)length;
|
|
|
|
// List<TdField> schemaFields = new ArrayList<>();
|
|
|
|
// ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a);
|
|
|
|
// TdField firstTdField = new TdField();
|
|
|
|
// tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB);
|
|
|
|
// firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
|
|
|
|
AllenBradleyNet ethernet = new AllenBradleyNet(plcDevice.getIp(),plcDevice.getPort1());
|
|
|
|
// long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
TdTableVo tdTableVo = new TdTableVo();
|
|
|
|
// firstTdField.setFieldValue(currentTimeMillis);
|
|
|
|
List<TdField> schemaFields = new ArrayList<>();
|
|
|
|
// String databaseName = TdEngineConstants.getDatabaseName();
|
|
|
|
TdField firstTdField = new TdField();
|
|
|
|
// String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId();
|
|
|
|
firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
|
|
|
|
// // firstTdField.setFieldValue(ts);
|
|
|
|
long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
// schemaFields.add(firstTdField);
|
|
|
|
firstTdField.setFieldValue(currentTimeMillis);
|
|
|
|
// List<PlcDeviceModeFunction> list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId());
|
|
|
|
String databaseName = TdEngineConstants.getDatabaseName();
|
|
|
|
// if (plcDevice.getDataType().equals("10")){
|
|
|
|
String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId();
|
|
|
|
// OperateResultExOne<String> resultExOne = net.ReadString(plcDevice.getLocation(),b, StandardCharsets.UTF_8);
|
|
|
|
// firstTdField.setFieldValue(ts);
|
|
|
|
// String content = resultExOne.Content;
|
|
|
|
schemaFields.add(firstTdField);
|
|
|
|
// ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
List<PlcDeviceModeFunction> list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId());
|
|
|
|
// Map map = objectMapper.readValue(content, Map.class);
|
|
|
|
if (plcDevice.getDataType().equals("10")){
|
|
|
|
// for (PlcDeviceModeFunction function : list) {
|
|
|
|
OperateResultExOne<String> resultExOne = ethernet.ReadString(plcDevice.getLocation(),b, StandardCharsets.UTF_8);
|
|
|
|
// Object value = map.get(function.getFunctionIdentifier());
|
|
|
|
String content = resultExOne.Content;
|
|
|
|
// TdField tdField = new TdField();
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
// tdField.setFieldName(function.getFunctionIdentifier());
|
|
|
|
Map map = objectMapper.readValue(content, Map.class);
|
|
|
|
// tdField.setFieldValue(value);
|
|
|
|
for (PlcDeviceModeFunction function : list) {
|
|
|
|
// schemaFields.add(tdField);
|
|
|
|
Object value = map.get(function.getFunctionIdentifier());
|
|
|
|
// }
|
|
|
|
TdField tdField = new TdField();
|
|
|
|
// }else if (plcDevice.getDataType().equals("2")){
|
|
|
|
tdField.setFieldName(function.getFunctionIdentifier());
|
|
|
|
// OperateResultExOne<Integer> exOne = net.ReadInt32(plcDevice.getLocation());
|
|
|
|
tdField.setFieldValue(value);
|
|
|
|
// TdField tdField = new TdField();
|
|
|
|
schemaFields.add(tdField);
|
|
|
|
// tdField.setFieldName(list.get(0).getFunctionIdentifier());
|
|
|
|
}
|
|
|
|
// tdField.setFieldValue(exOne.Content);
|
|
|
|
}else if (plcDevice.getDataType().equals("2")||plcDevice.getDataType().equals("9")){
|
|
|
|
// schemaFields.add(tdField);
|
|
|
|
OperateResultExOne<Integer> exOne = ethernet.ReadInt32(plcDevice.getLocation());
|
|
|
|
// }else if (plcDevice.getDataType().equals("4")){
|
|
|
|
TdField tdField = new TdField();
|
|
|
|
// OperateResultExOne<Float> floatOperateResultExOne = net.ReadFloat(plcDevice.getLocation());
|
|
|
|
tdField.setFieldName(list.get(0).getFunctionIdentifier());
|
|
|
|
// TdField tdField = new TdField();
|
|
|
|
tdField.setFieldValue(exOne.Content);
|
|
|
|
// tdField.setFieldName(list.get(0).getFunctionIdentifier());
|
|
|
|
schemaFields.add(tdField);
|
|
|
|
// tdField.setFieldValue(floatOperateResultExOne.Content);
|
|
|
|
}else if (plcDevice.getDataType().equals("4")){
|
|
|
|
// schemaFields.add(tdField);
|
|
|
|
OperateResultExOne<Float> floatOperateResultExOne = ethernet.ReadFloat(plcDevice.getLocation());
|
|
|
|
// }
|
|
|
|
TdField tdField = new TdField();
|
|
|
|
// tdTableVo.setDatabaseName(databaseName);
|
|
|
|
tdField.setFieldName(list.get(0).getFunctionIdentifier());
|
|
|
|
// tdTableVo.setTableName(tableName);
|
|
|
|
tdField.setFieldValue(floatOperateResultExOne.Content);
|
|
|
|
// tdTableVo.setSchemaFields(schemaFields);
|
|
|
|
schemaFields.add(tdField);
|
|
|
|
// final R<?> insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER);
|
|
|
|
}else if (plcDevice.getDataType().equals("5")){
|
|
|
|
// }
|
|
|
|
OperateResultExOne<Double> doubleOperateResultExOne = ethernet.ReadDouble(plcDevice.getLocation());
|
|
|
|
|
|
|
|
TdField tdField = new TdField();
|
|
|
|
|
|
|
|
tdField.setFieldName(list.get(0).getFunctionIdentifier());
|
|
|
|
|
|
|
|
tdField.setFieldValue(doubleOperateResultExOne.Content);
|
|
|
|
|
|
|
|
schemaFields.add(tdField);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
tdTableVo.setDatabaseName(databaseName);
|
|
|
|
|
|
|
|
tdTableVo.setTableName(tableName);
|
|
|
|
|
|
|
|
tdTableVo.setSchemaFields(schemaFields);
|
|
|
|
|
|
|
|
final R<?> insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER);
|
|
|
|
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|