huang
2025-09-03 6c9369ab9b7da99687857004470e8d7824eb69ae
JiuMuMesParent/common/servicebase/src/main/java/com/mes/service/PlcParameter.java
@@ -13,6 +13,8 @@
import java.util.HashMap;
import java.util.Map;
import static com.mes.tools.HexConversion.*;
/**
 * Plc参数
 */
@@ -28,7 +30,7 @@
    /**
     * 起始地址
     */
    private int addressIndex=0;
    private int addressStart=0;
    /**
     * 长度
     */
@@ -39,7 +41,11 @@
    private String type="int";
    /**
     * 实时读取的值
     * 实时读取的byte值
     */
    private byte[] readByte=null;
    /**
     * 实时读取的byte值转换成 对应类型
     */
    private Object readValue=null;
@@ -48,12 +54,17 @@
     */
    private Object writeValue=null;
    /**
     * 需要写入的值
     */
    private byte[] writeByte=null;
    PlcParameter(){
    }
    PlcParameter(String codeId, int addressIndex, int addressLength, String type){
    PlcParameter(String codeId, int addressStart, int addressLength, String type){
        this.CodeId=codeId;
        this.addressIndex=addressIndex;
        this.addressStart=addressStart;
        this.addressLength=addressLength;
        this.type=type;
    }
@@ -66,12 +77,12 @@
        CodeId = codeId;
    }
    public int getAddressIndex() {
        return addressIndex;
    public int getAddressStart() {
        return addressStart;
    }
    public void setAddressIndex(int addressIndex) {
        this.addressIndex = addressIndex;
    public void setAddressStart(int addressIndex) {
        this.addressStart = addressStart;
    }
    public int getAddressLength() {
@@ -91,18 +102,53 @@
    }
    public Object getReadValue() {
        return readValue;
    }
    public String getValueString() {
        return getValueInt()+"";
    }
    public int getValueInt() {
        if(this.readByte==null||this.readByte.length<1){
            //log.info("读取内容为null: {}  :{}",this.getCodeId(),this.readByte);
            return 0;
        }
        return bytesToIntDesc(this.readByte,0);
    }
    public void setReadValue(Object readValue) {
        this.readValue = readValue;
    }
    public byte[] getReadByte() {
        return this.readByte;
    }
    public void setReadByte(byte[] readByte) {
        this.readByte = readByte;
    }
    public Object getWriteValue() {
        return writeValue;
    }
    public void setWriteValue(Object writeValue) {
        this.writeValue = writeValue;
    public byte [] setWriteValue(Object writeValue) {
        //传入值根据参数类型进行转换成字符串保存进写入 字节内并且返回
        byte []sendByte=new byte[13+this.addressLength];
        if ("int".equals(this.type)){
            this.writeByte=intToBytesDesc(Integer.parseInt(writeValue.toString()),this.addressLength);
            return this.writeByte;
        }else if ("word".equals(this.type)){
            this.writeByte=intToBytesDesc(Integer.parseInt(writeValue.toString()),this.addressLength);
            return this.writeByte;
        }else if("string".equals(this.type)){
        }else{
        }
        return null;
    }
    public byte [] getWriteByte() {
        return this.writeByte;
    }
}