weixin_42401763 2010-10-20 14:22
浏览 391
已采纳

JAVA串口编程 如何通过USB接口来电显示盒实现来电显示

开发工具 myeclipse 7.0   JDK6.0   JRE6.0   USB来电显示盒一个   电话机一台(未开通来电显示)

操作系统:wimdows xp

我想知道来电显示可以通过自己截取MODEL信号来实现吗?

如果能,该怎么实现,我在网上找过一个比较正规的例子(下面有介绍),但是结果不行。

我按照里面的测试,超级终端开启不了,这个又改怎么解决。

具体并且详细的超级终端测试步骤应该是怎么样的?


我现在的测试步骤是这样的
------------------------------
链接上来电显示盒---->安装好驱动文件------>链接好TEL1线与LINE1线--->打开超级终端-->输入名称(确定)-->不修改在确定-->不修改继续确定-->修改一下(ASCII码设置里面的本地回显键入的字符)-->输入at按回车或者CTRL+H-->等半天没有网上说的OK出现。
------------------------------


测试串口我用的是COMM.JAR包。


我现在的串口代码是这么写的。我不是很明白其中的意思。也测试不懂。希望高手能够详细的解答一下JAVA实现来电弹屏的原理。

另外如果实现难度特别大,有没有一些二次开发的。二次开发也请帮忙简单介绍一下。

这是网上找的例子,但是报错了。

 

package comm;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.TooManyListenersException;

import javax.comm.CommDriver;
import javax.comm.CommPortIdentifier;
import javax.comm.PortInUseException;
import javax.comm.SerialPort;
import javax.comm.SerialPortEvent;
import javax.comm.SerialPortEventListener;
import javax.comm.UnsupportedCommOperationException;
import javax.swing.JApplet;

/**
 *
 * 项目名称:PhoneTest
 * 类名称:SimpleWrite
 * 类描述:
 * 创建人:彭**
 * 创建时间:2010-10-19下午02:33:57
 * 修改人:彭**
 * 修改时间:2010-10-19下午02:33:57
 * 修改备注:
 * @version  V1.0
 */
public class SimpleWrite {
    static { System.setSecurityManager(null); }

    public static void main(String[] args) {   
        // System.loadLibrary("win32com");   
        CommDriver driver = null;   
        String driverName = "com.sun.comm.Win32Driver";   
        // SerialPort sPort = (SerialPort) driver.getCommPort("COM4",   
        // CommPortIdentifier.PORT_SERIAL);   
        Enumeration<CommPortIdentifier> enumeration = CommPortIdentifier   
                .getPortIdentifiers();   
        while (enumeration.hasMoreElements()) {   
            CommPortIdentifier portId = enumeration.nextElement();   
            System.out.println(portId.getName() + "============");   
            if (portId.getName().equals("COM1")) {   
                try {   
                    System.out.println("jjj");   
                    final SerialPort sp = (SerialPort) portId.open(   
                            "SimpleWrite", 1000);   
                    sp.setSerialPortParams(2400, SerialPort.DATABITS_8,   
                            SerialPort.STOPBITS_2, SerialPort.PARITY_NONE);   
                    final InputStream is = sp.getInputStream();   
                    final OutputStream os = sp.getOutputStream();   
                    os.write(100);   
                    os.flush();   
                    os.close();   
                    //Set notifyOnDataAvailable to true to allow event driven input.      
                    sp.notifyOnDataAvailable(true);
                    // Set notifyOnBreakInterrup to allow event driven break   
                    // handling.   
                    sp.notifyOnBreakInterrupt(true);
                    // Set receive timeout to allow breaking out of polling loop   
                    // during input handling.   
                    sp.enableReceiveTimeout(30);
                    final StringBuffer linkWgt = new StringBuffer();// 存放获取的数据   
                    sp.addEventListener(new SerialPortEventListener() {
                        public void serialEvent(SerialPortEvent e) {
                            int newData = 0;
                            // Determine type of event.   
                            switch (e.getEventType()) {
                            // Read data until -1 is returned. If \r is received   
                            // substitute   
                            // \n for correct newline handling.   
                            case SerialPortEvent.DATA_AVAILABLE:
                                while (newData != -1) {
                                    try {   
                                        newData = is.read();   
                                        if (newData == -1) {
                                            break;   
                                        }   
                                        if ('\r' == (char) newData) {
                                        } else {   
                                            linkWgt.append((char) newData);   
                                        }   
                                    } catch (IOException ex) {   
                                        System.err.println(ex);   
                                        return;   
                                    }   
                                }   
  
                                // Append received data to messageAreaIn.   
  
                                try {   
                                    System.out   
                                            .println("linkWgt ---------|||||          "  
                                                    + Double.valueOf(linkWgt   
                                                            .toString()));   
  
                                } catch (Exception ew) {   
                                    ew.printStackTrace();   
                                } finally {   
                                    try {   
                                        // 用完了,记得关闭端口。   
                                        is.close();   
                                        sp.close();   
                                    } catch (Exception c) {   
                                        c.printStackTrace();   
                                    }   
                                }   
                                break;   
                            // If break event append BREAK RECEIVED message.   
                            case SerialPortEvent.BI:   
                                System.out   
                                        .println("\n--- BREAK RECEIVED ---\n");   
                            }   
                        }   
                    });   
                } catch (PortInUseException e) {   
                    e.printStackTrace();   
                } catch (UnsupportedCommOperationException e) {   
                    e.printStackTrace();   
                } catch (IOException e) {   
                    e.printStackTrace();   
                } catch (TooManyListenersException e) {   
                    e.printStackTrace();   
                }   
            }   
        }   
    }   
}

 

 这个是报的错误

Caught java.lang.ClassNotFoundException: com.sun.comm.Win32Driver while loading
driver com.sun.comm.Win32Driver
Error loading SolarisSerial: java.lang.UnsatisfiedLinkError: no SolarisSerialPar
allel in java.library.path
Caught java.lang.UnsatisfiedLinkError: com.sun.comm.SolarisDriver.readRegistrySe
rial(Ljava/util/Vector;Ljava/lang/String;)I while loading driver com.sun.comm.So
larisDriver


 

从错误的名称来看是这样的,但是comm.jar包我已经放进去了。并且放在了任何可能需要的地方。

-------------------
comm.jar可以放在JDK中的jre\lib\ext目录下
win32com.dll可以直接放在JDK中的bin目录下
javax.comm.properties放在JDK中的jre\lib目录下就可以。
-------------------

 

 

 还有一个非常重要的疑问,JAVA能够实现截取USB来电显示盒信息实现来电显示吗?

 

  • 写回答

2条回答

  • iteye_3976 2010-10-22 17:23
    关注

    我们公司也在做这个,首先你应该用录音盒或者语音盒,而不是普通的来电显示盒

    要看厂家有没有提供给你接口的,有了接口才能获取的到

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器