请老大指点

解决方案 »

  1.   

    一 你要自己去找串口编程的资料,写一个串口通信的程序;二 打开串口以后,设置显示来电模式--即写入如下命令:
    AT+CLIP=1\r三 写一个线程,不断的读取数据,当有来电的时候,串口会自动返回如下形式的字符串:
    +CLIP: "01012345678",129四 你只需要判断如果字符串以“+CLIP”开头,读取双引号中间的字符串即可。祝你好运~!
      

  2.   

    谢谢,但我完全不懂,java有一个jtapi的东东,但是我不会用,不知道是不是就是你所讲的那样啊
      

  3.   

    java comm用sun的java.comm.jar即可,网上很多。
    给你一个例子:
    import javax.comm.*;
    ....        System.setSecurityManager(null);
            CommDriver commDriver;
            try {
                commDriver = (CommDriver) Class.forName("com.sun.comm.Win32Driver").
                             newInstance();
                commDriver.initialize();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }        while (true) {
                try {
                    comm = CommPortIdentifier.getPortIdentifier("COM" + port);
                    serialPort = (SerialPort) comm.open("Serial Communication",
                            2000);
                    is = serialPort.getInputStream();
                    os = serialPort.getOutputStream();
                    read = new BufferedReader(new InputStreamReader(is));
                    serialPort.setSerialPortParams(portSpeeed,
                                                   SerialPort.DATABITS_8,
                                                   SerialPort.STOPBITS_1,
                                                   SerialPort.PARITY_NONE);
                    System.out.println("串口打开成功。");
                    break ;
                } catch (Exception e) {
                    System.out.println("串口初始化失败。正在重试...\n");
                    e.printStackTrace();
                    try {
                        Thread.sleep(2000);
                    } catch (Exception ee) {}
    System.exit(1);
                }
            }
            status = this.STATUS_SERIALREAD;
            command("AT+CLIP=1\r"); //设置为工作模式
    ...//写指令函数
        public void command(String msg) {
            msg = msg.toUpperCase();
            try {
                for (int i = 0; i < msg.length(); i++) {
                    os.write(msg.charAt(i));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    //读串口
    //这个就从is读取即可,自己去实现吧。不能再多写了,再多写你就没的写了,呵呵。