serialportapi.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 102 行

JAVA
102
字号
/*
 * $Id: SerialPortAPI.java,v 1.1 2003/11/25 11:42:35 epr Exp $
 * 
 * Serial port device API Oct 15 2003, mgeisse
 */
package org.jnode.driver.serial;

import org.jnode.driver.character.CharacterDeviceAPI;

/**
 * @author mgeisse
 * 
 * Serial port API. Note: This should actually be a subinterface of
 * CharacterDeviceAPI, but currently only single bytes can be sent.
 */
public interface SerialPortAPI extends CharacterDeviceAPI {
	public static final int BAUD1200 = 96;
	public static final int BAUD1800 = 64;
	public static final int BAUD2400 = 48;
	public static final int BAUD3600 = 32;
	public static final int BAUD4800 = 24;
	public static final int BAUD7200 = 16;
	public static final int BAUD9600 = 12;

	/**
	 * Configure the data format to be sent. Data is sent in blocks of 5 to 8
	 * bits, with 1, 1.5 or 2 stop bits and optional parity bits, in a
	 * definable baud rate.
	 * 
	 * The baud rate cannot be set directly, but only by a divisor parameter.
	 * The actual rate is then determined by the formula (115200/divisor). This
	 * is to allow most accurate control over the serial port hardware, which
	 * allows control only through a divisor value. The driver interface
	 * defines some constants for often-used baud rates.
	 * 
	 * This driver always maps one byte from the driver's data channel to one
	 * data block on the serial port. When reading or writing data in blocks
	 * less than 8 bits, the most significant bits are ignored (sending) or
	 * cleared (receiving).
	 * 
	 * The number of stop bits is determined as follows: If the longStop
	 * parameter is false, then one stop bit is used. Otherwise, a longer stop
	 * sequence is used: If the data block length is 5 bits, then 1.5 stop bits
	 * are used. If the data block length is 6-8 bits, then 2 stop bits are
	 * used.
	 * 
	 * Note that configuration of the serial port first requires to flush all
	 * buffers. If there is more data to be sent or received, this method
	 * blocks until that has happened.
	 * 
	 * @param divisor
	 *            defines the baud rate divisor
	 * @param bits
	 *            defines the number of bits per data block, ranging 5-8.
	 * @param longStop
	 *            determines whether more than one stop bit is used
	 * @param parity
	 *            enables the parity bit
	 * @param pEven
	 *            determines whether even parity (true) or odd parity (false)
	 *            is sent
	 */
	public void configure(int divisor, int bits, boolean longStop, boolean parity, boolean pEven);

	/**
	 * Configure the data format to be sent, using 8 data bits, no parity bit,
	 * and 1 stop bit.
	 * 
	 * @see org.jnode.driver.serial.SerialPortDriver#configure(int,int,boolean,boolean,boolean)
	 * 
	 * @param divisor
	 *            the baud rate divisor
	 */
	public void configure(int divisor);

	/**
	 * This method is not part of the final serial port API.
	 * 
	 * Receive a single byte from the serial port. This method blocks until a
	 * byte is available.
	 * 
	 * @return the received byte
	 */
	public int readSingle();

	/**
	 * This method is not part of the final serial port API.
	 * 
	 * Send a single byte through the serial port. This function blocks until
	 * the byte can be sent to the transmission buffer.
	 * 
	 * @param value
	 *            the byte to transmit
	 */
	public void writeSingle(int value);

	/**
	 * Wait until all buffered data is sent.
	 */
	public void flush();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?