package com.dev.fbs9600;
|
|
import com.battdata_rt.BattData_RT;
|
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 FBS9600_State {
|
static final int UsrCmdNull = 0;
|
static final int UsrCmdTestRes = 81;
|
static final int UsrCmdTestResSuc = 82;
|
static final int WorkStateNull = 0;
|
static final int WorkStateRes = 1;
|
public String ip_addr;
|
public int dev_id;
|
public int check_dev_id; //校验设备id
|
private int op_cmd;
|
private boolean op_cmd_ack_fromdev = false;
|
int work_state;
|
int com_count;
|
int com_err_count;
|
long alm_rec_id = 0L;
|
|
public FBS9600_State(String ipaddr, int id) {
|
this.ip_addr = ipaddr;
|
this.dev_id = id;
|
}
|
|
public void setWorkState() {
|
this.work_state = 1;
|
}
|
|
public void clearWorkState() {
|
this.work_state = 0;
|
}
|
|
public int getWorkState() {
|
return this.work_state;
|
}
|
|
public void setFBS9600CmdAckFromDev(boolean stat) {
|
this.op_cmd_ack_fromdev = stat;
|
}
|
|
public boolean getFBS9600CmdAckFromDev() {
|
return this.op_cmd_ack_fromdev;
|
}
|
|
public void setFBS9600Cmd(int cmd) {
|
this.op_cmd = cmd;
|
}
|
|
public int getFBS9600Cmd() {
|
return this.op_cmd;
|
}
|
|
public void setComCountInc() {
|
this.com_err_count = 0;
|
this.com_count += 1;
|
if (this.com_count >= 90000000)
|
this.com_count = 1;
|
}
|
|
public void setComErrCountInc() {
|
this.com_err_count += 1;
|
if (this.com_err_count >= 90000000)
|
this.com_err_count = 20;
|
}
|
|
/**
|
* 构造State读取集合
|
* @param master
|
* @return
|
*/
|
public BatchRead<Integer> createBatchRead(MyModbusMaster master) {
|
BatchRead<Integer> batch = new BatchRead<Integer>();
|
batch.addLocator(0,MyModbusUtils.createBaseLocator(0xF001,DataType.TWO_BYTE_INT_UNSIGNED, master)); //机箱跳闸输出
|
batch.addLocator(1,MyModbusUtils.createBaseLocator(0xF002, DataType.TWO_BYTE_INT_UNSIGNED, master)); //故障复位信号
|
|
return batch;
|
}
|
|
/**
|
* 解析State读取集合
|
* @param res
|
*/
|
public boolean putBatchResult(BatchResults<Integer> res) {
|
if(res != null) {
|
int dev_head = res.getIntValue(0);
|
int dev_food = res.getIntValue(1);
|
|
this.check_dev_id = dev_head*100000+dev_food;
|
//System.out.println(this.check_dev_id+"===="+dev_head+"==="+dev_food);
|
return true;
|
}
|
return false;
|
}
|
|
/**
|
* 读取电池组组端数据信息
|
* @param master
|
* @return
|
*/
|
public BatchRead<Integer> createGruopBatchRead(MyModbusMaster master,int index) {
|
int offset = index*0x1000;
|
BatchRead<Integer> batch = new BatchRead<Integer>();
|
batch.addLocator(0,MyModbusUtils.createBaseLocator(0x0003+offset,DataType.TWO_BYTE_INT_UNSIGNED, master)); //模块状态:0-正常采集 1-内阻测试 2-单体编号
|
batch.addLocator(1,MyModbusUtils.createBaseLocator(0x0004+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //组端电压
|
batch.addLocator(2,MyModbusUtils.createBaseLocator(0x0006+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //组端电流
|
batch.addLocator(3,MyModbusUtils.createBaseLocator(0x0007+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //蓄电池状态
|
batch.addLocator(4,MyModbusUtils.createBaseLocator(0x000A+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //纹波电流均值
|
batch.addLocator(5,MyModbusUtils.createBaseLocator(0x000B+offset, DataType.TWO_BYTE_INT_UNSIGNED, master)); //纹波电流峰值
|
return batch;
|
}
|
|
|
|
public boolean putGroupBatchResult(BatchResults<Integer> res,int index,BattData_RT battData_RT) {
|
if(res != null) {
|
battData_RT.mTestData.updateGroupVolFrom_FBSDev(((float)res.getIntValue(0))/10);
|
float battcurr = ((float)res.getIntValue(1))/10;
|
int battstate = res.getIntValue(2);
|
if (1 == battstate) {
|
battcurr *= -1.0F;
|
}
|
battData_RT.mTestData.updateCurrFrom_FBSDev(battcurr);
|
return true;
|
}
|
return false;
|
}
|
|
public BatchRead<Integer> createMonVolBatchRead(MyModbusMaster master, int index,int monCount) {
|
int offset = index*0x1000;
|
BatchRead<Integer> batch = new BatchRead<Integer>();
|
for(int i=0;i<monCount;i++) {
|
batch.addLocator(i,MyModbusUtils.createBaseLocator(0x001C+offset+i,DataType.TWO_BYTE_INT_UNSIGNED, master)); //单体电压
|
}
|
return batch;
|
}
|
|
public boolean putMonVolBatchResult(BatchResults<Integer> res, int index, BattData_RT battData_RT) {
|
if(res != null) {
|
for(int i=0;i<battData_RT.MonCount;i++) {
|
battData_RT.al_MonVol.get(i).monVol = ((float)res.getIntValue(i))/1000;
|
}
|
return true;
|
}
|
return false;
|
}
|
}
|