whyclj
2021-01-05 64aba412c2b739d67795b14a3cae069d311697f9
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
package com.dev.afeinverter;
 
import java.util.Date;
 
import com.ComBase;
import com.intelligt.modbus.MyJlibModbus;
import com.intelligt.modbus.jlibmodbus.exception.IllegalDataAddressException;
import com.intelligt.modbus.jlibmodbus.exception.IllegalDataValueException;
import com.modbus.data.MyModbusMaster;
import com.modbus.data.MyModbusUtils;
import com.serotonin.modbus4j.BatchRead;
import com.serotonin.modbus4j.BatchResults;
import com.serotonin.modbus4j.code.DataType;
 
/**
 *     ÕûÁ÷״̬ÐÅÏ¢
 */
public class Afe_Rectifier_State {
    
    public int dev_id;
    public Date record_time = new Date();            //¼Ç¼ʱ¼ä
    
    public int state1;
    public int state2;
    public int rectifier_start;            //'ÕûÁ÷Æô¶¯',
    public int rectifier_stop;            //'ÕûÁ÷Í£Ö¹',
    public int inverter_start;            //'Äæ±äÆô¶¯',
    public int inverter_stop;            //'Äæ±äÍ£Ö¹',
    public int speed_torque_change;        //'ËÙ¶È/ת¾ØÄ£Ê½',
    public int reset;                    //'¸´Î»',
    public int rectifier_run;            //'ÕûÁ÷ÔËÐÐ',
    public int inverter_run;            //'Äæ±äÔËÐÐ',
    public int report_alm;                //'×ۺϱ¨¾¯',
    public int report_fault;            //'×ۺϹÊÕÏ',
    
    public BatchRead<Integer> createBatchRead(MyModbusMaster master) {
        BatchRead<Integer> batch = new BatchRead<Integer>();        
        batch.addLocator(0,MyModbusUtils.createBaseLocator(0x85B6,DataType.TWO_BYTE_INT_UNSIGNED,master));        //
        batch.addLocator(1,MyModbusUtils.createBaseLocator(0x85B7,DataType.TWO_BYTE_INT_UNSIGNED,master));        //
        return batch;
    }
 
    public void putBatchResult(BatchResults<Integer> res) {
        if(null != res) {
            int state1 = MyModbusUtils.readIntergerToInt(res.getValue(0));
            int state2 = MyModbusUtils.readIntergerToInt(res.getValue(1));
            //System.out.println(state1+"==="+state2);
            
            this.rectifier_start = (state1 & ComBase.my_power_2(0))>0?1:0;
            this.rectifier_stop = (state1 & ComBase.my_power_2(1))>0?1:0;
            this.inverter_start = (state1 & ComBase.my_power_2(2))>0?1:0;
            this.inverter_stop = (state1 & ComBase.my_power_2(3))>0?1:0;
            this.speed_torque_change = (state1 & ComBase.my_power_2(4))>0?1:0;
            this.reset = (state1 & ComBase.my_power_2(5))>0?1:0;
            
            this.rectifier_run = (state2 & ComBase.my_power_2(0))>0?1:0;
            this.inverter_run = (state2 & ComBase.my_power_2(1))>0?1:0;
            this.report_alm = (state2 & ComBase.my_power_2(2))>0?1:0;
            this.report_fault = (state2 & ComBase.my_power_2(3))>0?1:0;
            this.record_time = new Date();
        }
    }
 
    public void readMutliData(MyJlibModbus mymodbus) {
        try {
            int state1 = mymodbus.holdings_ser.get(0x85B6);
            int state2 = mymodbus.holdings_ser.get(0x85B7);
            
            rectifier_start = (state1&ComBase.my_power_2(0))>0?1:0;            //'ÕûÁ÷Æô¶¯',
            rectifier_stop = (state1&ComBase.my_power_2(1))>0?1:0;            //'ÕûÁ÷Í£Ö¹',
            inverter_start = (state1&ComBase.my_power_2(2))>0?1:0;            //'Äæ±äÆô¶¯',
            inverter_stop = (state1&ComBase.my_power_2(3))>0?1:0;            //'Äæ±äÍ£Ö¹',
            speed_torque_change = (state1&ComBase.my_power_2(4))>0?1:0;        //'ËÙ¶È/ת¾ØÄ£Ê½',
            reset = (state1&ComBase.my_power_2(5))>0?1:0;                    //'¸´Î»',
            rectifier_run = (state2&ComBase.my_power_2(0))>0?1:0;            //'ÕûÁ÷ÔËÐÐ',
            inverter_run = (state2&ComBase.my_power_2(1))>0?1:0;            //'Äæ±äÔËÐÐ',
            report_alm = (state2&ComBase.my_power_2(2))>0?1:0;                //'×ۺϱ¨¾¯',
            report_fault = (state2&ComBase.my_power_2(3))>0?1:0;            //'×ۺϹÊÕÏ',
        } catch (IllegalDataAddressException e) {
            e.printStackTrace();
        }
    }
    
