feat():OPC UA 示例
This commit is contained in:
@@ -1,33 +1,36 @@
|
|||||||
package com.fizz.business.scheduled;
|
package com.fizz.business.comm.OPC;
|
||||||
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import com.fizz.business.constants.enums.OpcMessageType;
|
||||||
|
import com.fizz.business.domain.msg.AppMeasureMessage;
|
||||||
|
import com.fizz.business.scheduled.BaseSchedule;
|
||||||
|
import com.fizz.business.service.hanle.OpcReceiverHandler;
|
||||||
import com.kangaroohy.milo.model.ReadWriteEntity;
|
import com.kangaroohy.milo.model.ReadWriteEntity;
|
||||||
import com.kangaroohy.milo.service.MiloService;
|
import com.kangaroohy.milo.service.MiloService;
|
||||||
import jdk.nashorn.internal.runtime.Debug;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
//@Component
|
//@Component
|
||||||
@AllArgsConstructor
|
public class MessageReceiveSchedule extends BaseSchedule {
|
||||||
public class LineMeasureSchedule extends BaseSchedule{
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
MiloService miloService;
|
MiloService miloService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
OpcReceiverHandler opcReceiverHandler;
|
||||||
@Scheduled(fixedDelay = 200)
|
@Scheduled(fixedDelay = 200)
|
||||||
public void L1L2LineMeasure() {
|
public void L1L2LineMeasure() {
|
||||||
try {
|
try {
|
||||||
ReadWriteEntity node = miloService.readFromOpcUa("ns=2;s=通道 2.LockStautsRead.lockStauts1");
|
ReadWriteEntity node = miloService.readFromOpcUa("ns=2;s=通道 2.LockStautsRead.lockStauts1");
|
||||||
log.debug(node.toString());
|
log.debug(node.toString());
|
||||||
node.getValue();
|
|
||||||
|
AppMeasureMessage msg = new AppMeasureMessage();
|
||||||
|
opcReceiverHandler.onMessageReceived(OpcMessageType.APP_MEASURE,msg);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
log.error("读取测量值失败:{0}",e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.fizz.business.comm.OPC;
|
||||||
|
|
||||||
|
import com.fizz.business.constants.enums.OpcMessageType;
|
||||||
|
import com.fizz.business.domain.msg.AppMeasureMessage;
|
||||||
|
import com.kangaroohy.milo.model.ReadWriteEntity;
|
||||||
|
import com.kangaroohy.milo.service.MiloService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.compress.utils.Lists;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.ApplicationArguments;
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
//@Component
|
||||||
|
@Slf4j
|
||||||
|
public class MessageSubscriptionRunner implements ApplicationRunner {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MiloService miloService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(ApplicationArguments args) {
|
||||||
|
subEntryMove();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void subEntryMove() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
List<String> ids = Lists.newArrayList();
|
||||||
|
ids.add("GA.T1.T1001R");
|
||||||
|
ids.add("GA.T1.String");
|
||||||
|
miloService.subscriptionFromOpcUa(ids, (id, value) -> {
|
||||||
|
log.info("subscription 点位:{} 订阅到消息:{}", id, value);
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("EntryMove 订阅失败:{0}",e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.fizz.business.comm.OPC;
|
||||||
|
|
||||||
|
import com.fizz.business.domain.msg.PdiSetup;
|
||||||
|
import com.kangaroohy.milo.model.ReadWriteEntity;
|
||||||
|
import com.kangaroohy.milo.service.MiloService;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.apache.commons.compress.utils.Lists;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Log4j2
|
||||||
|
public class OpcMessageSend {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MiloService miloService;
|
||||||
|
|
||||||
|
private void sendPdiSetup(PdiSetup pdiSetup) throws Exception {
|
||||||
|
try {
|
||||||
|
List<ReadWriteEntity> entities = new ArrayList<>();
|
||||||
|
miloService.writeToOpcUa(entities);
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送设定失败:{0}",e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.fizz.business.mq.RabbitMQ;
|
package com.fizz.business.comm.RabbitMQ;
|
||||||
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.fizz.business.constants.CommonConstants;
|
import com.fizz.business.constants.CommonConstants;
|
||||||
@@ -2,7 +2,7 @@ package com.fizz.business.controller;
|
|||||||
|
|
||||||
|
|
||||||
import com.fizz.business.form.WebOperateMatForm;
|
import com.fizz.business.form.WebOperateMatForm;
|
||||||
import com.fizz.business.mq.RabbitMQ.RabbitQueueListener;
|
import com.fizz.business.comm.RabbitMQ.RabbitQueueListener;
|
||||||
import com.fizz.business.service.TrackService;
|
import com.fizz.business.service.TrackService;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.fizz.business.domain.msg;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Schema(description = "设定电文")
|
||||||
|
public class PdiSetup {
|
||||||
|
@Schema(description = "钢卷号")
|
||||||
|
private String coilNo;
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.fizz.business.service.manager;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class OpcMessageIdsManager {
|
||||||
|
private static Map<String,String> lineMeasureIds = Maps.newHashMap();
|
||||||
|
private static Map<String,String> entryMoveIds = Maps.newHashMap();
|
||||||
|
private static Map<String,String> exitCutIds = Maps.newHashMap();
|
||||||
|
private static Map<String,String> exitMeasureIds = Maps.newHashMap();
|
||||||
|
private static Map<String,String> exitMoveIds = Maps.newHashMap();
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public static void init() {
|
||||||
|
|
||||||
|
//TODO load from database
|
||||||
|
loadEntryMoveIds();
|
||||||
|
loadExitCutIds();
|
||||||
|
loadExitMeasureIds();
|
||||||
|
loadExitMoveIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadEntryMoveIds(){
|
||||||
|
entryMoveIds.put("ns=2;s=通道 2.LockStautsRead.lockStauts1","materialPlaceSource");
|
||||||
|
entryMoveIds.put("ns=2;s=通道 2.LockStautsRead.lockStauts1","materialPlaceDestination");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadExitCutIds(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadExitMeasureIds(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadExitMoveIds(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user