9度通讯程序适用于9度多组设备
Administrator
2023-12-27 c736aaea5522e295b42676f094d313e7f6a4afb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
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_param {
    public static int BYTE_LEN=17;         //¼Ä´æÆ÷¸öÊý
    private int cmd;                        //·¢ËÍÊý¾ÝµÄÃüÁî
    private int cmd_addr;                    //Ä£¿éµØÖ·
    private int cmd_addr_back;                //¼Ä´æÆ÷µÄÆðʼµØÖ·
    private int dataCount;                    //Êý¾ÝµÄ³¤¶È
    
    private int op_cmd;                        //ÓÃÓÚÉèÖÃÉ豸µÄ¿ØÖÆÃüÁî
    private int param_teststart_batt_num;   //²âÊÔÆðʼµç³ØÐòºÅ
    private int param_cap;                  //±ê³ÆÈÝÁ¿
    private double param_discharge_curr;    //·ÅµçµçÁ÷0.001
    private double param_mon_curr_high;     //µ¥ÌåÏÂÏÞ0.001
    private double param_charge_curr;       //³äµçµçÁ÷0.001
    private double param_mon_curr_low;      //µ¥ÌåÉÏÏÞ0.001
    private double param_online_vol;        //ÔÚÏßµçѹ·§Öµ0.01
    private double param_charge_curr_low;  //³äµçµçÁ÷ÏÂÏÞ·§Öµ0.001
    private double param_charge_cap_low;    //³äµçÈÝÁ¿ÏÂÏÞ·§Öµ%
    private double param_online_vol_recover;//ÔÚÏßµçѹ»Ö¸´·§Öµ0.01
    private int param_module_address;       //Ä£¿éµØÖ·
    
    private int param_junheng_model;        //¾ùºâ¹¦ÄܵįôÓûòÕß½ûÓà       0:½ûÓà         1:ÆôÓÃ
    private double param_cap_low;            //ÈÝÁ¿ÏÂÏÞ0.1
    private int param_datasource;            //Êý¾ÝÀ´Ô´£¨0 -  ±¾»ú           1-»ã¼¯Æ÷£©
    private int param_res_args;                //ÄÚ×è²âÊÔϵÊý£¨1-100£©
    private int param_tmp_high;                //ζÈÉÏÏÞ
    private double param_res_high;            //ÄÚ×èÉÏÏÞ
    
    
    //»ñÈ¡²ÎÊýÐÅÏ¢
    public boolean setLD_param(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.param_teststart_batt_num = ComBase.changeShortToInt(tmpbuf.getShort());        
                this.param_cap = ComBase.changeShortToInt(tmpbuf.getShort());        
                this.param_discharge_curr = ComBase.changeShortToInt(tmpbuf.getShort())*0.001;            
                this.param_mon_curr_low = ComBase.changeShortToInt(tmpbuf.getShort())*0.001;            
                this.param_charge_curr = ComBase.changeShortToInt(tmpbuf.getShort())*0.001;            
                this.param_mon_curr_high= ComBase.changeShortToInt(tmpbuf.getShort())*0.001;        
                this.param_online_vol = ComBase.changeShortToInt(tmpbuf.getShort())*0.01;            
                this.param_charge_curr_low = ComBase.changeShortToInt(tmpbuf.getShort())*0.001;        
                
                this.param_charge_cap_low = ComBase.changeShortToInt(tmpbuf.getShort());             
                this.param_online_vol_recover = ComBase.changeShortToInt(tmpbuf.getShort())*0.01;            
                this.param_module_address = ComBase.changeShortToInt(tmpbuf.getShort());
                this.param_junheng_model = ComBase.changeShortToInt(tmpbuf.getShort());
                this.param_cap_low = (float) (ComBase.changeShortToInt(tmpbuf.getShort())*0.1);
                this.param_datasource = ComBase.changeShortToInt(tmpbuf.getShort());    
                this.param_res_args = ComBase.changeShortToInt(tmpbuf.getShort());
                this.param_tmp_high = ComBase.changeShortToInt(tmpbuf.getShort());
                this.param_res_high = (float)(ComBase.changeShortToInt(tmpbuf.getShort())*0.1);
                
                //System.err.println(this.param_cap_low+"#################");
                flag = true;
            } catch (Exception e) {
                  e.printStackTrace();
              }                
              return flag;
        }
 
    public int getParam_teststart_batt_num() {
        return param_teststart_batt_num;
    }
 
    public void setParam_teststart_batt_num(int param_teststart_batt_num) {
        this.param_teststart_batt_num = param_teststart_batt_num;
    }
 
    public int getParam_cap() {
        return param_cap;
    }
 
    public void setParam_cap(int param_cap) {
        this.param_cap = param_cap;
    }
 
    public double getParam_discharge_curr() {
        return param_discharge_curr;
    }
 
    public void setParam_discharge_curr(double param_discharge_curr) {
        this.param_discharge_curr = param_discharge_curr;
    }
 
    public double getParam_mon_curr_high() {
        return param_mon_curr_high;
    }
 
    public void setParam_mon_curr_high(double param_mon_curr_high) {
        this.param_mon_curr_high = param_mon_curr_high;
    }
 
    public double getParam_charge_curr() {
        return param_charge_curr;
    }
 
    public void setParam_charge_curr(double param_charge_curr) {
        this.param_charge_curr = param_charge_curr;
    }
 
    public double getParam_mon_curr_low() {
        return param_mon_curr_low;
    }
 
    public void setParam_mon_curr_low(double param_mon_curr_low) {
        this.param_mon_curr_low = param_mon_curr_low;
    }
 
    public double getParam_online_vol() {
        return param_online_vol;
    }
 
    public void setParam_online_vol(double param_online_vol) {
        this.param_online_vol = param_online_vol;
    }
 
 
    public double getParam_cap_low() {
        return param_cap_low;
    }
 
    public void setParam_cap_low(double param_cap_low) {
        this.param_cap_low = param_cap_low;
    }
 
    public double getParam_charge_curr_low() {
        return param_charge_curr_low;
    }
 
    public void setParam_charge_curr_low(double param_charge_curr_low) {
        this.param_charge_curr_low = param_charge_curr_low;
    }
 
    public double getParam_charge_cap_low() {
        return param_charge_cap_low;
    }
 
    public void setParam_charge_cap_low(double param_charge_cap_low) {
        this.param_charge_cap_low = param_charge_cap_low;
    }
 
    public double getParam_online_vol_recover() {
        return param_online_vol_recover;
    }
 
    public void setParam_online_vol_recover(double param_online_vol_recover) {
        this.param_online_vol_recover = param_online_vol_recover;
    }
 
    public int getParam_module_address() {
        return param_module_address;
    }
 
    public void setParam_module_address(int param_module_address) {
        this.param_module_address = param_module_address;
    }
 
    public int getOp_cmd() {
        return op_cmd;
    }
 
    public void setOp_cmd(int op_cmd) {
        this.op_cmd = op_cmd;
    }
 
    public int getParam_junheng_model() {
        return param_junheng_model;
    }
 
    public void setParam_junheng_model(int param_junheng_model) {
        this.param_junheng_model = param_junheng_model;
    }
 
    public int getParam_datasource() {
        return param_datasource;
    }
 
    public void setParam_datasource(int param_datasource) {
        this.param_datasource = param_datasource;
    }
 
    public int getParam_res_args() {
        return param_res_args;
    }
 
    public void setParam_res_args(int param_res_args) {
        this.param_res_args = param_res_args;
    }
 
    
 
    public int getParam_tmp_high() {
        return param_tmp_high;
    }
 
    public void setParam_tmp_high(int param_tmp_high) {
        this.param_tmp_high = param_tmp_high;
    }
 
    public double getParam_res_high() {
        return param_res_high;
    }
 
    public void setParam_res_high(double param_res_high) {
        this.param_res_high = param_res_high;
    }
 
    @Override
    public String toString() {
        return "LD_param [cmd=" + cmd + ", cmd_addr=" + cmd_addr + ", cmd_addr_back=" + cmd_addr_back + ", dataCount="
                + dataCount + ", op_cmd=" + op_cmd + ", param_teststart_batt_num=" + param_teststart_batt_num
                + ", param_cap=" + param_cap + ", param_discharge_curr=" + param_discharge_curr
                + ", param_mon_curr_high=" + param_mon_curr_high + ", param_charge_curr=" + param_charge_curr
                + ", param_mon_curr_low=" + param_mon_curr_low + ", param_online_vol=" + param_online_vol
                + ", param_charge_curr_low=" + param_charge_curr_low + ", param_charge_cap_low=" + param_charge_cap_low
                + ", param_online_vol_recover=" + param_online_vol_recover + ", param_module_address="
                + param_module_address + ", param_junheng_model=" + param_junheng_model + ", param_cap_low="
                + param_cap_low + ", param_datasource=" + param_datasource + ", param_res_args=" + param_res_args
                + ", param_tmp_high=" + param_tmp_high + ", param_res_high=" + param_res_high + "]";
    }
 
    public BatchRead<Integer> createLDDisChargeParam(MyModbusMaster master) {
        int offset = MyModBusCom.LD_PARM_ADDR;
        int count = 0;
        BatchRead<Integer> batch = new BatchRead<Integer>();
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //²âÊÔÆðʼµç³ØÐòºÅ                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //±ê³ÆÈÝÁ¿                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //·ÅµçµçÁ÷                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //µ¥ÌåÏÂÏÞ                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //³äµçµçÁ÷                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //µ¥ÌåÉÏÏÞ                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //ÔÚÏßµçѹ·§Öµ                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //³äµçµçÁ÷ÏÂÏÞ·§Öµ                    
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //³äµçÈÝÁ¿ÏÂÏÞÂÊ                
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //ÔÚÏßµçѹ»Ö¸´·§Öµ                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //Ä£¿éµØÖ·                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //¾ùºâ¹¦ÄÜÆôÍ£                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //ÈÝÁ¿ÏÂÏÞ                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //Êý¾ÝÀ´Ô´                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //ÄÚ×è²âÊÔϵÊý                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //ζÈÉÏÏÞ                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //ÄÚ×èÉÏÏÞ                            
            
        return batch;
    }
 
    public boolean putLDDisChargeParamBatchResult(BatchResults<Integer> res) {
        if(null != res) {
            int index = 0;
            
            this.param_teststart_batt_num = res.getIntValue(index++);        
            this.param_cap = res.getIntValue(index++);        
            this.param_discharge_curr = (double)res.getIntValue(index++)*0.001;            
            this.param_mon_curr_low = (double)res.getIntValue(index++)*0.001;            
            this.param_charge_curr = (double)res.getIntValue(index++)*0.001;            
            this.param_mon_curr_high= (double)res.getIntValue(index++)*0.001;        
            this.param_online_vol = (double)res.getIntValue(index++)*0.01;            
            this.param_charge_curr_low = (double)res.getIntValue(index++)*0.001;        
            
            this.param_charge_cap_low = res.getIntValue(index++);             
            this.param_online_vol_recover = (double)res.getIntValue(index++)*0.01;            
            this.param_module_address = res.getIntValue(index++);
            this.param_junheng_model = res.getIntValue(index++);
            this.param_cap_low = (double)res.getIntValue(index++)*0.1;
            this.param_datasource = res.getIntValue(index++);    
            this.param_res_args = res.getIntValue(index++);
            this.param_tmp_high = res.getIntValue(index++);
            this.param_res_high = (double)res.getIntValue(index++)*0.1;
        }
        return false;
    }
 
    public boolean setUpDisChargeParam(MyModbusMaster master) {    
        int offset = MyModBusCom.LD_PARM_ADDR;
        int index = offset;
        
        boolean flag = MyModbusUtils.writeHoldingRegister(index++, this.param_teststart_batt_num, DataType.TWO_BYTE_INT_UNSIGNED, master);        //²âÊÔÆðʼµç³ØÐòºÅ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_cap, DataType.TWO_BYTE_INT_UNSIGNED, master);                    //±ê³ÆÈÝÁ¿
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_discharge_curr*1000, DataType.TWO_BYTE_INT_UNSIGNED, master);    //·ÅµçµçÁ÷
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_mon_curr_low*1000, DataType.TWO_BYTE_INT_UNSIGNED, master);        //µ¥ÌåÏÂÏÞ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_charge_curr*1000, DataType.TWO_BYTE_INT_UNSIGNED, master);        //³äµçµçÁ÷
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_mon_curr_high*1000, DataType.TWO_BYTE_INT_UNSIGNED, master);        //µ¥ÌåÉÏÏÞ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_online_vol*100, DataType.TWO_BYTE_INT_UNSIGNED, master);            //ÔÚÏßµçѹ·§Öµ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_charge_curr_low*1000, DataType.TWO_BYTE_INT_UNSIGNED, master);    //³äµçµçÁ÷ÏÂÏÞ·§Öµ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_charge_cap_low, DataType.TWO_BYTE_INT_UNSIGNED, master);            //³äµçÈÝÁ¿ÏÂÏÞÂÊ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_online_vol_recover*100, DataType.TWO_BYTE_INT_UNSIGNED, master);    //ÔÚÏßµçѹ»Ö¸´·§Öµ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_module_address, DataType.TWO_BYTE_INT_UNSIGNED, master);            //Ä£¿éµØÖ·
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_junheng_model, DataType.TWO_BYTE_INT_UNSIGNED, master);            //¾ùºâ¹¦ÄÜÆôÍ£
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_cap_low*10, DataType.TWO_BYTE_INT_UNSIGNED, master);                //ÈÝÁ¿ÏÂÏÞ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_datasource, DataType.TWO_BYTE_INT_UNSIGNED, master);                //Êý¾ÝÀ´Ô´
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_res_args, DataType.TWO_BYTE_INT_UNSIGNED, master);                //ÄÚ×è²âÊÔϵÊý
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_tmp_high, DataType.TWO_BYTE_INT_UNSIGNED, master);                //ζÈÉÏÏÞ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.param_res_high*10, DataType.TWO_BYTE_INT_UNSIGNED, master);                //ÄÚ×èÉÏÏÞ
        
        return flag;
    }
 
    /**
     * 
     * @param master
     * @param regAddr
     * @param controlvalue
     * @return
     */
    public boolean controlLDcontrol(MyModbusMaster master, int regAddr, int controlvalue) {
        return MyModbusUtils.writeHoldingRegister(regAddr, controlvalue, DataType.TWO_BYTE_INT_UNSIGNED, master);
    }
 
    
}