在 Java 中打开端口时出错
我在尝试打开现金抽屉时收到以下错误。
加载 win32com 时出错:java.lang.UnsatisfiedLinkError:C:\Program Files\Java\jdk1.6.0_15\jre\bin\win32com.dll:无法在 AMD 64 位上加载 IA 32 位 .dll platform
我正在使用的代码如下
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该错误清楚地表明您的 dll 是 32 位的。 JVM 也应该是 32 位的。
The error clearly saying that your dll is 32 bit. JVM should be 32 bit also.
如前所述,您正在使用的 Java Communications API (2.0 (不是当前的 3.0,不适用于 Windows)适用于 Windows 32 位,因此 win32com.dll 必须与 32 位 JRE/JDK 一起使用,而不是与 64 位 JRE/JDK 一起使用。尝试使用 JDK 1.6.0_15 32 位版本。
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.
看起来你在 64 位平台上使用 32 位 JDK。尝试 64 位 JDK!或者,如果可用,请安装 64 位版本的 API。
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.