怎么可能读不到数据呢?
你试试comm包的那些例子程序好了,我就是参考那些例子来做的,
程序都是没有问题的.
你试试comm包的那些例子程序好了,我就是参考那些例子来做的,
程序都是没有问题的.
解决方案 »
- 我刚装了jdk7.0,用了com.sun.awt.AWTUtilities包,我用exe4j还可以把他转换成exe运行程序吗?
- 我在同一个package里定义了两个application Window,分别是s和a。我现在在s中定义一个按钮,想点击这个按钮后,a就显示,是怎么弄的啊,谢谢
- 急啊,TOMCAT里的域名设置
- 定义和使用抽象类,调用不到age这个方法!信息显示有误!望指点
- netbeans4.0的中文问题
- 菜鸟提问CardLayout的奇怪问题。。。。
- 基础知识!一个关于数组的问题!!
- 为什么我不能在JCreator3.5下调试程序?
- 外网机器如何与局域网内机器通信????????急!!!!在线等待!!!!
- 分离下面的字符串的方法?
- 大家好,今天做游戏,遇到JAVA的编程问题,不懂不懂,请大家帮我!
- 怎样判断输入的字符串是否是“YYYY-MM-DD”格式的?
import java.util.*;
import javax.comm.*;public class Dial_up implements SerialPortEventListener{
static Enumeration portList;
static CommPortIdentifier portId;
static String messageString = "Hello, world!\n";
static SerialPort serialPort;
static OutputStream outputStream;
static InputStream inputStream; public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers(); while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM1")) {
//if (portId.getName().equals("/dev/term/a")) {
try {
serialPort = (SerialPort)
portId.open("SimpleWriteApp", 2000);
} catch (PortInUseException e) {} try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {} try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {} try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {} try {
serialPort.addEventListener(new SerialListener1());
} catch (TooManyListenersException e) {}
serialPort.notifyOnDataAvailable(true); try {
outputStream.write(messageString.getBytes());
} catch (IOException e) {}
}
}//end of if COM1
}//end of while
}//end of main public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[20]; try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
System.out.print(new String(readBuffer));
} catch (IOException e) {}
break;
}
}
}//end of class