jx pcn plc pass step
parent
8761faceb6
commit
920c81e4cd
@ -0,0 +1,40 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.api.busi.jx;
|
||||
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesPlc;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* @Author: wangjie
|
||||
* @CreateDate: 2021/01/18 11:22 上午
|
||||
* @Description:
|
||||
**/
|
||||
public interface IJxPlcExtService {
|
||||
|
||||
/**
|
||||
* 获取PLC信息
|
||||
* @param organizeCode 组织代码
|
||||
* @param plcCode PLC代码
|
||||
* @return 产品条码信息
|
||||
*/
|
||||
@ApiOperation(value = "获取PLC信息", notes = "获取PLC信息")
|
||||
MesPlc getPlcDb(String organizeCode, String plcCode);
|
||||
|
||||
/**
|
||||
* 读取PLC数据
|
||||
* @param plc PLC信息
|
||||
* @return PLC数据
|
||||
*/
|
||||
@ApiOperation(value = "读取PLC数据", notes = "读取PLC数据")
|
||||
Object doReadOpcParamValue(MesPlc plc);
|
||||
|
||||
/**
|
||||
* 写入PLC数据
|
||||
* @param plc PLC信息
|
||||
* @param value 数据
|
||||
* @return 结果
|
||||
*/
|
||||
@ApiOperation(value = "写入PLC数据", notes = "写入PLC数据")
|
||||
Boolean doWriteOpcParamValue(MesPlc plc, String value);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.jx;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.busi.jx.IJxPlcExtService;
|
||||
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||
import cn.estsh.i3plus.platform.plugin.opc.iservice.IOpcUAService;
|
||||
import cn.estsh.i3plus.platform.plugin.opc.service.OpcUAService;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.hardswitch.bean.OpcUAParam;
|
||||
import cn.estsh.i3plus.pojo.mes.bean.MesPlc;
|
||||
import cn.estsh.i3plus.pojo.mes.repository.MesPlcRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
/**
|
||||
* @Author: wangjie
|
||||
* @CreateDate: 2021/01/18 11:41 上午
|
||||
* @Description:
|
||||
**/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class JxPlcExtService implements IJxPlcExtService {
|
||||
|
||||
@Autowired
|
||||
private MesPlcRepository plcRepository;
|
||||
|
||||
@Override
|
||||
public MesPlc getPlcDb(String organizeCode, String plcCode) {
|
||||
if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(plcCode)) return null;
|
||||
return plcRepository.getByProperty(
|
||||
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.PLC_CODE},
|
||||
new Object[]{organizeCode, CommonEnumUtil.IS_VAILD.VAILD.getValue(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), plcCode});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object doReadOpcParamValue(MesPlc plc) {
|
||||
IOpcUAService opcService = new OpcUAService();
|
||||
String tagAddress = MessageFormat.format("{0}.{1}.{2}", plc.getChannel(), plc.getDevice(), plc.getTagAddress());
|
||||
OpcUAParam opcParam = new OpcUAParam();
|
||||
opcParam.setServerUrl(plc.getOpcUrl());
|
||||
opcParam.setTagAddress(tagAddress);
|
||||
opcParam.setNamespaceIndex(plc.getNameSpaceIndex());
|
||||
opcParam.setTagValueType(plc.getDataType());
|
||||
Object result = opcService.getOpcParamValue(opcParam);
|
||||
opcService.disConnection();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean doWriteOpcParamValue(MesPlc plc, String value) {
|
||||
IOpcUAService opcService = new OpcUAService();
|
||||
String tagAddress = MessageFormat.format("{0}.{1}.{2}", plc.getChannel(), plc.getDevice(), plc.getTagAddress());
|
||||
OpcUAParam opcParam = new OpcUAParam();
|
||||
opcParam.setServerUrl(plc.getOpcUrl());
|
||||
opcParam.setTagAddress(tagAddress);
|
||||
opcParam.setNamespaceIndex(plc.getNameSpaceIndex());
|
||||
opcParam.setTagValueType(plc.getDataType());
|
||||
opcParam.setTagValue(value);
|
||||
Boolean result = opcService.editOpcParamValue(opcParam);
|
||||
opcService.disConnection();
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue