Error while opening port in Java

Posted by Deepak on Stack Overflow See other posts from Stack Overflow or by Deepak
Published on 2011-03-20T16:05:29Z Indexed on 2011/03/20 16:09 UTC
Read the original article Hit count: 325

Filed under:
|

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.out.println ("  " + owner_name);
      }
 }

} //main } // PortListOpen`

© Stack Overflow or respective owner

Related posts about java

Related posts about serial-port