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
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;
 
/**
 * »ã¼¯Æ÷²ÎÊý
 * @author LiJun
 *
 */
public class ConcentratorParam {
    
    public static final int BYTE_LEN = 17;
 
    private int op_cmd;
    
    private int addr;                    //»ã¼¯Æ÷µØÖ·£¨£©
    private int firthMonCount;            //µÚһ·µ¥Ìå¸öÊý
    private int secondMonCount;            //µÚ¶þ·µ¥Ìå¸öÊý
    private int thirdMonCount;            //µÚÈý·µ¥Ìå¸öÊý
    private int fourthMonCount;            //µÚËÄ·µ¥Ìå¸öÊý
    private int fifthMonCount;            //µÚÎå·µ¥Ìå¸öÊý
    
    private int currRange;                //µçÁ÷ǯÁ¿³Ì
    private double floatCurrLimit;        //¸¡³äµçÁ÷ÃÅÏÞ(0.1)
    private double rippleCurrLimit;        //ÎÆ²¨µçÁ÷·§Öµ(0.01)
    private int autoTestCycle;            //×Ô¶¯²âÊÔÖÜÆÚ(Сʱ)
    private int resTestType;            //ÄÚ×è²âÊÔ·½·¨(0-·Åµç         1-¼²¨·¨        2×Ô¶¯)
    private int dischargeType;            //·Åµçģʽ(0-µ¥½Ú·Åµç        1-¹ã²¥·Åµç)
    private int battCapStd;                //±ê³ÆÈÝÁ¿(0-9999)
    
    private int backup1;                //±¸ÓÃ
    private int backup2;                //±¸ÓÃ
    private int backup3;                //±¸ÓÃ
    private int backup4;                //±¸ÓÃ
    
    public BaseData baseData = new BaseData();
    
    public boolean setConcenParam(ByteBuffer bf) {
        ByteBuffer tmpbuf = bf;    
          tmpbuf.position(0);    
          if(!this.baseData.putByteBuffer(bf)){
              return false;
          }
          this.addr = ComBase.changeShortToInt(tmpbuf.getShort());
          this.firthMonCount = ComBase.changeShortToInt(tmpbuf.getShort());
          this.secondMonCount = ComBase.changeShortToInt(tmpbuf.getShort());
          this.thirdMonCount = ComBase.changeShortToInt(tmpbuf.getShort());
          this.fourthMonCount = ComBase.changeShortToInt(tmpbuf.getShort());
          this.fifthMonCount = ComBase.changeShortToInt(tmpbuf.getShort());
          this.currRange = ComBase.changeShortToInt(tmpbuf.getShort());
          this.floatCurrLimit = ComBase.changeShortToDouble(tmpbuf.getShort())/10;
          this.rippleCurrLimit = ComBase.changeShortToDouble(tmpbuf.getShort())/100;
          this.autoTestCycle = ComBase.changeShortToInt(tmpbuf.getShort());
          this.resTestType = ComBase.changeShortToInt(tmpbuf.getShort());
          this.dischargeType = ComBase.changeShortToInt(tmpbuf.getShort());
          this.battCapStd = ComBase.changeShortToInt(tmpbuf.getShort());
          this.backup1 = ComBase.changeShortToInt(tmpbuf.getShort());
          this.backup2 = ComBase.changeShortToInt(tmpbuf.getShort());
          this.backup3 = ComBase.changeShortToInt(tmpbuf.getShort());
          this.backup4 = ComBase.changeShortToInt(tmpbuf.getShort());
        return true;
    }
    