    public void randomData() {
        rectifier_start = MyModbusUtils.CreateSwitchRanDom();
        rectifier_stop = MyModbusUtils.CreateSwitchRanDom();
        inverter_start = MyModbusUtils.CreateSwitchRanDom();
        inverter_stop = MyModbusUtils.CreateSwitchRanDom();
        speed_torque_change = MyModbusUtils.CreateSwitchRanDom();
        reset = MyModbusUtils.CreateSwitchRanDom();
        state1 = rectifier_start*ComBase.my_power_2(0) + rectifier_stop*ComBase.my_power_2(1)+inverter_start*ComBase.my_power_2(2)+inverter_stop*ComBase.my_power_2(3)+speed_torque_change*ComBase.my_power_2(4)+reset*ComBase.my_power_2(5);
        rectifier_run = MyModbusUtils.CreateSwitchRanDom();
        inverter_run = MyModbusUtils.CreateSwitchRanDom();
        report_alm = MyModbusUtils.CreateSwitchRanDom();
        report_fault = MyModbusUtils.CreateSwitchRanDom();
        state2 = rectifier_run*ComBase.my_power_2(0)+inverter_run*ComBase.my_power_2(1)+report_alm*ComBase.my_power_2(2)+report_fault*ComBase.my_power_2(3);
    }
    
    public void writeMutliData(MyJlibModbus mymodbus) {
        try {
            mymodbus.holdings_ser.set(0x85B6, state1);
            mymodbus.holdings_ser.set(0x85B7, state2);
        } catch (IllegalDataAddressException | IllegalDataValueException e) {
            e.printStackTrace();
        }
    }
    
    public Afe_Rectifier_State() {
        
    }
    
    public Afe_Rectifier_State(int dev_id) {
        this.dev_id = dev_id;
    }
    
    public int getDev_id() {
        return dev_id;
    }
    public void setDev_id(int dev_id) {
        this.dev_id = dev_id;
    }
    public Date getRecord_time() {
        return record_time;
    }
    public void setRecord_time(Date record_time) {
        this.record_time = record_time;
    }
    public int getRectifier_start() {
        return rectifier_start;
    }
    public void setRectifier_start(int rectifier_start) {
        this.rectifier_start = rectifier_start;
    }
    public int getRectifier_stop() {
        return rectifier_stop;
    }
    public void setRectifier_stop(int rectifier_stop) {
        this.rectifier_stop = rectifier_stop;
    }
    public int getInverter_start() {
        return inverter_start;
    }
    public void setInverter_start(int inverter_start) {
        this.inverter_start = inverter_start;
    }
    public int getInverter_stop() {
        return inverter_stop;
    }
    public void setInverter_stop(int inverter_stop) {
        this.inverter_stop = inverter_stop;
    }
    public int getSpeed_torque_change() {
        return speed_torque_change;
    }
    public void setSpeed_torque_change(int speed_torque_change) {
        this.speed_torque_change = speed_torque_change;
    }
    public int getReset() {
        return reset;
    }
    public void setReset(int reset) {
        this.reset = reset;
    }
    public int getRectifier_run() {
        return rectifier_run;
    }
    public void setRectifier_run(int rectifier_run) {
        this.rectifier_run = rectifier_run;
    }
    public int getInverter_run() {
        return inverter_run;
    }
    public void setInverter_run(int inverter_run) {
        this.inverter_run = inverter_run;
    }
    public int getReport_alm() {
        return report_alm;
    }
    public void setReport_alm(int report_alm) {
        this.report_alm = report_alm;
    }
    public int getReport_fault() {
        return report_fault;
    }
    public void setReport_fault(int report_fault) {
        this.report_fault = report_fault;
    }
    
    @Override
    public String toString() {
        return "Afe_Rectifier_State [dev_id=" + dev_id + ", record_time=" + record_time + ", rectifier_start="
                + rectifier_start + ", rectifier_stop=" + rectifier_stop + ", inverter_start=" + inverter_start
                + ", inverter_stop=" + inverter_stop + ", speed_torque_change=" + speed_torque_change + ", reset="
                + reset + ", rectifier_run=" + rectifier_run + ", inverter_run=" + inverter_run + ", report_alm="
                + report_alm + ", report_fault=" + report_fault + "]";
    }
}