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

com.ghgande.j2mod.modbus.io.AbstractModbusTransport Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
/*
 * Copyright 2002-2016 jamod & j2mod development teams
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ghgande.j2mod.modbus.io;

import com.ghgande.j2mod.modbus.Modbus;
import com.ghgande.j2mod.modbus.ModbusIOException;
import com.ghgande.j2mod.modbus.msg.ModbusMessage;
import com.ghgande.j2mod.modbus.msg.ModbusRequest;
import com.ghgande.j2mod.modbus.msg.ModbusResponse;
import com.ghgande.j2mod.modbus.net.AbstractModbusListener;

import java.io.IOException;

/**
 * Interface defining the I/O mechanisms for
 * ModbusMessage instances.
 *
 * @author Dieter Wimberger
 * @author Steve O'Hara (4NG)
 * @version 2.0 (March 2016)
 */
public abstract class AbstractModbusTransport {

    protected int timeout = Modbus.DEFAULT_TIMEOUT;

    /**
     * Set the socket timeout
     *
     * @param time Timeout in milliseconds
     */
    public void setTimeout(int time) {
        timeout = time;
    }

    /**
     * Closes the raw input and output streams of
     * this ModbusTransport.
     * 

* * @throws IOException if a stream * cannot be closed properly. */ public abstract void close() throws IOException; /** * Creates a Modbus transaction for the underlying transport. * * @return the new transaction */ public abstract ModbusTransaction createTransaction(); /** * Writes a ModbusMessage to the * output stream of this ModbusTransport. *

* * @param msg a ModbusMessage. * * @throws ModbusIOException data cannot be * written properly to the raw output stream of * this ModbusTransport. */ public abstract void writeMessage(ModbusMessage msg) throws ModbusIOException; /** * Reads a ModbusRequest from the * input stream of this ModbusTransport. *

* * @param listener Listener the request was received by * * @return req the ModbusRequest read from the underlying stream. * * @throws ModbusIOException data cannot be * read properly from the raw input stream of * this ModbusTransport. */ public abstract ModbusRequest readRequest(AbstractModbusListener listener) throws ModbusIOException; /** * Reads a ModbusResponse from the * input stream of this ModbusTransport. *

* * @return res the ModbusResponse read from the underlying stream. * * @throws ModbusIOException data cannot be * read properly from the raw input stream of * this ModbusTransport. */ public abstract ModbusResponse readResponse() throws ModbusIOException; }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy