package com.ruoyi.hard.modbus.tcp; import com.jwk.spring.boot.autoconfigure.ModbusTcpMasterTemplate; import com.jwk.spring.boot.modbus4j.ModbusMasterUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; /** * 警报灯对接 * * @author JWK * @version 1.0 * @date 2022/04/16 21:04 */ @Slf4j @Service public class WarningLightClient { /** * 警报灯对接 */ @Autowired(required = false) @Qualifier("modbusTcpMasterTemplateEighth") private ModbusTcpMasterTemplate modbusTcpMasterTemplateEighth; /** * 开警报灯 * * @return */ public Boolean openWarningLight() { ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateEighth.getModbusMasterUtil(); Boolean do1 = false;//打开DO1中间端 Boolean do3 = false;//打开DO3中间端 try { do1 = modbusMasterUtil.writeCoil(0x20, 0x0000, 0xFF00); do3 = modbusMasterUtil.writeCoil(0x20, 0x0002, 0xFF00); } catch (Exception e) { log.error("开警报灯失败!", e); } return do1 && do3; } /** * 关警报灯 * * @return */ public Boolean closeWarningLight() { ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateEighth.getModbusMasterUtil(); Boolean do1 = false;//关闭DO1中间端 Boolean do3 = false;//关闭DO3中间端 try { do1 = modbusMasterUtil.writeCoil(0x20, 0x0000, 0x0000);//关闭DO1中间端 do3 = modbusMasterUtil.writeCoil(0x20, 0x0002, 0x0000);//关闭DO3中间端 } catch (Exception e) { log.error("关警报灯失败!", e); } return do1 && do3; } }