我正在开发一个 Java 应用程序来获取电话号码。我正在使用 USRobotics 5639 调制解调器(支持来电显示),并且我的电话公司确实提供来电显示服务。当我使用超级终端时,我得到了呼叫的号码、时间和日期:
https
://imgur.com/wwwRHa7但是当我尝试在我的应用程序中做同样的事情时,我只得到以下信息:
ATZ
OK
AT+VCID= 1
OK
这就是我目前所拥有的:
import gnu.io.CommPortIdentifier;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import gnu.io.UnsupportedCommOperationException;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
public class Rxtx
{
static CommPortIdentifier portId;
static CommPortIdentifier saveportId;
static Enumeration portList;
static InputStream inputStream;
static OutputStream outputStream;
static BufferedInputStream bufferedInputStream;
static SerialPort serialPort;
public static void main(String[] args)
{
boolean gotPort = false;
String port;
portList = CommPortIdentifier.getPortIdentifiers();
String feedback = null;
String data = null;
while(portList.hasMoreElements())
{
portId = (CommPortIdentifier) portList.nextElement();
if(portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
{
if(portId.getName().equals("COM5"))
{
port = portId.getName();
gotPort = true;
}
if(gotPort == true)
{
try
{
serialPort = (SerialPort)portId.open("Pruebas", 2000);
}
catch(PortInUseException ex)
{
ex.printStackTrace();
}
try
{
outputStream = serialPort.getOutputStream();
}
catch(IOException ex)
{
ex.printStackTrace();
}
try
{
serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
}
catch(UnsupportedCommOperationException ex)
{
ex.printStackTrace();
}
try
{
inputStream = serialPort.getInputStream();
bufferedInputStream = new BufferedInputStream(inputStream);
}
catch(IOException e)
{
e.printStackTrace();
}
serialPort.notifyOnDataAvailable(true);
}
}
}
try
{
if(!(outputStream == null))
{
String serialMessage = "ATZ\r\n";
OutputStream outstream = serialPort.getOutputStream();
outstream.write(serialMessage.getBytes());
String comando = "AT+VCID=1\r\n";
OutputStream os = serialPort.getOutputStream();
os.write(comando.getBytes());
byte[] readBuffer = new byte[1024];
boolean read = false;
while(!read)
{
try
{
String getInfo = "";
Thread.sleep(100);
while(bufferedInputStream.available() > 0)
{
int numBytes = bufferedInputStream.read(readBuffer);
getInfo += new String(readBuffer);
read = true;
data = data + new String(readBuffer, 0, numBytes);
data = data.trim();
}
feedback += getInfo;
int length = getInfo.length();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
System.out.println("data: " + data);
}
}
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
我缺少什么来获取主叫号码的所有信息?