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

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

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

/*-
 * #%L
 * **********************************************************************
 * ORGANIZATION  :  Pi4J
 * PROJECT       :  Pi4J :: LIBRARY  :: Java Library (CORE)
 * FILENAME      :  Serial.java
 *
 * This file is part of the Pi4J project. More information about
 * this project can be found here:  https://pi4j.com/
 * **********************************************************************
 * 
 * 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.
 * #L%
 */

import com.pi4j.context.Context;
import com.pi4j.io.IO;
import com.pi4j.io.IODataReader;
import com.pi4j.io.IODataWriter;

/**
 * 

Serial interface.

* * @author Robert Savage (http://www.savagehomeautomation.com) * @version $Id: $Id */ public interface Serial extends IO, AutoCloseable, IODataWriter, IODataReader { /** Constant DEFAULT_BAUD=9600 */ int DEFAULT_BAUD = 9600; /** Constant DEFAULT_DATA_BITS */ DataBits DEFAULT_DATA_BITS = DataBits._8; /** Constant DEFAULT_PARITY */ Parity DEFAULT_PARITY = Parity.NONE; /** Constant DEFAULT_STOP_BITS */ StopBits DEFAULT_STOP_BITS = StopBits._1; /** Constant DEFAULT_FLOW_CONTROL */ FlowControl DEFAULT_FLOW_CONTROL = FlowControl.NONE; /** *

newConfigBuilder.

* * @param context {@link Context} * @return a {@link com.pi4j.io.serial.SerialConfigBuilder} object. */ static SerialConfigBuilder newConfigBuilder(Context context) { return SerialConfigBuilder.newInstance(context); } /** * Serial Device Communication State is OPEN * * @return The Serial device communication state */ boolean isOpen(); /** * Get the number of data bytes available in the serial receive buffer * * @return a int. */ int available(); /** * This function will drain the current serial receive buffer of any lingering bytes. * * @return Returns the number of bytes of data drained (>=0) if OK, otherwise a negative error code. */ default int drain() { // get number of bytes available int avail = this.available(); if(avail > 0) { byte[] temp = new byte[avail]; return this.read(temp); } else{ return 0; } } /** *

open.

*/ void open(); /** *

close.

*/ void close(); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy