我晕啦,终于成功了,原来是我的基础不稳固造成的,呵呵今天成功了!!!
2008-01-01 19:17
351 查看
import java.util.*;
import java.io.*;
import javax.comm.*;
public class Jcomm
{
static OutputStream out;
static InputStream in;
public static void main(String args[]) throws IOException
{
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
String portName;
CommPortIdentifier portId;
SerialPort serialPort;
if (ports == null)
{
System.out.println("No comm ports found!");
}
else
while(ports.hasMoreElements())
{
System.out.println(" "+ ((CommPortIdentifier) ports.nextElement()).getName());
System.out.print("Selet one port from the list up:");
portName=buf.readLine();
try
{
portId=CommPortIdentifier.getPortIdentifier(portName);
try
{
serialPort=(SerialPort)portId.open("Jcomm",2000);
try
{
serialPort.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
System.out.println("Port Open Successfully!");
serialPort.close();
}
catch(UnsupportedCommOperationException e)
{
System.out.println("Port set failed!");
}
}
catch(PortInUseException e){}
}
catch(NoSuchPortException e){}
}
}
}
把上面的try欢欢位置就ok了!
import java.io.*;
import javax.comm.*;
public class Jcomm
{
static OutputStream out;
static InputStream in;
public static void main(String args[]) throws IOException
{
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
String portName;
CommPortIdentifier portId;
SerialPort serialPort;
if (ports == null)
{
System.out.println("No comm ports found!");
}
else
while(ports.hasMoreElements())
{
System.out.println(" "+ ((CommPortIdentifier) ports.nextElement()).getName());
System.out.print("Selet one port from the list up:");
portName=buf.readLine();
try
{
portId=CommPortIdentifier.getPortIdentifier(portName);
try
{
serialPort=(SerialPort)portId.open("Jcomm",2000);
try
{
serialPort.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
System.out.println("Port Open Successfully!");
serialPort.close();
}
catch(UnsupportedCommOperationException e)
{
System.out.println("Port set failed!");
}
}
catch(PortInUseException e){}
}
catch(NoSuchPortException e){}
}
}
}
把上面的try欢欢位置就ok了!
相关文章推荐
- Laravel 部署安装到虚拟主机的方法(折腾了一周,终于成功部署,原来是虚拟机不加载.env,谢谢莫回首http://lxl520.com/index.php/archives/88/!)
- 今天终于申请成功了!
- 今天终于将seu-spark编译成功
- 呵呵今天终于把Discuz的通行证给搞定了!高兴嗯~
- 最近N95掉了,郁闷,还好整了个山寨,通过多方软件,终于把MTK刷得成功了,比以前的N95还安逸呵呵
- MySQL主从复制与读写分离在windows系统下的实现(amoeba3.0+mysql5.1实现)因版本问题,本文在原来文章基础上有更改并且本人已经测试成功
- 今天终于将第一个 Android NDK 程序编译、运行成功
- 三天了!今天终于成功安装ArcIMS9.2!
- 今天,终于成功注册了blog
- 今天终于面视成功了
- 今天终于将第一个 Android NDK 程序编译、运行成功
- 早就想收录的一编文章了,呵呵,今天终于收录进来了!
- 呵呵,今天原来是愚人节,可惜放假,无人可愚。
- [Android]今天终于编译sample hello-jni成功了。
- 呵呵,我今天才发现原来DOS命令界面是可以有我最爱的Consolas字体的
- 今天安装SPS,终于在第二次成功~~
- 今天终于在wamp环境下将Zend Optimizer安装成功了
- 再谈关于我原来写的一篇博文《终于成功安装了 SigmaTel High Definition Audio CODEC 驱动》
- 呵呵! 今天终于开通了。
- 今天终于申请成功了