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.ReadCH4ParamTask; 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); // System.out.println(Float.intBitsToFloat(Integer.parseInt("3F4054F5",16))); } /** * 发送查询甲烷监测值命令 * * @param client */ public void testSendCH4Command(ACUClient client) { ReadMemoryCommand ch4 = ReadMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_READCH4PARAM); 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); //读取监测值时位数量无效 ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new ReadCH4ParamTask(client, ch4), 12, TimeUnit.SECONDS); sche.shutdown(); //执行完任务之后关闭线程 } /** * 发送查询甲烷报警状态命令 * @param client */ public void testSendCH4StatsuCommand(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"))); ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new ReadCH4StatusTask(client, ch4alm), 15, TimeUnit.SECONDS); sche.shutdown(); //执行完任务之后关闭线程 } }