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
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_sys_version {
    public static int BYTE_LEN=4;            //¼Ä´æÆ÷¸öÊý
    private int cmd;                        //·¢ËÍÊý¾ÝµÄÃüÁî
    private int cmd_addr;                    //É豸µØÖ·
    private int cmd_addr_back;                //¼Ä´æÆ÷µÄÆðʼµØÖ·
    
    private int dataCount;                    //Êý¾ÝµÄ³¤¶È
    private int sys_type;                    //É豸ÀàÐÍ
    private int sys_dev_id;                  //É豸id
    private int sys_software_version;        //É豸Èí¼þ°æ±¾
    private int sys_hardware_version;        //É豸Ӳ¼þ°æ±¾
    
    //»ñȡϵͳʱ¼ä
      public boolean setLD_sys_tem_version(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.sys_type=ComBase.changeShortToInt(tmpbuf.getShort());
            this.sys_dev_id=ComBase.changeShortToInt(tmpbuf.getShort());
            this.sys_dev_id = this.sys_dev_id + 4019*100000;
            this.sys_software_version=ComBase.changeShortToInt(tmpbuf.getShort());
            this.sys_hardware_version=ComBase.changeShortToInt(tmpbuf.getShort());
            
            flag = true;
        } catch (Exception e) {
              e.printStackTrace();
          }                
          return flag;
    }
      
      /**
       * »ñÈ¡É豸µÄ°æ±¾ºÅ
       * @return
       */
      public String getDev_version(){
          String version = "";
          if(sys_hardware_version>=0 && sys_hardware_version >= 0){
              version = "V"+sys_software_version+"."+sys_hardware_version;
          }
          return version;
      }
 
    public int getCmd() {
        return cmd;
    }
 
    public void setCmd(int cmd) {
        this.cmd = cmd;
    }
 
    public int getCmd_addr() {
        return cmd_addr;
    }
 
    public void setCmd_addr(int cmd_addr) {
        this.cmd_addr = cmd_addr;
    }
 
    public int getDataCount() {
        return dataCount;
    }
 
    public void setDataCount(int dataCount) {
        this.dataCount = dataCount;
    }
 
    public int getSys_type() {
        return sys_type;
    }
 
    public void setSys_type(int sys_type) {
        this.sys_type = sys_type;
    }
 
    public int getSys_dev_id() {
        return sys_dev_id;
    }
 
    public void setSys_dev_id(int sys_dev_id) {
        this.sys_dev_id = sys_dev_id;
    }
 
    public int getSys_software_version() {
        return sys_software_version;
    }
 
    public void setSys_software_version(int sys_software_version) {
        this.sys_software_version = sys_software_version;
    }
 
    public int getSys_hardware_version() {
        return sys_hardware_version;
    }
 
    public void setSys_hardware_version(int sys_hardware_version) {
        this.sys_hardware_version = sys_hardware_version;
    }
 
    public int getCmd_addr_back() {
        return cmd_addr_back;
    }
 
    public void setCmd_addr_back(int cmd_addr_back) {
        this.cmd_addr_back = cmd_addr_back;
    }
 
    public BatchRead<Integer> createLDVersionBatchRead(MyModbusMaster master) {
        int offset = MyModBusCom.LD_CMD_SYS_VERSION_ADDR;
        BatchRead<Integer> batch = new BatchRead<Integer>();
        batch.addLocator(0,MyModbusUtils.createBaseLocator(offset,DataType.TWO_BYTE_INT_UNSIGNED, master));        //É豸ÀàÐÍ                            
        batch.addLocator(1,MyModbusUtils.createBaseLocator(offset+1, DataType.TWO_BYTE_INT_UNSIGNED, master));    //É豸µØÖ·                        
        batch.addLocator(2,MyModbusUtils.createBaseLocator(offset+2, DataType.TWO_BYTE_INT_UNSIGNED, master));    //Èí¼þ°æ±¾                    
        batch.addLocator(3,MyModbusUtils.createBaseLocator(offset+3, DataType.TWO_BYTE_INT_UNSIGNED, master));    //Ó²¼þ°æ±¾                            
        return batch;
    }
 
    public boolean putLDVersionBatchResult(BatchResults<Integer> res) {
        if(null != res) {            
            this.sys_type = res.getIntValue(0);
            this.sys_dev_id = res.getIntValue(1);
            this.sys_dev_id = this.sys_dev_id + 4019*100000;
            this.sys_software_version = res.getIntValue(2);
            this.sys_hardware_version = res.getIntValue(3);
            return true;
        }    
        return false;
    }
      
      
}