WarningLightClient.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.ruoyi.hard.modbus.tcp;
  2. import com.jwk.spring.boot.autoconfigure.ModbusTcpMasterTemplate;
  3. import com.jwk.spring.boot.modbus4j.ModbusMasterUtil;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.beans.factory.annotation.Qualifier;
  7. import org.springframework.stereotype.Service;
  8. /**
  9. * 警报灯对接
  10. *
  11. * @author JWK
  12. * @version 1.0
  13. * @date 2022/04/16 21:04
  14. */
  15. @Slf4j
  16. @Service
  17. public class WarningLightClient {
  18. /**
  19. * 警报灯对接
  20. */
  21. @Autowired(required = false)
  22. @Qualifier("modbusTcpMasterTemplateEighth")
  23. private ModbusTcpMasterTemplate modbusTcpMasterTemplateEighth;
  24. /**
  25. * 开警报灯
  26. *
  27. * @return
  28. */
  29. public Boolean openWarningLight() {
  30. ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateEighth.getModbusMasterUtil();
  31. Boolean do1 = false;//打开DO1中间端
  32. Boolean do3 = false;//打开DO3中间端
  33. try {
  34. do1 = modbusMasterUtil.writeCoil(0x20, 0x0000, 0xFF00);
  35. do3 = modbusMasterUtil.writeCoil(0x20, 0x0002, 0xFF00);
  36. } catch (Exception e) {
  37. log.error("开警报灯失败!", e);
  38. }
  39. return do1 && do3;
  40. }
  41. /**
  42. * 关警报灯
  43. *
  44. * @return
  45. */
  46. public Boolean closeWarningLight() {
  47. ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateEighth.getModbusMasterUtil();
  48. Boolean do1 = false;//关闭DO1中间端
  49. Boolean do3 = false;//关闭DO3中间端
  50. try {
  51. do1 = modbusMasterUtil.writeCoil(0x20, 0x0000, 0x0000);//关闭DO1中间端
  52. do3 = modbusMasterUtil.writeCoil(0x20, 0x0002, 0x0000);//关闭DO3中间端
  53. } catch (Exception e) {
  54. log.error("关警报灯失败!", e);
  55. }
  56. return do1 && do3;
  57. }
  58. }