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.message.AppMessageConstants; import com.szpg.plc.message.command.ReadMemoryCommand; import com.szpg.plc.protocol.fins.FINSConstants; import com.szpg.plc.server.ACUClient; import com.szpg.plc.server.ACUClientUtil; import com.szpg.plc.util.ByteUtil; import com.szpg.task.ACUSocketCheckTask; import com.szpg.task.ReadCH4ValueTask; import com.szpg.task.ReadWSStatusTask; import com.szpg.task.ReadWSValueTask; import com.szpg.task.ReadCH4StatusTask; import com.szpg.util.Configure; public class DSCTest { private static DSCTest dsc = new DSCTest(); public static void main(String[] args) { ACUClient client = new ACUClient("192.168.8.105", 6800); client.setNet("00"); client.setNode("6B"); client.setUnit("00"); // 3将ACU的信息加入到map中 ACUClientUtil.getInstance().addClient(client); // 4新建线程启动client new ScheduledThreadPoolExecutor(1).scheduleAtFixedRate(new ACUSocketCheckTask(client), 0, 30, TimeUnit.SECONDS); // 测试发送查询甲烷参数命令 // dsc.testSendCH4Command(client); // 测试发送查询甲烷报警状态命令 // dsc.testSendCH4StatsuCommand(client); // 测试发送查询温湿度监测值命令 // dsc.testSendWSCommand(client); // 测试发送查询温湿度报警状态命令 dsc.testSendWSStatusCommand(client); } /** * 发送查询甲烷监测值命令 * * @param client */ public void testSendCH4Command(ACUClient client) { ReadMemoryCommand ch4 = ReadMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_READCH4VALUE); String sour = Configure.getProperty("sys", "LOCALHOST.NET") + Configure.getProperty("sys", "LOCALHOST.NODE") + Configure.getProperty("sys", "LOCALHOST.UNIT"); ch4.setMessageProducerId(sour); PgAcu acu = new PgAcuDaoImpl().findACUById(1); String dest = acu.getAcu_net() + acu.getAcu_node() + acu.getAcu_unit(); ch4.setDestinationId(dest); ch4.setMemoryArea(FINSConstants.MEMORY_DM_AREA); ch4.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(Integer.parseInt(Configure.getProperty("acubl", acu.getAcu_code() + ".CH.START")), 2)) + "00"); ch4.setCountWord(Integer.parseInt(Configure.getProperty("acubl", acu.getAcu_code() + ".CH.WORDCOUNT"))); ch4.setCountBit(0); //读取监测值时位数量无效 ch4.setCountSensor(Integer.parseInt(Configure.getProperty("acubl", acu.getAcu_code() + ".CH.COUNT"))); ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new ReadCH4ValueTask(client, ch4), 12, TimeUnit.SECONDS); sche.shutdown(); //执行完任务之后关闭线程 } /** * 发送查询甲烷报警状态命令 * @param client */ public void testSendCH4StatusCommand(ACUClient client) { ReadMemoryCommand ch4alm = ReadMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_READCH4STATUS); String sour = Configure.getProperty("sys", "LOCALHOST.NET") + Configure.getProperty("sys", "LOCALHOST.NODE") + Configure.getProperty("sys", "LOCALHOST.UNIT"); ch4alm.setMessageProducerId(sour); PgAcu acu = new PgAcuDaoImpl().findACUById(1); String dest = acu.getAcu_net() + acu.getAcu_node() + acu.getAcu_unit(); ch4alm.setDestinationId(dest); ch4alm.setMemoryArea(FINSConstants.MEMORY_WORK_AREA); ch4alm.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(Integer.parseInt(Configure.getProperty("acubl", acu.getAcu_code() + ".CHALM.START")), 2)) + "00"); ch4alm.setCountWord(Integer.parseInt(Configure.getProperty("acubl", acu.getAcu_code() + ".CHALM.WORDCOUNT"))); ch4alm.setCountBit(Integer.parseInt(Configure.getProperty("acubl", acu.getAcu_code() + ".CHALM.BITCOUNT"))); ch4alm.setCountSensor(Integer.parseInt(Configure.getProperty("acubl", acu.getAcu_code() + ".CH.COUNT"))); ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new ReadCH4StatusTask(client, ch4alm), 15, TimeUnit.SECONDS); sche.shutdown(); //执行完任务之后关闭线程 } /** * 发送查询温湿度监测值命令 * * @param client */ public void testSendWSCommand(ACUClient client) { ReadMemoryCommand ws = ReadMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_READWSVALUE); String sour = Configure.getProperty("sys", "LOCALHOST.NET") + Configure.getProperty("sys", "LOCALHOST.NODE") + Configure.getProperty("sys", "LOCALHOST.UNIT"); ws.setMessageProducerId(sour); PgAcu acu = new PgAcuDaoImpl().findACUById(1); String dest = acu.getAcu_net() + acu.getAcu_node() + acu.getAcu_unit(); ws.setDestinationId(dest); ws.setMemoryArea(FINSConstants.MEMORY_DM_AREA); ws.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(Integer.parseInt(Configure.getProperty("acubl", acu.getAcu_code() + ".WD.START")), 2)) + "00"); ws.setCountWord(Integer.parseInt(Configure.getProperty("acubl", acu.getAcu_code() + ".WS.WORDCOUNT"))); ws.setCountBit(0); //读取监测值时位数量无效 ws.setCountSensor(Integer.parseInt(Configure.getProperty("acubl", acu.getAcu_code() + ".WS.COUNT"))); ws.setOffset(Integer.parseInt(Configure.getProperty("acubl", acu.getAcu_code() + ".SD.OFFSET"))); ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new ReadWSValueTask(client, ws), 12, TimeUnit.SECONDS); sche.shutdown(); //执行完任务之后关闭线程 } /** * 发送查询温湿度报警状态命令 * @param client */ public void testSendWSStatusCommand(ACUClient client) { ReadMemoryCommand wsalm = ReadMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_READWSSTATUS); String sour = Configure.getProperty("sys", "LOCALHOST.NET") + Configure.getProperty("sys", "LOCALHOST.NODE") + Configure.getProperty("sys", "LOCALHOST.UNIT"); wsalm.setMessageProducerId(sour); PgAcu acu = new PgAcuDaoImpl().findACUById(1); String dest = acu.getAcu_net() + acu.getAcu_node() + acu.getAcu_unit(); wsalm.setDestinationId(dest); wsalm.setMemoryArea(FINSConstants.MEMORY_WORK_AREA); wsalm.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(Integer.parseInt(Configure.getProperty("acubl", acu.getAcu_code() + ".WSALM.START")), 2)) + "00"); wsalm.setCountWord(Integer.parseInt(Configure.getProperty("acubl", acu.getAcu_code() + ".WSALM.WORDCOUNT"))); wsalm.setCountBit(Integer.parseInt(Configure.getProperty("acubl", acu.getAcu_code() + ".WSALM.BITCOUNT"))); wsalm.setCountSensor(Integer.parseInt(Configure.getProperty("acubl", acu.getAcu_code() + ".WS.COUNT"))); ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new ReadWSStatusTask(client, wsalm), 15, TimeUnit.SECONDS); sche.shutdown(); //执行完任务之后关闭线程 } }