本文整理汇总了Java中javax.comm.CommPortIdentifier.getPortType方法的典型用法代码示例。如果您正苦于以下问题:Java CommPortIdentifier.getPortType方法的具体用法?Java CommPortIdentifier.getPortType怎么用?Java CommPortIdentifier.getPortType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.comm.CommPortIdentifier
的用法示例。
在下文中一共展示了CommPortIdentifier.getPortType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.comm.CommPortIdentifier; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException
{
portList = CommPortIdentifier.getPortIdentifiers();
int i;
while (portList.hasMoreElements())
{
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
{
if (portId.getName().equals("COM5"))
{
System.out.println("Welcome To UltraClenz Gateway Diagnosis Center");
HyperMain reader = new HyperMain();
}
}
}
}
示例2: getPortIdentifiers
import javax.comm.CommPortIdentifier; //导入方法依赖的package包/类
@Override
public List<String> getPortIdentifiers() {
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
List<String> list = new ArrayList<String>();
while (ports.hasMoreElements()) {
CommPortIdentifier id = (CommPortIdentifier) ports.nextElement();
if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
list.add(id.getName());
}
}
return list;
}
示例3: CommPortSimple
import javax.comm.CommPortIdentifier; //导入方法依赖的package包/类
public CommPortSimple(String devName) throws Exception {
@SuppressWarnings("unchecked")
Enumeration<CommPortIdentifier> pList =
CommPortIdentifier.getPortIdentifiers();
// Walk the list, looking for the given name
CommPortIdentifier cpi = null;
boolean atLeastOneSerialPresent = false;
while (pList.hasMoreElements()) {
CommPortIdentifier c = pList.nextElement();
if (c.getPortType() !=CommPortIdentifier.PORT_SERIAL) {
System.err.println("Not a serial port: " + c.getName());
continue;
}
if (devName.equals(c.getName())) {
cpi = c;
break; // found!
}
atLeastOneSerialPresent = true;
System.out.println("Not matched: " + c.getName());
}
if (cpi == null) {
System.err.println("Did not find serial port '" + devName + "'");
if (atLeastOneSerialPresent)
System.err.println("Try again with one of the listed names");
else
System.err.println("In fact, I didn't see ANY serial ports!");
System.exit(1);
}
thePort = cpi.open("JavaCook DataComm",
TIMEOUTSECONDS * 1000);
SerialPort myPort = (SerialPort) thePort;
// set up the serial port
myPort.setSerialPortParams(BAUD, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
// Get the input and output streams
is = new BufferedReader(new InputStreamReader(thePort.getInputStream()));
os = new PrintStream(thePort.getOutputStream(), true);
}