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.command.read.ReadCH4ParamCommand; 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.util.Configure; public class DSCTest { private static DSCTest dsc = new DSCTest(); public static void main(String[] args) { ACUClient client = new ACUClient("192.168.8.107", 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); // System.out.println(Float.intBitsToFloat(Integer.parseInt("3F4054F5",16))); } private void testSendCH4Command(ACUClient client) { ReadCH4ParamCommand ch4 = new ReadCH4ParamCommand(); 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", "YXL.ACU001.DCH.START")))) + "00"); ch4.setCount(Integer.parseInt(Configure.getProperty("acubl", "YXL.ACU001.DCH.COUNT"))); ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1); sche.schedule(new ReadCH4ParamTask(client, ch4), 15, TimeUnit.SECONDS); sche.shutdown(); //执行完任务之后关闭线程 } }