/*
* @(#)SimpleRead.java 1.12 98/06/25 SMI
*
* Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
*
* Sun grants you ("Licensee") a non-exclusive, royalty free, license
* to use, modify and redistribute this software in source and binary
* code form, provided that i) this copyright notice and license appear
* on all copies of the software; and ii) Licensee does not utilize the
* software in a manner which is disparaging to Sun.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
* LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE
* SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS
* BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,
* HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING
* OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* This software is not designed or intended for use in on-line control
* of aircraft, air traffic, aircraft navigation or aircraft
* communications; or in the design, construction, operation or
* maintenance of any nuclear facility. Licensee represents and
* warrants that it will not use or redistribute the Software for such
* purposes.
*/
package javax.comm;
import java.io.*;
import java.util.*;
/**
* Communications port management. <CODE>CommPortIdentifier</CODE>
* is the central class for controlling access to communications ports.
* It includes methods for:
* <UL>
* <LI>
* Determining the communications ports made available by the driver.
* <LI>
* Opening communications ports for I/O operations.
* <LI>
* Determining port ownership.
* <LI>
* Resolving port ownership contention.
* <LI>
* Managing events that indicate changes in port ownership status.
* </UL>
* <P>
* An application first uses methods in <CODE>CommPortIdentifier</CODE>
* to negotiate with the driver to discover which communication ports
* are available and then select a port for opening. It then uses
* methods in other classes like <CODE>CommPort</CODE>, <CODE>ParallelPort</CODE>
* and <CODE>SerialPort</CODE> to communicate through the port.
*
* @author Jagane Sundar
* @version 1.11, 23 Jan 1998
* @see javax.comm.CommPort
* @see javax.comm.CommPortOwnershipListener
* @see javax.comm.ParallelPort
* @see javax.comm.SerialPort
*/
public class CommPortIdentifier {
/**
* Obtains an enumeration object that contains a <CODE>CommPortIdentifier</CODE>
* object for each port in the system.
*
* @return an <CODE> Enumeration </CODE> object that can be used to
* enumerate all the ports known to the system
*
* @see java.util.Enumeration
*/
static public Enumeration getPortIdentifiers() {
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
sec.checkRead(propfilename);
}
return new CommPortEnumerator();
}
/**
* Obtains a <CODE>CommPortIdentifier</CODE> object by using a port name.
* The port name may have been stored in persistent storage by the application.
*
* @param <CODE>portName</CODE> name of the port to open
* @return a <CODE>CommPortIdentifier</CODE> object
* @exception NoSuchPortException if the port does not exist
*/
static public CommPortIdentifier getPortIdentifier(String portName)
throws NoSuchPortException {
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
sec.checkRead(propfilename);
}
CommPortIdentifier portId = null;
synchronized (lock) {
portId = masterIdList;
while (portId != null) {
if (portId.name.equals(portName))
break;
portId = portId.next;
}
}
if (portId != null) {
return portId;
} else {
throw new NoSuchPortException();
}
}
/**
* Obtains the <CODE>CommPortIdentifier</CODE> object corresponding
* to a port that has already been opened by the application.
*
* @param port a CommPort object obtained from a previous open
* @return a CommPortIdentifier object
* @exception NoSuchPortException if the port object is invalid
*/
static public CommPortIdentifier getPortIdentifier(CommPort port)
throws NoSuchPortException {
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
sec.checkRead(propfilename);
}
CommPortIdentifier portId = null;
synchronized (lock) {
portId = masterIdList;
while (portId != null) {
if (portId.port == port)
break;
portId = portId.next;
}
}
if (portId != null) {
return portId;
} else {
throw new NoSuchPortException();
}
}
/**
* Adds <CODE>CommPort</CODE> object to the list of ports.
*/
private static void addPort(CommPort port, int portType) {
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
sec.checkRead(propfilename);
}
CommPortIdentifier newentry =
new CommPortIdentifier(port.getName(), port, portType, null);
CommPortIdentifier cur = masterIdList, prev = null;
synchronized (lock) {
while (cur != null) {
prev = cur;
cur = cur.next;
}
if (prev != null) {
prev.next = newentry;
} else {
masterIdList = newentry;
}
}
}
/**
* Adds <CODE>portName</CODE> to the list of ports.
* @param portName The name of the port being added
* @param portType The type of the port being added
* @param driver The driver representing the port being added
* @see javax.comm.CommDriver
* @since CommAPI 1.1
*/
public static void addPortName(String portName, int portType,
CommDriver driver) {
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
sec.checkRead(propfilename);
}
CommPortIdentifier newentry =
new CommPortIdentifier(portName, null, portType, driver);
CommPortIdentifier cur = masterIdList, prev = null;
synchronized (lock) {
while (cur != null) {
prev = cur;
cur = cur.next;
}
if (prev != null) {
prev.next = newentry;
} else {
masterIdList = newentry;
}
}
}
/**
* Returns the name of the port. The port name should be identifiable
* by the user. Ideally, it should be the label on the hardware.
* For example, "COM1" and "COM2" on PCs; "Serial A" and "Serial B"
* on Sun Ultra workstations. The port name may be stored by an application
* and subsequently used to create a <CODE>CommPortIdentifier</CODE>
* object using <CODE>getPortIdentifier(String portName)</CODE> method.
*
* @return the name of the port
*/
public String getName() {
return name;
}
String name;
private int portType;
/**
* RS-232 serial port
*/
public static final int PORT_SERIAL = 1;
/**
* IEEE 1284 parallel port
*/
public static final int PORT_PARALLEL = 2;
/**
* Returns the port type.
*
* @return portType - PORT_SERIAL or PORT_PARALLEL
*/
public int getPortType() {
return portType;
}
private boolean maskOwnershipEvents;
/**
* Opens the communications port. <CODE>open</CODE> obtains
* exclusive ownership of the port. If the port is owned by some
* other application, a <CODE>PORT_OWNERSHIP_REQUESTED</CODE> event
* is propagated using the <CODE>CommPortOwnershipListener</CODE>
* event mechanism. If the application that owns the port calls
没有合适的资源?快使用搜索试试~ 我知道了~
javacomm.jar+api文档
共115个文件
java:43个
class:21个
gif:20个
需积分: 5 2 下载量 16 浏览量
2023-01-06
14:21:50
上传
评论
收藏 244KB RAR 举报
温馨提示
用Java实现串口通信(windows系统下),需要用到sun提供的串口包 javacomm20-win32.zip。
资源推荐
资源详情
资源评论
收起资源包目录
javacomm.jar+api文档 (115个子文件)
SerialPortDisplay.class 9KB
BlackBox.class 6KB
Transmitter.class 5KB
Receiver.class 4KB
ReceiveFraming.class 3KB
CtlSigDisplay.class 3KB
ReceiveThreshold.class 3KB
ReceiveTimeout.class 3KB
BufferSize.class 3KB
FlowCtlDisplay.class 3KB
ByteStatistics.class 2KB
BaudRate.class 2KB
DataBits.class 2KB
StopBits.class 2KB
Parity.class 2KB
ByteCounter.class 2KB
ToggleMouseListener.class 1KB
ReceiveOptions.class 1KB
OneWayMouseListener.class 864B
ToggleLabel.class 689B
ConvertedOutputStream.class 668B
win32com.dll 27KB
constructor-index.gif 2KB
exception-index.gif 2KB
interface-index.gif 2KB
package-index.gif 2KB
method-index.gif 2KB
variable-index.gif 2KB
constructors.gif 2KB
class-index.gif 1KB
methods.gif 1KB
variables.gif 1KB
blue-ball.gif 925B
yellow-ball.gif 925B
magenta-ball.gif 896B
green-ball.gif 886B
red-ball.gif 527B
red-ball-small.gif 255B
blue-ball-small.gif 255B
yellow-ball-small.gif 255B
magenta-ball-small.gif 104B
green-ball-small.gif 102B
AllNames.html 37KB
javax.comm.SerialPort.html 31KB
javax.comm.CommPort.html 21KB
javax.comm.CommPortIdentifier.html 15KB
javax.comm.ParallelPort.html 14KB
javax.comm.SerialPortEvent.html 9KB
javax.comm.ParallelPortEvent.html 6KB
javax.comm.CommPortOwnershipListener.html 5KB
API_users_guide.html 4KB
javax.comm.UnsupportedCommOperationException.html 3KB
javax.comm.CommDriver.html 3KB
javax.comm.PortInUseException.html 2KB
javax.comm.ParallelPortEventListener.html 2KB
tree.html 2KB
javax.comm.SerialPortEventListener.html 2KB
Package-javax.comm.html 2KB
javax.comm.NoSuchPortException.html 1KB
packages.html 581B
BlackBox.jar 35KB
comm.jar 27KB
CommPortIdentifier.java 21KB
SerialDemo.java 18KB
SerialPortDisplay.java 12KB
ParallelPortDisplay.java 11KB
SerialConnection.java 10KB
SerialParameters.java 10KB
NullSerialPort.java 10KB
BlackBox.java 8KB
ParallelBlackBox.java 7KB
CtlSigDisplay.java 6KB
Transmitter.java 6KB
Receiver.java 5KB
Transmitter.java 5KB
Receiver.java 5KB
FlowCtlDisplay.java 5KB
ByteStatistics.java 5KB
ByteStatistics.java 5KB
ReceiveThreshold.java 4KB
ReceiveThreshold.java 4KB
ReceiveTimeout.java 4KB
ReceiveTimeout.java 4KB
ReceiveFraming.java 4KB
ReceiveFraming.java 4KB
SimpleRead.java 4KB
BufferSize.java 4KB
BufferSize.java 4KB
LPTMode.java 4KB
DataBits.java 4KB
PortRequestedDialog.java 4KB
StopBits.java 4KB
CtlSigDisplay.java 3KB
Parity.java 3KB
BaudRate.java 3KB
AlertDialog.java 3KB
NullDriver.java 3KB
SimpleWrite.java 3KB
ByteCounter.java 3KB
ByteCounter.java 3KB
共 115 条
- 1
- 2
资源评论
十月呀
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功