whyclj
2020-12-28 abbe39a2e93415bff7014cf2134a47103f85dbff
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
package com.data;
 
import java.util.Date;
 
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 Central_RT_Data {
    
    private int dev_id;             // 'É豸id',
    private Date record_time;    //'¸üÐÂʱ¼ä',
    
    private int switch_close;    // '¿ª¹ØºÏբ״̬',
    private int switch_open;     // '¿ª¹Ø·Öբ״̬',
    private int switch_fault;    // '¿ª¹Ø¹ÊÕÏ״̬',
    private float panel_vol ;    // '½øÏ߯Áµçѹ',
    private float panel_curr ;   // '½øÏ߯ÁµçÁ÷',
    
    private String note;         //'±¸ÓÃ',
    
    public BatchRead<Integer> createBatchRead(MyModbusMaster master) {
        BatchRead<Integer> batch = new BatchRead<Integer>();        
        batch.addLocator(0,MyModbusUtils.createInputLocator(1,master));        //'1ºÅ2500A½øÏ߯Á¿ª¹ØºÏբ״̬',
        batch.addLocator(1,MyModbusUtils.createInputLocator(2,master));        //'1ºÅ2500A½øÏ߯Á¿ª¹Ø·Öբ״̬'
        batch.addLocator(2,MyModbusUtils.createInputLocator(3, master));    //'1ºÅ2500A½øÏ߯Á¿ª¹Ø¹ÊÕÏ״̬',
        
        batch.addLocator(3,MyModbusUtils.createBaseLocator(1,DataType.TWO_BYTE_INT_SIGNED,master));    //'AÅŵçÁ÷',
        if(10001 == dev_id) {            
            batch.addLocator(4,MyModbusUtils.createBaseLocator(2,DataType.TWO_BYTE_INT_SIGNED,master));    //'AÅŵçѹ',
        }
 
        
        return batch;
    }
 
    public void putBatchResult(BatchResults<Integer> res) {
        if(null != res) {
            switch_close = MyModbusUtils.readBooleanToInt(res.getValue(0));    // '¿ª¹ØºÏբ״̬',
            switch_open = MyModbusUtils.readBooleanToInt(res.getValue(1));     // '¿ª¹Ø·Öբ״̬',
            switch_fault = MyModbusUtils.readBooleanToInt(res.getValue(2));    // '¿ª¹Ø¹ÊÕÏ״̬',
            if(10001 == dev_id) {
                panel_vol  = MyModbusUtils.readShortToInt(res.getValue(3));    // '½øÏ߯Áµçѹ',
                panel_curr = MyModbusUtils.readShortToInt(res.getValue(4));   // '½øÏ߯ÁµçÁ÷',
            }else {
                panel_curr = MyModbusUtils.readShortToInt(res.getValue(3));   // '½øÏ߯ÁµçÁ÷',
            }
        }
    }
    
    
    public Central_RT_Data() {
        
    }
    
    public Central_RT_Data(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 getSwitch_close() {
        return switch_close;
    }
    public void setSwitch_close(int switch_close) {
        this.switch_close = switch_close;
    }
    public int getSwitch_open() {
        return switch_open;
    }
    public void setSwitch_open(int switch_open) {
        this.switch_open = switch_open;
    }
    public int getSwitch_fault() {
        return switch_fault;
    }
    public void setSwitch_fault(int switch_fault) {
        this.switch_fault = switch_fault;
    }
    public float getPanel_vol() {
        return panel_vol;
    }
    public void setPanel_vol(float panel_vol) {
        this.panel_vol = panel_vol;
    }
    public float getPanel_curr() {
        return panel_curr;
    }
    public void setPanel_curr(float panel_curr) {
        this.panel_curr = panel_curr;
    }
    public String getNote() {
        return note;
    }
    public void setNote(String note) {
        this.note = note;
    }
    @Override
    public String toString() {
        return "Central_RT_Data [dev_id=" + dev_id + ", record_time=" + record_time + ", switch_close=" + switch_close
                + ", switch_open=" + switch_open + ", switch_fault=" + switch_fault + ", panel_vol=" + panel_vol
                + ", panel_curr=" + panel_curr + ", note=" + note + "]";
    }
}