12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package com.gzlh.device.plc.handler;
- import cn.hutool.core.util.StrUtil;
- import com.gzlh.bus.EventConfig;
- import com.gzlh.config.dto.SerialSetting;
- import com.gzlh.device.plc.action.PLCAction;
- import com.gzlh.device.plc.client.PlcNettyConfig;
- import com.gzlh.utils.ModbusUtils;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- @Service
- @Slf4j
- public class PLCHadnler {
- @Resource
- private PlcNettyConfig plcNettyConfig;
- private final String COMMAND_PREFIX="010500";
- private final String COMMAND_ON="FF00";
- private final String COMMAND_OFF="0000";
- public void handlerAction(String action){
- SerialSetting serialSetting= EventConfig.serialSetting;
- if (StrUtil.equals(action, PLCAction.RED_LIGHT_ON)){
- //亮红灯
- String redPoint= serialSetting.getPlc().getOut().getSignalRedPoint();
- String command= COMMAND_PREFIX+redPoint+COMMAND_ON;
- log.info("plc发送消息:{}",command);
- String packData= ModbusUtils.buildRequestPacket(command);
- plcNettyConfig.send(packData);
- }else if (StrUtil.equals(action, PLCAction.RED_LIGHT_OFF)){
- //灭红灯
- String redPoint= serialSetting.getPlc().getOut().getSignalRedPoint();
- String command= COMMAND_PREFIX+redPoint+COMMAND_OFF;
- log.info("plc发送消息:{}",command);
- String packData= ModbusUtils.buildRequestPacket(command);
- plcNettyConfig.send(packData);
- }else if (StrUtil.equals(action, PLCAction.GREEN_LIGHT_ON)){
- //亮绿灯
- String greenPoint= serialSetting.getPlc().getOut().getSignalGreenPoint();
- String command= COMMAND_PREFIX+greenPoint+COMMAND_ON;
- log.info("plc发送消息:{}",command);
- String packData= ModbusUtils.buildRequestPacket(command);
- plcNettyConfig.send(packData);
- }else if (StrUtil.equals(action, PLCAction.GREEN_LIGHT_OFF)){
- //灭绿灯
- String greenPoint= serialSetting.getPlc().getOut().getSignalGreenPoint();
- String command= COMMAND_PREFIX+greenPoint+COMMAND_OFF;
- log.info("plc发送消息:{}",command);
- String packData= ModbusUtils.buildRequestPacket(command);
- plcNettyConfig.send(packData);
- }else if (StrUtil.equals(action, PLCAction.RAILING_RISE_ON)){
- //抬杆
- String gatePoint= serialSetting.getPlc().getOut().getGatePoint();
- String command= COMMAND_PREFIX+gatePoint+COMMAND_ON;
- log.info("plc发送消息:{}",command);
- String packData= ModbusUtils.buildRequestPacket(command);
- plcNettyConfig.send(packData);
- }else if (StrUtil.equals(action, PLCAction.RAILING_RISE_OFF)){
- //抬杆关闭
- String gatePoint= serialSetting.getPlc().getOut().getGatePoint();
- String command= COMMAND_PREFIX+gatePoint+COMMAND_OFF;
- log.info("plc发送消息:{}",command);
- String packData= ModbusUtils.buildRequestPacket(command);
- plcNettyConfig.send(packData);
- }
- }
- }
|