package com.szpg; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import com.szpg.db.dao.impl.PgAcuDaoImpl; import com.szpg.db.data.PgAcu; import com.szpg.plc.server.ACUClient; import com.szpg.plc.server.ACUClientUtil; import com.szpg.task.ACUSocketCheckTask; import com.szpg.task.ReadCH4StatusTask; import com.szpg.task.ReadCH4ValueTask; import com.szpg.task.ReadCOStatusTask; import com.szpg.task.ReadCOValueTask; import com.szpg.task.ReadDSStatusTask; import com.szpg.task.ReadFjRtTask; import com.szpg.task.ReadFjStatTask; import com.szpg.task.ReadHSStatusTask; import com.szpg.task.ReadHSValueTask; import com.szpg.task.ReadJgStatusTask; import com.szpg.task.ReadO2StatusTask; import com.szpg.task.ReadO2ValueTask; import com.szpg.task.ReadSbRtTask; import com.szpg.task.ReadSbStatTask; import com.szpg.task.ReadWSStatusTask; import com.szpg.task.ReadWSValueTask; import com.szpg.task.ReadYWStatusTask; import com.szpg.task.ReadZmRtTask; import com.szpg.task.ReadZmStatTask; import com.szpg.task.ResetDsTask; import com.szpg.task.SetCH4ThresholdTask; import com.szpg.task.SetCOThresholdTask; import com.szpg.task.SetHSThresholdTask; import com.szpg.task.SetJgUnlockTask; import com.szpg.task.SetO2ThresholdTask; import com.szpg.task.SetSdThresholdTask; import com.szpg.task.SetWdThresholdTask; import com.szpg.task.TurnOffFjTask; import com.szpg.task.TurnOffZmTask; import com.szpg.task.TurnOnFjTask; import com.szpg.task.TurnOnZmTask; public class DSCTest { private static DSCTest dsc = new DSCTest(); public static void main(String[] args) { // PLC设备地址和端口 ACUClient client = new ACUClient("192.168.0.244", 9600); PgAcu acu = new PgAcuDaoImpl().findACUById(1); client.setAcucode(acu.getAcu_code()); client.setNet(acu.getAcu_net()); //网络号 client.setNode(acu.getAcu_node()); //节点号 client.setUnit(acu.getAcu_unit()); //单元号 // 3将ACU的信息加入到map中 ACUClientUtil.getInstance().addClient(client); // 4新建线程启动client new ScheduledThreadPoolExecutor(1).scheduleAtFixedRate(new ACUSocketCheckTask(client), 0, 30, TimeUnit.SECONDS); // 甲烷 // dsc.testSendCH4Command(); // dsc.testSendCH4StatusCommand(); // 温湿度 // dsc.testSendWSCommand(); // dsc.testSendWSStatusCommand(); // 一氧化碳 // dsc.testSendCOCommand(); // dsc.testSendCOStatusCommand(); // 氧气 // dsc.testSendO2Command(); // dsc.testSendO2StatusCommand(); // 硫化氢 // dsc.testSendHSCommand(); // dsc.testSendHSStatusCommand(); // 爆管液位 // dsc.testSendYWStatusCommand(); // 对射报警 // dsc.testSendDSStatusCommand(); // 井盖 // dsc.testSendJgStatusCommand(); // 风机 dsc.testSendFjStatCommand(); // dsc.testSendFjRtCommand(); // 水泵 // dsc.testSendSbRtCommand(); // dsc.testSendSbStatCommand(); // 照明 // dsc.testSendZmRtCommand(); // dsc.testSendZmStatCommand(); // 照明开关 // dsc.testSendTurnOnZmCommand("YXL.ACU001.RZM01"); // dsc.testSendTurnOffZmCommand("YXL.ACU001.RZM01"); // 风机开关 // dsc.testSendTurnOnFjCommand("YXL.ACU001.RFJ01"); // dsc.testSendTurnOffFjCommand("YXL.ACU001.RFJ01"); // 井盖解锁 // dsc.testSendUnlockJgCommand("YXL.ACU001.RJG01"); // 对射报警清除 // dsc.testSendResetDsCommand("YXL.ACU001.DIR02"); // 甲烷报警阈值设定 // dsc.testSendCH4ThresholdCommand("YXL.ACU001.SCH01"); // 硫化氢报警阈值设定 // dsc.testSendHSThresholdCommand("YXL.ACU001.RHS01"); // 温湿度报警阈值设定 // dsc.testSendWSThresholdCommand("YXL.ACU001.SWS01"); // 氧气报警阈值设定 // dsc.testSendO2ThresholdCommand("YXL.ACU001.SYQ01"); // 一氧化碳阈值设定 // dsc.testSendCOThresholdCommand("YXL.ACU001.RCO01"); } /** * 发送查询甲烷监测值命令 * * @param client */ private void testSendCH4Command() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadCH4ValueTask(), 10, 300, TimeUnit.SECONDS); } /** * 发送查询甲烷报警状态命令 * @param client */ private void testSendCH4StatusCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadCH4StatusTask(), 15, 300, TimeUnit.SECONDS); } /** * 发送查询温湿度监测值命令 * * @param client */ private void testSendWSCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadWSValueTask(), 20, 300, TimeUnit.SECONDS); } /** * 发送查询温湿度报警状态命令 * @param client */ private void testSendWSStatusCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadWSStatusTask(), 25, 300, TimeUnit.SECONDS); } /** * 发送查询一氧化碳监测值命令 * * @param client */ private void testSendCOCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadCOValueTask(), 30, 300, TimeUnit.SECONDS); } /** * 发送查询一氧化碳报警状态命令 * @param client */ private void testSendCOStatusCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadCOStatusTask(), 35, 300, TimeUnit.SECONDS); } /** * 发送查询氧气监测值命令 * * @param client */ private void testSendO2Command() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadO2ValueTask(), 40, 300, TimeUnit.SECONDS); } /** * 发送查询一氧化碳报警状态命令 * @param client */ private void testSendO2StatusCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadO2StatusTask(), 45, 300, TimeUnit.SECONDS); } /** * 发送查询硫化氢监测值命令 * * @param client */ private void testSendHSCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadHSValueTask(), 50, 300, TimeUnit.SECONDS); } /** * 发送查询硫化氢报警状态命令 * @param client */ private void testSendHSStatusCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadHSStatusTask(), 55, 300, TimeUnit.SECONDS); } /** * 发送查询爆管液位报警状态命令 * @param client */ private void testSendYWStatusCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadYWStatusTask(), 10, 300, TimeUnit.SECONDS); } /** * 发送查询对射报警状态命令 * @param client */ private void testSendDSStatusCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadDSStatusTask(), 20, 300, TimeUnit.SECONDS); } /** * 发送查询井盖状态命令 * @param client */ private void testSendJgStatusCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadJgStatusTask(), 30, 300, TimeUnit.SECONDS); } /** * 发送查询风机运行状态命令 * @param client */ private void testSendFjStatCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadFjStatTask(), 15, 300, TimeUnit.SECONDS); } /** * 发送查询风机运行时长命令 * @param client */ private void testSendFjRtCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadFjRtTask(), 20, 300, TimeUnit.SECONDS); } /** * 发送查询水泵运行状态命令 * @param client */ private void testSendSbStatCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadSbStatTask(), 25, 300, TimeUnit.SECONDS); } /** * 发送查询水泵运行时长命令 * @param client */ private void testSendSbRtCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadSbRtTask(), 30, 300, TimeUnit.SECONDS); } /** * 发送查询照明运行状态命令 * @param client */ private void testSendZmStatCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadZmStatTask(), 35, 300, TimeUnit.SECONDS); } /** * 发送查询照明运行时长命令 * @param client */ private void testSendZmRtCommand() { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.scheduleWithFixedDelay(new ReadZmRtTask(), 40, 300, TimeUnit.SECONDS); } /** * 发送打开照明 */ private void testSendTurnOnZmCommand(String deviceCode) { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new TurnOnZmTask(deviceCode), 15, TimeUnit.SECONDS); sche.shutdown(); } /** * 发送关闭照明 */ private void testSendTurnOffZmCommand(String deviceCode) { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new TurnOffZmTask(deviceCode), 20, TimeUnit.SECONDS); sche.shutdown(); } /** * 发送打开风机 */ private void testSendTurnOnFjCommand(String deviceCode) { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new TurnOnFjTask(deviceCode), 25, TimeUnit.SECONDS); sche.shutdown(); } /** * 发送关闭风机 */ private void testSendTurnOffFjCommand(String deviceCode) { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new TurnOffFjTask(deviceCode), 30, TimeUnit.SECONDS); sche.shutdown(); } /** * 发送解锁井盖 */ private void testSendUnlockJgCommand(String deviceCode) { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new SetJgUnlockTask(deviceCode, 1), 15, TimeUnit.SECONDS); sche.shutdown(); } /** * 清除对射报警 */ private void testSendResetDsCommand(String deviceCode) { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new ResetDsTask(deviceCode), 15, TimeUnit.SECONDS); sche.shutdown(); } /** * 设置甲烷报警阈值 */ private void testSendCH4ThresholdCommand(String deviceCode) { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new SetCH4ThresholdTask(deviceCode, 40.0f), 15, TimeUnit.SECONDS); sche.shutdown(); } /** * 设置硫化氢报警阈值 */ private void testSendHSThresholdCommand(String deviceCode) { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new SetHSThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); sche.shutdown(); } /** * 设置硫化氢报警阈值 */ private void testSendWSThresholdCommand(String deviceCode) { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new SetWdThresholdTask(deviceCode, 35.0f), 15, TimeUnit.SECONDS); sche.shutdown(); ScheduledExecutorService sche2 = new ScheduledThreadPoolExecutor(1); sche2.schedule(new SetSdThresholdTask(deviceCode, 75.0f), 20, TimeUnit.SECONDS); sche2.shutdown(); } /** * 设置氧气报警阈值 */ private void testSendO2ThresholdCommand(String deviceCode) { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new SetO2ThresholdTask(deviceCode, 18.0f), 15, TimeUnit.SECONDS); sche.shutdown(); } /** * 设置一氧化碳报警阈值 */ private void testSendCOThresholdCommand(String deviceCode) { ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new SetCOThresholdTask(deviceCode, 55.0f), 20, TimeUnit.SECONDS); sche.shutdown(); } }