Java 为什么我的计算机的状态是';当我的手机调制解调器正在使用时,它的COM4端口可用吗?
这是我的密码:Java 为什么我的计算机的状态是';当我的手机调制解调器正在使用时,它的COM4端口可用吗?,java,serial-port,javax.comm,Java,Serial Port,Javax.comm,这是我的密码: import java.io.*; import java.util.*; import javax.comm.*; public class SMS { public static void main(String[] args) { Enumeration lists=CommPortIdentifier.getPortIdentifiers(); System.out.println(CommPortIdenti
import java.io.*;
import java.util.*;
import javax.comm.*;
public class SMS {
public static void main(String[] args) {
Enumeration lists=CommPortIdentifier.getPortIdentifiers();
System.out.println(CommPortIdentifier.PORT_SERIAL);
System.out.println(lists.hasMoreElements());
while (lists.hasMoreElements()){
CommPortIdentifier cn=(CommPortIdentifier)lists.nextElement();
if ((CommPortIdentifier.PORT_SERIAL==cn.getPortType())){
System.out.println("Name is serail port "+cn.getName()+" Owned status "+cn.isCurrentlyOwned());
try{
SerialPort port1=(SerialPort)cn.open("ComControl",800000);
port1.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
System.out.println("Before get stream");
OutputStream out=port1.getOutputStream();
InputStream input=port1.getInputStream();
System.out.println("Before write");
out.write("AT".getBytes());
System.out.println("After write");
int sample=0;
//while((( sample=input.read())!=-1)){
System.out.println("Before read");
//System.out.println(input.read() + "Testing ");
//}
System.out.println("After read");
System.out.println("Receive timeout is "+port1.getReceiveTimeout());
}catch(Exception e){
System.err.println(e.getMessage());
}
}
else{
System.out.println("Name is parallel port "+cn.getName()+" Owned status "+cn.isCurrentlyOwned()+cn.getPortType()+" ");
}
}
}
}
这是输出:
1
true
Name is serail port COM1 Owned status false
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is serail port COM2 Owned status false
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is serail port COM3 Owned status false
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is serail port COM4 Owned status false
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is parallel port LPT1 Owned status false2
Name is parallel port LPT2 Owned status false2
1.
真的
名称为serail端口COM1拥有状态false
在得到流之前
写之前
写完后
阅读前
读完
接收超时为-1
名称为serail端口COM2所有状态为false
在得到流之前
写之前
写完后
阅读前
读完
接收超时为-1
名称为serail端口COM3所有状态为false
在得到流之前
写之前
写完后
阅读前
读完
接收超时为-1
名称为serail端口COM4拥有状态为false
在得到流之前
写之前
写完后
阅读前
读完
接收超时为-1
名称为并行端口LPT1拥有状态2
名称为并口LPT2所有状态2
我的手机调制解调器正在使用我的COM4端口,但根据代码,它的状态是免费的。
代码中是否有我遗漏的内容?我如何才能将其整理出来?可能是控制手机的软件处于睡眠模式,或者类似的情况