好象要使用JAVA的一个什么包,具体不记得了

解决方案 »

  1.   

    呵呵,实在不行,就调用本地接口,用C来实现,java中确实不知道。
      

  2.   

    package javax.comm.*
    可以到java.sun.com寻找。里面有一些Demo.看看那个BlackBox就可以了。
      

  3.   

    http://dev-club.ccw.com.cn/club/bbs/showEssence.asp?id=17588&page=1
    记得IBM的DW上面也有个文章.
      

  4.   

    我正在做这方面的程序,基本的功能都能用JAVA实现,如用数据猫发送数据,从数据猫读接收到的消息等。但是还有一些问题,希望我们多交流。下面的程序供参考,在JBuider 5.0调试通过import java.io.*;
    import javax.comm.*;
    import java.util.*;
    public class test  {
      private SerialPort sPort=null;
      public static boolean lock=false;
      public test() {
       //sPort=setSerialPort();  }   //得到计算机的串口
      public   SerialPort getSerialPort(String com)
      {
         SerialPort sPort=null;
         CommPortIdentifier portID;
         String owner=new String("modemn");
         int keeptime=1000;
         Enumeration portList;
         portList=CommPortIdentifier.getPortIdentifiers();   while(portList.hasMoreElements())
        {
         portID=(CommPortIdentifier)portList.nextElement();
         if(portID.getName().equals(com))
           try{sPort=(SerialPort)portID.open(owner,keeptime);}
              catch(PortInUseException e){System.out.println(e.getMessage());}    }    System.out.println("serial name is :"+sPort.getName());
        try{
          //设置串口的参数
          sPort.setSerialPortParams(9600,//波特率
                     SerialPort.DATABITS_8,//数据位数
                    SerialPort.STOPBITS_1, //停止位
                    SerialPort.PARITY_NONE);//奇偶位
        }catch (UnsupportedCommOperationException e) {System.out.println(e.getMessage());}    int baudrate=sPort.getBaudRate();
         int databits=sPort.DATABITS_8;
          int parity=sPort.getParity();
       int stopbits=sPort.getStopBits();
        int flowcontrolMode=sPort.getFlowControlMode();
       System.out.println("baudrate:"+baudrate);
       System.out.println("databits:"+databits);
       System.out.println("parity:"+parity);
       System.out.println("stopbits:"+stopbits);
       System.out.println("flow control mode is:"+flowcontrolMode);  return sPort;
       }
      public static void main(String[] args)
       {test t=new test();
        SerialPort sPort=t.getSerialPort("COM1");
        //SerialPort sPort2=t.getSerialPort("COM2");    new sendCmd(sPort).start();
        //new receiveCmd(sPort).start();
        //new delCmd(sPort).start();
        }}*********************************************************
    public class sendCmd extends Thread implements SerialPortEventListener {  SerialPort sPort=null;
      BufferedReader br=null;
      public sendCmd(SerialPort sPort) {
        this.sPort=sPort;
        //this.setPriority(10);
      }  public  void send(SerialPort sPort)
       {
         String cmd1="AT+CMGS=\"+8613939060564\"\r hello";
         cmd1+=(char)(Integer.parseInt("1a",16))+"z";//用ctrl-z表示结束并发送
         String cmd2="AT+CMGL=\"REC UNREAD\"";
         String cmd3="AT+CMGL=\"ALL\"";
         PrintWriter pw=null;    try{
           pw=new PrintWriter(sPort.getOutputStream());
           pw.println(cmd1);
           pw.flush();
           pw.close();
           System.out.println("command has been send");
           br=new BufferedReader(new InputStreamReader(sPort.getInputStream()));       sPort.addEventListener(this);
           sPort.notifyOnDataAvailable(true);
         } catch(IOException e){System.out.println("catch exception when send cmd to modemn");
                         System.out.println(e.getMessage());}
         catch(TooManyListenersException e){}
       }   public void run()
       {
        send(sPort);
           
         }
      public synchronized void serialEvent(SerialPortEvent ev)
       {
       if(ev.getEventType()==ev.DATA_AVAILABLE)
         try{
          while(true)
          {
           String msg= br.readLine();
           System.out.println("response is:"+msg);
           //if(msg.equals("OK"))
           //{
            // br.close();
            // break;
           //  }//if
           }//while
         }//try
          catch(IOException e){}
        }
    }