    public void putByteBuffer(ByteBuffer bytebuffer) {
        bytebuffer.putShort(ComBase.changeIntToShort(this.addr));
        bytebuffer.putShort(ComBase.changeIntToShort(this.firthMonCount));
        bytebuffer.putShort(ComBase.changeIntToShort(this.secondMonCount));
        bytebuffer.putShort(ComBase.changeIntToShort(this.thirdMonCount));
        bytebuffer.putShort(ComBase.changeIntToShort(this.fourthMonCount));
        bytebuffer.putShort(ComBase.changeIntToShort(this.fifthMonCount));
        bytebuffer.putShort(ComBase.changeIntToShort(this.currRange));
        bytebuffer.putShort(ComBase.changeDoubleToShort(this.floatCurrLimit*10));
        bytebuffer.putShort(ComBase.changeDoubleToShort(this.rippleCurrLimit*100));
        bytebuffer.putShort(ComBase.changeIntToShort(this.autoTestCycle));
        bytebuffer.putShort(ComBase.changeIntToShort(this.resTestType));
        bytebuffer.putShort(ComBase.changeIntToShort(this.dischargeType));
        bytebuffer.putShort(ComBase.changeIntToShort(this.battCapStd));
        bytebuffer.putShort(ComBase.changeIntToShort(this.backup1));
        bytebuffer.putShort(ComBase.changeIntToShort(this.backup2));
        bytebuffer.putShort(ComBase.changeIntToShort(this.backup3));
        bytebuffer.putShort(ComBase.changeIntToShort(this.backup4));
        
    }
    
    public int getAddr() {
        return addr;
    }
    public int getFirthMonCount() {
        return firthMonCount;
    }
    public int getSecondMonCount() {
        return secondMonCount;
    }
    public int getThirdMonCount() {
        return thirdMonCount;
    }
    public int getFourthMonCount() {
        return fourthMonCount;
    }
    public int getFifthMonCount() {
        return fifthMonCount;
    }
    public int getCurrRange() {
        return currRange;
    }
    public double getFloatCurrLimit() {
        return floatCurrLimit;
    }
    public double getRippleCurrLimit() {
        return rippleCurrLimit;
    }
    public int getAutoTestCycle() {
        return autoTestCycle;
    }
    public int getResTestType() {
        return resTestType;
    }
    public int getDischargeType() {
        return dischargeType;
    }
    public int getBattCapStd() {
        return battCapStd;
    }
    public int getBackup1() {
        return backup1;
    }
    public int getBackup2() {
        return backup2;
    }
    public int getBackup3() {
        return backup3;
    }
    public int getBackup4() {
        return backup4;
    }
    public void setAddr(int addr) {
        this.addr = addr;
    }
    public void setFirthMonCount(int firthMonCount) {
        this.firthMonCount = firthMonCount;
    }
    public void setSecondMonCount(int secondMonCount) {
        this.secondMonCount = secondMonCount;
    }
    public void setThirdMonCount(int thirdMonCount) {
        this.thirdMonCount = thirdMonCount;
    }
    public void setFourthMonCount(int fourthMonCount) {
        this.fourthMonCount = fourthMonCount;
    }
    public void setFifthMonCount(int fifthMonCount) {
        this.fifthMonCount = fifthMonCount;
    }
    public void setCurrRange(int currRange) {
        this.currRange = currRange;
    }
    public void setFloatCurrLimit(double floatCurrLimit) {
        this.floatCurrLimit = floatCurrLimit;
    }
    public void setRippleCurrLimit(double rippleCurrLimit) {
        this.rippleCurrLimit = rippleCurrLimit;
    }
    public void setAutoTestCycle(int autoTestCycle) {
        this.autoTestCycle = autoTestCycle;
    }
    public void setResTestType(int resTestType) {
        this.resTestType = resTestType;
    }
    public void setDischargeType(int dischargeType) {
        this.dischargeType = dischargeType;
    }
    public void setBattCapStd(int battCapStd) {
        this.battCapStd = battCapStd;
    }
    public void setBackup1(int backup1) {
        this.backup1 = backup1;
    }
    public void setBackup2(int backup2) {
        this.backup2 = backup2;
    }
    public void setBackup3(int backup3) {
        this.backup3 = backup3;
    }
    public void setBackup4(int backup4) {
        this.backup4 = backup4;
    }
    public int getOp_cmd() {
        return op_cmd;
    }
    public void setOp_cmd(int op_cmd) {
        this.op_cmd = op_cmd;
    }
 
