package com.dev.fbs9009;
|
|
import java.nio.ByteBuffer;
|
|
import com.base.ComBase;
|
import com.dev.modbus4j.MyModbusMaster;
|
import com.dev.modbus4j.MyModbusUtils;
|
import com.serotonin.modbus4j.BatchRead;
|
import com.serotonin.modbus4j.BatchResults;
|
import com.serotonin.modbus4j.code.DataType;
|
|
public class LD_sys_version {
|
public static int BYTE_LEN=4; //¼Ä´æÆ÷¸öÊý
|
private int cmd; //·¢ËÍÊý¾ÝµÄÃüÁî
|
private int cmd_addr; //É豸µØÖ·
|
private int cmd_addr_back; //¼Ä´æÆ÷µÄÆðʼµØÖ·
|
|
private int dataCount; //Êý¾ÝµÄ³¤¶È
|
private int sys_type; //É豸ÀàÐÍ
|
private int sys_dev_id; //É豸id
|
private int sys_software_version; //É豸Èí¼þ°æ±¾
|
private int sys_hardware_version; //É豸Ӳ¼þ°æ±¾
|
|
//»ñȡϵͳʱ¼ä
|
public boolean setLD_sys_tem_version(ByteBuffer bf){
|
boolean flag = false;
|
ByteBuffer tmpbuf = bf;
|
tmpbuf.position(0);
|
try {
|
this.cmd_addr = ComBase.changeByteToInt(tmpbuf.get());
|
this.cmd = ComBase.changeByteToInt(tmpbuf.get()); //ÃüÁîµØÖ·
|
this.cmd_addr_back = ComBase.changeShortToInt(tmpbuf.getShort()); //»ñÈ¡¼Ä´æÆ÷µÄÆðʼµØÖ·
|
this.dataCount = ComBase.changeByteToInt(tmpbuf.get());
|
//System.out.println("Êý¾ÝÇø×Ö½ÚÊýµÄ³¤¶È:"+this.dataCount);
|
this.sys_type=ComBase.changeShortToInt(tmpbuf.getShort());
|
this.sys_dev_id=ComBase.changeShortToInt(tmpbuf.getShort());
|
this.sys_dev_id = this.sys_dev_id + 4019*100000;
|
this.sys_software_version=ComBase.changeShortToInt(tmpbuf.getShort());
|
this.sys_hardware_version=ComBase.changeShortToInt(tmpbuf.getShort());
|
|
flag = true;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return flag;
|
}
|
|
/**
|
* »ñÈ¡É豸µÄ°æ±¾ºÅ
|
* @return
|
*/
|
public String getDev_version(){
|
String version = "";
|
if(sys_hardware_version>=0 && sys_hardware_version >= 0){
|
version = "V"+sys_software_version+"."+sys_hardware_version;
|
}
|
return version;
|
}
|
|
public int getCmd() {
|
return cmd;
|
}
|
|
public void setCmd(int cmd) {
|
this.cmd = cmd;
|
}
|
|
public int getCmd_addr() {
|
return cmd_addr;
|
}
|
|
public void setCmd_addr(int cmd_addr) {
|
this.cmd_addr = cmd_addr;
|
}
|
|
public int getDataCount() {
|
return dataCount;
|
}
|
|
public void setDataCount(int dataCount) {
|
this.dataCount = dataCount;
|
}
|
|
public int getSys_type() {
|
return sys_type;
|
}
|
|
public void setSys_type(int sys_type) {
|
this.sys_type = sys_type;
|
}
|
|
public int getSys_dev_id() {
|
return sys_dev_id;
|
}
|
|
public void setSys_dev_id(int sys_dev_id) {
|
this.sys_dev_id = sys_dev_id;
|
}
|
|
public int getSys_software_version() {
|
return sys_software_version;
|
}
|
|
public void setSys_software_version(int sys_software_version) {
|
this.sys_software_version = sys_software_version;
|
}
|
|
public int getSys_hardware_version() {
|
return sys_hardware_version;
|
}
|
|
public void setSys_hardware_version(int sys_hardware_version) {
|
this.sys_hardware_version = sys_hardware_version;
|
}
|
|
public int getCmd_addr_back() {
|
return cmd_addr_back;
|
}
|
|
public void setCmd_addr_back(int cmd_addr_back) {
|
this.cmd_addr_back = cmd_addr_back;
|
}
|
|
public BatchRead<Integer> createLDVersionBatchRead(MyModbusMaster master) {
|
int offset = MyModBusCom.LD_CMD_SYS_VERSION_ADDR;
|
BatchRead<Integer> batch = new BatchRead<Integer>();
|
batch.addLocator(0,MyModbusUtils.createBaseLocator(offset,DataType.TWO_BYTE_INT_UNSIGNED, master)); //É豸ÀàÐÍ
|
batch.addLocator(1,MyModbusUtils.createBaseLocator(offset+1, DataType.TWO_BYTE_INT_UNSIGNED, master)); //É豸µØÖ·
|
batch.addLocator(2,MyModbusUtils.createBaseLocator(offset+2, DataType.TWO_BYTE_INT_UNSIGNED, master)); //Èí¼þ°æ±¾
|
batch.addLocator(3,MyModbusUtils.createBaseLocator(offset+3, DataType.TWO_BYTE_INT_UNSIGNED, master)); //Ó²¼þ°æ±¾
|
return batch;
|
}
|
|
public boolean putLDVersionBatchResult(BatchResults<Integer> res) {
|
if(null != res) {
|
this.sys_type = res.getIntValue(0);
|
this.sys_dev_id = res.getIntValue(1);
|
this.sys_dev_id = this.sys_dev_id + 4019*100000;
|
this.sys_software_version = res.getIntValue(2);
|
this.sys_hardware_version = res.getIntValue(3);
|
return true;
|
}
|
return false;
|
}
|
|
|
}
|