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

com.pi4j.io.serial.SerialDataReader Maven / Gradle / Ivy

Go to download

This bundle wraps Pi4j (http://pi4j.com) that wraps the native code Wiring Pi (http://wiringpi.com). It wraps these libraries to make them OSGi friendly and allow them to work together with the OSGi enRoute IoT circuit library (osgi.enroute.iot.circuit). The bundle will first use Pi4J to detect on what hardware it runs. If it runs on an appropriate type, it will register a component that can be configured with Metatype. The Metatype defines a full blown configuration template for all the Pi's functions. The GPIO's are registered as components for the circuit. Regardless of the success of the configuration, this bundle will also register a GpioController service, which is the main Pi4J class.

The newest version!
package com.pi4j.io.serial;

/*
 * #%L
 * **********************************************************************
 * ORGANIZATION  :  Pi4J
 * PROJECT       :  Pi4J :: Java Library (Core)
 * FILENAME      :  SerialDataReader.java  
 * 
 * This file is part of the Pi4J project. More information about 
 * this project can be found here:  http://www.pi4j.com/
 * **********************************************************************
 * %%
 * Copyright (C) 2012 - 2015 Pi4J
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.Collection;


public interface SerialDataReader {

    /**
     * Gets the number of bytes available for reading, or -1 for any error condition.
     *
     * @return Returns the number of bytes available for reading, or -1 for any error
     */
    public int available() throws IllegalStateException, IOException;


    // ----------------------------------------
    // READ OPERATIONS
    // ----------------------------------------

    /**
     * 

discard/drain all available bytes from the serial port/device.

*/ public void discardData() throws IllegalStateException, IOException; /** *

Reads all available bytes from the serial port/device.

* * @return Returns a byte array with the data read from the serial port. */ public byte[] read() throws IllegalStateException, IOException; /** *

Reads a length of bytes from the port/serial device.

* * @param length * The number of bytes to get from the serial port/device. * This number must not be higher than the number of available bytes. * * @return Returns a byte array with the data read from the serial port. */ public byte[] read(int length) throws IllegalStateException, IOException; /** *

Reads all available bytes from the serial device into a provided ByteBuffer.

* * @param buffer * The ByteBuffer object to write to. */ public void read(ByteBuffer buffer) throws IllegalStateException, IOException; /** *

Reads a length bytes from the serial port/device into a provided ByteBuffer.

* * @param length * The number of bytes to get from the serial port/device. * This number must not be higher than the number of available bytes. * @param buffer * The ByteBuffer object to write to. * */ public void read(int length, ByteBuffer buffer) throws IllegalStateException, IOException; /** *

Reads all available bytes from the serial device into a provided OutputStream.

* * @param stream * The OutputStream object to write to. */ public void read(OutputStream stream) throws IllegalStateException, IOException; /** *

Reads a length bytes from the serial port/device into a provided OutputStream.

* * @param length * The number of bytes to get from the serial port/device. * This number must not be higher than the number of available bytes. * @param stream * The OutputStream object to write to. * */ public void read(int length, OutputStream stream) throws IllegalStateException, IOException; /** *

Reads all available bytes from the serial port/device into a provided collection of ByteBuffer objects.

* * @param collection * The collection of CharSequence objects to append to. * */ public void read(Collection collection) throws IllegalStateException, IOException; /** *

Reads a length of bytes from the serial port/device into a provided collection of ByteBuffer objects.

* * @param length * The number of bytes to get from the serial port/device. * This number must not be higher than the number of available bytes. * @param collection * The collection of CharSequence objects to append to. * */ public void read(int length, Collection collection) throws IllegalStateException, IOException; /** *

Reads all available bytes from the port/serial device and returns a CharBuffer from the decoded bytes.

* * @param charset * The character set to use for encoding/decoding bytes to/from text characters * * @return Returns a character set with the data read from the serial port. */ public CharBuffer read(Charset charset) throws IllegalStateException, IOException; /** *

Reads a length of bytes from the port/serial device and returns a CharBuffer from the decoded bytes.

* * @param length * The number of bytes to get from the serial port/device. * This number must not be higher than the number of available bytes. * @param charset * The character set to use for encoding/decoding bytes to/from text characters * * @return Returns a character set with the data read from the serial port. */ public CharBuffer read(int length, Charset charset) throws IllegalStateException, IOException; /** *

Reads all available bytes from the serial port/device into a provided Writer.

* * @param charset * The character set to use for encoding/decoding bytes to/from text characters * @param writer * The Writer object to write to. * */ public void read(Charset charset, Writer writer) throws IllegalStateException, IOException; /** *

Reads a length bytes from the serial port/device into a provided Writer.

* * @param length * The number of bytes to get from the serial port/device. * This number must not be higher than the number of available bytes. * @param charset * The character set to use for encoding/decoding bytes to/from text characters * @param writer * The Writer object to write to. * */ public void read(int length, Charset charset, Writer writer) throws IllegalStateException, IOException; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy