下面是我写的源程序。该脚本想实现往LPT1并口发送数据,LPT1并口连接着条码打印机。
目前的运行状况是不报错,而且并口也连接上,现在就是不知道,为什么并口接收不到我发的数据。
import   java.io.*;
import   java.util.*;
import   javax.comm.*;class   SendCom
{   static   CommPortIdentifier   portId;
   static   OutputStream   out;
   static   ParallelPort   serialPort;   public   static   void   main(String[]   args)
  {     try
    {
       //连接LPT1口
       String   driverName   =   "com.sun.comm.Win32Driver";   
       CommDriver   driver   =   null;   
       System.loadLibrary("win32com");   
       driver   =   (CommDriver)Class.forName(driverName).newInstance();   
       driver.initialize();   
   
       serialPort = (ParallelPort)driver.getCommPort("LPT1", javax.comm.CommPortIdentifier.PORT_PARALLEL); 
       System.out.println( serialPort.getName() );       try
       {  
     out = serialPort.getOutputStream();  
       }
       catch(IOException   e)
      {
     e.printStackTrace();
     System.out.println(e.getMessage());
      }      try
      {
//往并口发送 Msg的字符串。
   String Msg = "N" + "\r" + "A50,30,0,4,1,1,N,'材料名称'" + "\r" + "A100,30,0,4,1,1,N,'型号规格'" + "\r" + "A150,30,0,4,1,1,N,'2007年' " + "\r" + " B10,10,0,3,3,7,200,B,'000000000012'" + "\r" + "P1" + "\r";
   for (int i = 0; i < Msg.length(); i++)
   {
      out.write( Msg.charAt(i) );
   }                   
      }
      catch( Exception e )
     {
   System.out.println(e.getMessage());
     }
  }
  catch( Exception   e )
  {
    System.out.println(e.getMessage());
  }
}
}

解决方案 »

  1.   

    顶一个,我的问题更严重,我想用java调用modem拔号,使用jb2006+jdk1.6+xtapi.可是一直报错:****************************************************************************
    Java Communications API - Early Access
    Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
    ****************************************************************************