Newer
Older
pgdsc / src / com / szpg / task / ReadWSStatusTask.java
ty-pc\admin on 19 Jun 2018 1 KB 20180619 修改提交
package com.szpg.task;

import java.util.Map;

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.service.ReadSensorStatusService;
import com.szpg.util.Configure;

public class ReadWSStatusTask implements Runnable {

	private ReadSensorStatusService service;

	public ReadWSStatusTask() {
		service = new ReadSensorStatusService();
	}
	
	@Override
	public void run() {
		// 查找所有的client
		Map<String, ACUClient> clients = ACUClientUtil.getInstance().getClients();
		
		for (String key : clients.keySet()) {
			ACUClient client = clients.get(key);
			
			ReadMemoryCommand command = ReadMemoryCommand.getInstance(AppMessageConstants.CMD_TYPE_READWSSTATUS);
			String sour = Configure.getProperty("sys", "LOCALHOST.NET") + 
						  Configure.getProperty("sys", "LOCALHOST.NODE") + 
						  Configure.getProperty("sys", "LOCALHOST.UNIT");
			command.setMessageProducerId(sour);
			
			String dest = client.getNet() + client.getNode() + client.getUnit();
			command.setDestinationId(dest);
			
			command.setMemoryArea(FINSConstants.MEMORY_WORK_AREA_WORD);
			
			try {
				command.setStartAddress(ByteUtil.binToHexString(ByteUtil.intToBins(Integer.parseInt(Configure.getProperty("acubl", client.getAcucode() + ".WSALM.START")), 2)) + "00");
				command.setCountWord(Integer.parseInt(Configure.getProperty("acubl", client.getAcucode() + ".WSALM.WORDCOUNT")));
			
				service.executeService(client, (ReadMemoryCommand) command);
			} catch (Exception ex) {
				continue;
			}
		}
	}
}