All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.martiii.modbustcpjava.protocol.ModbusResponse Maven / Gradle / Ivy

The newest version!
package me.martiii.modbustcpjava.protocol;

import java.util.Arrays;

public class ModbusResponse {
    private byte functionCode;
    protected byte[] data;
    private boolean error;

    public ModbusResponse(byte functionCode, byte[] data, boolean error) {
        this.functionCode = functionCode;
        this.data = data;
        this.error = error;

        //TODO: Add write response helper class (like ReadResponse)
    }

    public byte getFunctionCode() {
        return functionCode;
    }

    public byte[] getData() {
        return data;
    }

    public boolean isError() {
        return error;
    }

    public int getErrorCode() {
        if (isError()) {
            return data[0];
        }
        return -1;
    }

    @Override
    public String toString() {
        return "ModbusResponse{" +
                "functionCode=" + functionCode +
                ", data=" + Arrays.toString(data) +
                ", error=" + error +
                '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy