开发者

Error while opening port in Java

I am getting the following error while trying to open the cash drawer.

Error loading win32com: java.lang.UnsatisfiedLinkError: C:\Program Files\Java\jdk1.6.0_15\jre\bin\win32com.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform

The code i am using is as follows

import javax.comm.*;  
import java.util.*;    
/** Check each port to see if it is open. **/  
public class openPort {  

  public static void main (String [] args) {  
      Enumeration port_list = CommPortIdentifier.getPortIdentifiers ();

      while (port_list.hasMoreElements ()) {
          // Get the list of ports
          CommPortIdentifier port_id =
                  (CommPortIdentifier) port_list.nextElement ();

          // Find each ports type and name
          if (port_id.getPortType () == CommPortIdentifier.PORT_SERIAL)
          {
              System.out.println ("Serial port: " + port_id.getName ());
          }
          else if (port_id.getPortType () == CommPortIdentifier.PORT_PARALLEL)
          {
              System.out.println ("Parallel port: " + port_id.getName ());
          } else
              System.out.println ("Other port: " + port_id.getName ());

          // Attempt to open it
          try {
              CommPort port = port_id.open ("PortListOpen",20);
              System.out.println ("  Opened successfully");
              port.close ();
          }
          catch  (PortInUseException pe)
          {
              System.out.println ("  Open failed");
              String owner_name = port_id.getCurrentOwner ();
              if (owner_name == null)
                  System.out.println ("  Port Owned by unidentified app");
              else
                  // The owner name not returned correctly unless it is
                  // a Java program.
                  System.ou开发者_如何学JAVAt.println ("  " + owner_name);
          }
     }
  } //main
} // PortListOpen


The error clearly saying that your dll is 32 bit. JVM should be 32 bit also.


As stated previously, the Java Communications API you are using (2.0, not current 3.0 that is not implementation available for Windows) is for Windows 32bit, so the win32com.dll must be used with a 32bit JRE/JDK, not a 64bit JRE/JDK. Try using the JDK 1.6.0_15 32 bit version.


Seems like you use a 32bit JDK on a 64bit platform. Try a 64bit JDK! Or if available, install the 64bit version of the API.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