Good afternoon, I was given a code that connects a scale with java through the serial port and I already imported all the libraries that the program needs, specifically the serialPort.jar library with its libSerialPort.dll library
When following the sequence of the program, I get an error of
link Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\Development\Documents\NetBeansProjects\pesar\libSerialPort.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
I leave the code below consists of three files which are:
-Setting
package Controlador;
public class Configuracion {
private final String archivo = "Configuracion.txt";//Archivo de donde se sacaran los datos de configuracion
private String PuertoCOM;
private int Delay;
private boolean OcultarConsola;
private String ultimoCaracter;
private String PuertoSerial;
private String url;
private String caracterSolicitud;
private String impresora;
private boolean MandarCaracterPeticion;
public void CargarConfiguracion() {
PuertoCOM = this.obtenerValorParametro("Puerto");
if(PuertoCOM.equals("")){
System.out.println("Error al leer el valor Puerto, se asignarán valores predeterminados");
PuertoCOM = "COM1";
}
PuertoSerial = this.obtenerValorParametro("Serial");
if(PuertoSerial.equals("")){
System.out.println("Error al leer el valor Serial, se asignarán valores predeterminados");
PuertoSerial = "9600";
}
try{
Delay = Integer.parseInt(this.obtenerValorParametro("Delay"));
}catch(NumberFormatException e){
System.out.println("Error al leer el valor Delay, se asignarán valores predeterminados");
Delay = 10;
}
ultimoCaracter = this.obtenerValorParametro("UltimoCaracter");
if(ultimoCaracter.equals("")){
System.out.println("Error al leer el valor UltimoCaracter, se asignarán valores predeterminados");
ultimoCaracter = "R";
}
url = this.obtenerValorParametro("URL");
if(url.equals("")){
System.out.println("Error al leer el valor UltimoCaracter, se asignarán valores predeterminados");
url = "http://localhost/RegistroPesajeWS";
}
impresora = this.obtenerValorParametro("Impresora");
if(impresora.equals("")){
System.out.println("Error al leer el valor Impresora, se asignarán valores predeterminados");
impresora = "EPSON";
}
caracterSolicitud = this.obtenerValorParametro("CaracterPeticion");
if(caracterSolicitud.equals("")){
System.out.println("Error al leer el valor caracterSolicitud, se asignarán valores predeterminados");
caracterSolicitud = "P";
}
OcultarConsola = (this.obtenerValorParametro("OcultarConsola").equals("1"));
MandarCaracterPeticion = (this.obtenerValorParametro("MandarCaracterPeticion").equals("1"));
}
private String obtenerValorParametro(String parametro){
String valor = "";
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader(this.archivo));
while ((sCurrentLine = br.readLine()) != null) {
if(sCurrentLine.contains(parametro + ":")){//Cuando se encuentra el parametro a buscar
int indice = sCurrentLine.indexOf(parametro+":");//Se obtiene el indice donde empieza el texto del parametro
int lengthParametro = parametro.length()+1;//Se obtiene la longitud en caracteres del parametro
valor = sCurrentLine.substring(indice+lengthParametro);
//System.out.println("El valor debería de ser: "+valor);
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null) {
br.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return valor;
}
public String getPuertoCOM() {
return PuertoCOM;
}
public int getDelay() {
return Delay;
}
public boolean isOcultarConsola() {
return OcultarConsola;
}
public String getPuertoSerial() {
return PuertoSerial;
}
public String getUltimoCaracter() {
return ultimoCaracter;
}
public void setUltimoCaracter(String ultimoCaracter) {
this.ultimoCaracter = ultimoCaracter;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getCaracterSolicitud() {
return caracterSolicitud;
}
public void setCaracterSolicitud(String caracterSolicitud) {
this.caracterSolicitud = caracterSolicitud;
}
public String getImpresora() {
return impresora;
}
public void setImpresora(String impresora) {
this.impresora = impresora;
}
public boolean isMandarCaracterPeticion() {
return MandarCaracterPeticion;
}
public void setMandarCaracterPeticion(boolean MandarCaracterPeticion) {
this.MandarCaracterPeticion = MandarCaracterPeticion;
}
}
-Request data Data
private final Enviar_datos enviar;
private Configuracion configuracion = new Configuracion();
private String puertoSerial = "";
private SerialPort puerto;
private Parameters settings;
private Com com1;
public Pedir_Datos_Bascula(Configuracion conf) {
this.configuracion = conf;
enviar = new Enviar_datos(this.configuracion);
}
public String hacerPeticionPesaje() {
try {
puerto = new SerialPort();
List<String> listaPuertos;
String recibido = "";
String caracter = "";
puertoSerial = "";
listaPuertos = puerto.getFreeSerialPort();
puertoSerial = this.configuracion.getPuertoCOM();
for (String string : listaPuertos) {//Se recorren todos los puertos
puertoSerial = string;
if (string.equals(this.configuracion.getPuertoCOM())) {//Si se encuentra el puerto marcado en la configuracion, se trabaja con este puerto
break;
}
}
settings = new Parameters();
settings.setPort(puertoSerial);
settings.setBaudRate(configuracion.getPuertoSerial());//Se asigna el puerto serial que viene en la configuracion
com1 = new Com(settings);
if (configuracion.isMandarCaracterPeticion()) {
com1.sendSingleData(configuracion.getCaracterSolicitud());
com1.sendSingleData(Character.toString((char) 13));
com1.sendSingleData(Character.toString((char) 10));
}
int contador = 0;
recibido = "";
while (!caracter.equals(configuracion.getUltimoCaracter())) {
caracter = com1.receiveSingleString();
recibido += caracter;
contador++;
if (contador > 100) {
return "";
}
}
if (!recibido.equals("")) {
//System.out.println(recibido);//cbc
String pesoNeto = recibido;
enviar.setPeso_neto(pesoNeto);
this.terminarLeerDatos();
return this.convertirPesaje(pesoNeto);
//enviar.converir_datos();
} else {
this.terminarLeerDatos();
return "";
}
} catch (Exception e) {
this.terminarLeerDatos();
System.out.println("Run: " + e);
return null;
}
}
private String convertirPesaje(String peso_neto) {
String peso = "";
for (int x = 0; x < peso_neto.length(); x++) {
if (peso_neto.charAt(x) == '0') {
peso += "0";
} else if (peso_neto.charAt(x) == '1') {
peso += "1";
} else if (peso_neto.charAt(x) == '2') {
peso += "2";
} else if (peso_neto.charAt(x) == '3') {
peso += "3";
} else if (peso_neto.charAt(x) == '4') {
peso += "4";
} else if (peso_neto.charAt(x) == '5') {
peso += "5";
} else if (peso_neto.charAt(x) == '6') {
peso += "6";
} else if (peso_neto.charAt(x) == '7') {
peso += "7";
} else if (peso_neto.charAt(x) == '8') {
peso += "8";
} else if (peso_neto.charAt(x) == '9') {
peso += "9";
} else if (peso_neto.charAt(x) == '.') {
peso += ".";
} else {
//robot.keyPress(KeyEvent.VK_9);
}
}
return peso;
}
public void terminarLeerDatos() {
try {
puerto.closePortC(puertoSerial);
com1.closePortC(puertoSerial);
//puerto.closePortC(puertoSerial);
} catch (Exception e) {
System.err.println("Error terminarLeerDatos: " + e.toString());
}
}
}
The external configuration file is a notepad file, what it brings I will put it below
Puerto:COM4
Delay:10
OcultarConsola:1
Serial:9600
UltimoCaracter:k
CaracterPeticion:P
Impresora:EPSONL355
MandarCaracterPeticion:0
When I start to follow the steps I get the error at the beginning. My question is: How can I make it run with the same file? Would I have to use another library?
What you're getting is that you're trying to load a 32-bit DLL into a 64-bit JVM. The only solution you have is to use a DLL and a JVM with the same architecture (both for 32-bit or both for 64-bit).