PLCHadnler.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package com.gzlh.device.plc.handler;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.gzlh.bus.EventConfig;
  4. import com.gzlh.config.dto.SerialSetting;
  5. import com.gzlh.device.plc.action.PLCAction;
  6. import com.gzlh.device.plc.client.PlcNettyConfig;
  7. import com.gzlh.utils.ModbusUtils;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.stereotype.Service;
  10. import javax.annotation.Resource;
  11. @Service
  12. @Slf4j
  13. public class PLCHadnler {
  14. @Resource
  15. private PlcNettyConfig plcNettyConfig;
  16. private final String COMMAND_PREFIX="010500";
  17. private final String COMMAND_ON="FF00";
  18. private final String COMMAND_OFF="0000";
  19. public void handlerAction(String action){
  20. SerialSetting serialSetting= EventConfig.serialSetting;
  21. if (StrUtil.equals(action, PLCAction.RED_LIGHT_ON)){
  22. //亮红灯
  23. String redPoint= serialSetting.getPlc().getOut().getSignalRedPoint();
  24. String command= COMMAND_PREFIX+redPoint+COMMAND_ON;
  25. log.info("plc发送消息:{}",command);
  26. String packData= ModbusUtils.buildRequestPacket(command);
  27. plcNettyConfig.send(packData);
  28. }else if (StrUtil.equals(action, PLCAction.RED_LIGHT_OFF)){
  29. //灭红灯
  30. String redPoint= serialSetting.getPlc().getOut().getSignalRedPoint();
  31. String command= COMMAND_PREFIX+redPoint+COMMAND_OFF;
  32. log.info("plc发送消息:{}",command);
  33. String packData= ModbusUtils.buildRequestPacket(command);
  34. plcNettyConfig.send(packData);
  35. }else if (StrUtil.equals(action, PLCAction.GREEN_LIGHT_ON)){
  36. //亮绿灯
  37. String greenPoint= serialSetting.getPlc().getOut().getSignalGreenPoint();
  38. String command= COMMAND_PREFIX+greenPoint+COMMAND_ON;
  39. log.info("plc发送消息:{}",command);
  40. String packData= ModbusUtils.buildRequestPacket(command);
  41. plcNettyConfig.send(packData);
  42. }else if (StrUtil.equals(action, PLCAction.GREEN_LIGHT_OFF)){
  43. //灭绿灯
  44. String greenPoint= serialSetting.getPlc().getOut().getSignalGreenPoint();
  45. String command= COMMAND_PREFIX+greenPoint+COMMAND_OFF;
  46. log.info("plc发送消息:{}",command);
  47. String packData= ModbusUtils.buildRequestPacket(command);
  48. plcNettyConfig.send(packData);
  49. }else if (StrUtil.equals(action, PLCAction.RAILING_RISE_ON)){
  50. //抬杆
  51. String gatePoint= serialSetting.getPlc().getOut().getGatePoint();
  52. String command= COMMAND_PREFIX+gatePoint+COMMAND_ON;
  53. log.info("plc发送消息:{}",command);
  54. String packData= ModbusUtils.buildRequestPacket(command);
  55. plcNettyConfig.send(packData);
  56. }else if (StrUtil.equals(action, PLCAction.RAILING_RISE_OFF)){
  57. //抬杆关闭
  58. String gatePoint= serialSetting.getPlc().getOut().getGatePoint();
  59. String command= COMMAND_PREFIX+gatePoint+COMMAND_OFF;
  60. log.info("plc发送消息:{}",command);
  61. String packData= ModbusUtils.buildRequestPacket(command);
  62. plcNettyConfig.send(packData);
  63. }
  64. }
  65. }