whyclxw
2021-05-13 366b7c2daeac609853befcc05ddbac2058425c52
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
package com.data;
 
import java.io.Serializable;
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 Torque_sensor_RT implements Serializable{
    private int num;
    private int dev_id;
    private Date record_time;
    private float torque;//40020/40037
    private float speed;
    private String note;
    
    public BatchRead<Integer> createBatchRead(MyModbusMaster master) {
        BatchRead<Integer> batch = new BatchRead<Integer>();        
        
        batch.addLocator(0,MyModbusUtils.createBaseLocator(40020,DataType.TWO_BYTE_INT_SIGNED,master));    //'Ť¾Ø',
        batch.addLocator(1,MyModbusUtils.createBaseLocator(40037,DataType.TWO_BYTE_INT_SIGNED,master));    //'תËÙ',
        return batch;
    }
    
    public void putBatchResult(BatchResults<Integer> res) {
        if(null != res) {
            torque = MyModbusUtils.readShortToFloat(res.getValue(0));                //'ת¾Ø',
            speed = MyModbusUtils.readShortToFloat(res.getValue(1));                //'תËÙ',
        }
        record_time = new Date();
    }
    
    public Torque_sensor_RT(int dev_id) {
        super();
        this.dev_id = dev_id;
    }
    public int getNum() {
        return num;
    }
    public void setNum(int num) {
        this.num = num;
    }
    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 float getTorque() {
        return torque;
    }
    public void setTorque(float torque) {
        this.torque = torque;
    }
    public float getSpeed() {
        return speed;
    }
    public void setSpeed(float speed) {
        this.speed = speed;
    }
    public String getNote() {
        return note;
    }
    public void setNote(String note) {
        this.note = note;
    }
    @Override
    public String toString() {
        return "Torque_sensor_RT [num=" + num + ", dev_id=" + dev_id + ", record_time=" + record_time + ", torque="
                + torque + ", speed=" + speed + ", note=" + note + "]";
    }
    
    
}