本文整理汇总了Java中javax.comm.CommPortIdentifier类的典型用法代码示例。如果您正苦于以下问题:Java CommPortIdentifier类的具体用法?Java CommPortIdentifier怎么用?Java CommPortIdentifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommPortIdentifier类属于javax.comm包,在下文中一共展示了CommPortIdentifier类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: abrePorta
import javax.comm.CommPortIdentifier; //导入依赖的package包/类
private void abrePorta() {
try {
CommPortIdentifier cp = CommPortIdentifier.getPortIdentifier( "/dev/ttyS0" );
porta = (SerialPort) cp.open( "SComm", 1 );
InputStream entrada = porta.getInputStream();
porta.notifyOnDataAvailable( true );
porta.addEventListener( this );
} catch ( Exception e ) {
e.printStackTrace();
}
}
示例4: abrePorta
import javax.comm.CommPortIdentifier; //导入依赖的package包/类
private void abrePorta() {
try {
CommPortIdentifier cp = CommPortIdentifier.getPortIdentifier( "/dev/ttyS0" );
porta = (SerialPort) cp.open( "SComm", 1 );
InputStream entrada = porta.getInputStream();
porta.notifyOnDataAvailable( true );
} catch ( Exception e ) {
e.printStackTrace();
}
}
示例5: 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);
}