    public BatchRead<Integer> createConcenParamBatchRead(MyModbusMaster master) {
        int offset = MyModBusCom.LD_BATT_COLLECTIO_PARAM_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 putConcenParamBatchResult(BatchResults<Integer> res) {
        if(null != res) {
            int index = 0;
            this.addr = res.getIntValue(index++);
              this.firthMonCount = res.getIntValue(index++);
              this.secondMonCount = res.getIntValue(index++);
              this.thirdMonCount = res.getIntValue(index++);
              this.fourthMonCount = res.getIntValue(index++);
              this.fifthMonCount = res.getIntValue(index++);
              this.currRange = res.getIntValue(index++);
              this.floatCurrLimit = (double)res.getIntValue(index++)/10;
              this.rippleCurrLimit = (double)res.getIntValue(index++)/100;
              this.autoTestCycle = res.getIntValue(index++);
              this.resTestType = res.getIntValue(index++);
              this.dischargeType = res.getIntValue(index++);
              this.battCapStd = res.getIntValue(index++);
              this.backup1 = res.getIntValue(index++);
              this.backup2 = res.getIntValue(index++);
              this.backup3 = res.getIntValue(index++);
              this.backup4 = res.getIntValue(index++);
            return true;
        }
        return false;
    }
 
 
    public boolean setUpConcenParam(MyModbusMaster master) {    
        int offset = MyModBusCom.LD_BATT_COLLECTIO_PARAM_ADDR;
        int index = offset;
        
        boolean flag = MyModbusUtils.writeHoldingRegister(index++, this.addr, DataType.TWO_BYTE_INT_UNSIGNED, master);                //²âÊÔÆðʼµç³ØÐòºÅ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.firthMonCount, DataType.TWO_BYTE_INT_UNSIGNED, master);        //±ê³ÆÈÝÁ¿
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.secondMonCount, DataType.TWO_BYTE_INT_UNSIGNED, master);        //·ÅµçµçÁ÷
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.thirdMonCount, DataType.TWO_BYTE_INT_UNSIGNED, master);        //µ¥ÌåÏÂÏÞ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.fourthMonCount, DataType.TWO_BYTE_INT_UNSIGNED, master);        //³äµçµçÁ÷
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.fifthMonCount, DataType.TWO_BYTE_INT_UNSIGNED, master);        //µ¥ÌåÉÏÏÞ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.currRange, DataType.TWO_BYTE_INT_UNSIGNED, master);            //ÔÚÏßµçѹ·§Öµ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.floatCurrLimit*10, DataType.TWO_BYTE_INT_UNSIGNED, master);    //³äµçµçÁ÷ÏÂÏÞ·§Öµ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.rippleCurrLimit*100, DataType.TWO_BYTE_INT_UNSIGNED, master);    //³äµçÈÝÁ¿ÏÂÏÞÂÊ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.autoTestCycle, DataType.TWO_BYTE_INT_UNSIGNED, master);        //ÔÚÏßµçѹ»Ö¸´·§Öµ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.resTestType, DataType.TWO_BYTE_INT_UNSIGNED, master);            //Ä£¿éµØÖ·
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.dischargeType, DataType.TWO_BYTE_INT_UNSIGNED, master);        //¾ùºâ¹¦ÄÜÆôÍ£
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.battCapStd, DataType.TWO_BYTE_INT_UNSIGNED, master);            //ÈÝÁ¿ÏÂÏÞ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.backup1, DataType.TWO_BYTE_INT_UNSIGNED, master);                //Êý¾ÝÀ´Ô´
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.backup2, DataType.TWO_BYTE_INT_UNSIGNED, master);                //ÄÚ×è²âÊÔϵÊý
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.backup3, DataType.TWO_BYTE_INT_UNSIGNED, master);                //ζÈÉÏÏÞ
        flag = flag&MyModbusUtils.writeHoldingRegister(index++, this.backup4*10, DataType.TWO_BYTE_INT_UNSIGNED, master);            //ÄÚ×èÉÏÏÞ
        
        return flag;
    }
}