Página 1 de 1

Interface Java porta paralela

MensagemEnviado: 17 Abr 2007 13:23
por Meca
Olá passoal, tudo bem? espero q sim. estou tendo q fazer um projeto p/ a faculdade em JAVA e estou tentando usar a porta paralela p/ aciona uma placa leds, já tenho o programa, já instalei a API javax.comm e na hora de rodar o programa esta aparecendo alguns erro e não acontece na na placa led, segue-se abaixo o programa.

java code
import parport.ParallelPort;
import java.awt.*;
import java.io.*;
import javax.comm.*;


class SimpleIO {

public static void main (String[] args){
int Bit = 1;
ParallelPort Lpt1 = new ParallelPort(0x378);
Lpt1.write(Bit);
}
}


package parport;

public class ParallelPort {

/** The port base address (e.g. 0x378 is base address for LPT1) */
private int portBase;

/** To cunstruct a ParallelPort object,
* you need the port base address
*/
public ParallelPort (int portBase)
{
this.portBase = portBase;
}

/** Reads one byte from the STATUS pins of the parallel port.
*
* The byte read contains 5 valid bits, corresponing to 5 pins of input
* from the STATUS pins of the parallel port (the STATUS is located
* at "portBase + 1", e.g. the STATUS address for LPT1 is 0x379).
*
* This diagram shows the content of the byte:
*
* Bit | Pin # | Printer Status | Inverted
* -----+-------+-----------------+-----------
* 7 | ~11 | Busy | Yes
* 6 | 10 | Acknowledge |
* 5 | 12 | Out of paper |
* 4 | 13 | Selected |
* 3 | 15 | I/O error |
*
* Note that Pin 11 is inverted, this means that "Hi" input on pin
* means 0 on bit 7, "Low" input on pin means 1 on bit 7.
*/
public int read ()
{
return ParallelPort.readOneByte (this.portBase+1);
}

/** Writes one byte to the DATA pins of parallel port.
* The byte is written to the DATA pins of the port. The DATA pins are
* located at the base address of the port (e.g. DATA address for LPT1
* is 0x378).
*
* This diagram shows how the byte is written:
*
* Bit | Pin # | Printer DATA
* -----+-------+--------------
* 7 | 9 | DATA 7
* 6 | 8 | DATA 6
* 5 | 7 | DATA 5
* 4 | 6 | DATA 4
* 3 | 5 | DATA 3
* 2 | 4 | DATA 2
* 1 | 3 | DATA 1
* 0 | 2 | DATA 0
*/
public void write (int oneByte)
{
ParallelPort.writeOneByte (this.portBase, oneByte);
}

/** Reads one byte from the specified address.
* (normally the address is the STATUS pins of the port)
*/
public static native int readOneByte (int address);

/** Writes one byte to the specified address
* (normally the address is the DATA pins of the port)
*/
public static native void writeOneByte (int address, int oneByte);

static
{
System.loadLibrary("parport");
}
}


O erro q esta aparecendo é esse aqui:

init:
deps-jar:
Compiling 2 source files to C:\Documents and Settings\ExercicioJava\SimpleIO\build\classes
compile:
run:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no parport in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:992)
at parport.ParallelPort.<clinit>(ParallelPort.java:75)
at SimpleIO.main(Main.java:12)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)


bem espero q alguém possa me indicar um caminho pois não sei mais por onde ir nesse projetinho, Ah estou usando o NetBeans e windows XP.

Desde de já agradeço a atenção de todos, MECA.

MensagemEnviado: 17 Abr 2007 15:46
por ivan
O path pra esta lib(static "{System.loadLibrary("parport"); } ) está correto? Ela existe? Por estar no Windows XP ela deve ser uma dll!

1) Por ser um bloco "static" este é executado no momento de carga da Classe ParallelPort, e como a compilação está OK... então:
run:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no parport in java.library.path.
Erro de linkagem dinâmica.

2) O trecho de codigo abaixo declara métodos nativos que devem estar na library parport:
/** Reads one byte from the specified address.
* (normally the address is the STATUS pins of the port)
*/
public static native int readOneByte (int address);

/** Writes one byte to the specified address
* (normally the address is the DATA pins of the port)
*/
public static native void writeOneByte (int address, int oneByte);

Isto se chama JNI(Java Native Interface). Dê uma olhada nesta spec q talvez vc msm consiga solucionar o erro, ou pelo menos deve esclarecer um pouco mais as suas dúvidas.

MensagemEnviado: 17 Abr 2007 23:52
por Meca
Obrigado Ivan vou ferificar o JNI e vamos ver quais avanços conseguirei, ah e o parport é uma dll sim e instalei tudo conforme o artigo q peguei na net, q é esse site http://www.geocities.com/Juanga69/parport/. desde de já agradeço a ajuda e depois postarei os resultados e todo fonte do programa caso alguêm queira aproveitar tbm, isso é se funcionar, obrigado pela ajuda, já esclareceu bastante coisa p/ mim.

Abraçãos e até mais, Meca.

MensagemEnviado: 19 Abr 2007 10:56
por ivan
Meca,

Estive olhando o site indicado por vc e percebi q no seu caso (Windows XP) é necessário a instalação do UserPort tb. Vc já fez isso?

MensagemEnviado: 19 Abr 2007 22:02
por Meca
Já fiz isso sim Ivan estou achando q pode ser o meu java por q tinha duas versões instaladas no meu micro, vou desistalar tudo e instalar apenas a versão 5.5 do NetBeans e a versão 1.6.0 do JAVA, e obrigado pela ajuda mais uma vez IVAN, abração.

Infelizmente nada feito

MensagemEnviado: 10 Mai 2007 01:17
por Meca
Bem conforme havia prometido estou voltando p/ informar q não consegui fazer o acionamento da porta paralela, tendo em vista eu precisava apresentar um projeto em Java na faculdade acabei mudando o projeto e não utilizei a PP, mais pretendo retorma esse trabalho logo mais, e tbm agradeço a todos pela ajuda, muito obrigado e até mais pessoal, fui.

Rog Meca.

MensagemEnviado: 19 Dez 2007 23:21
por chipselect
boa noite Meca

meio tarde pra postar, mas se for tentar mais uma vez, veja se consegue utilizar a RXTX (rxtx.org)...

no meu caso, a dll eu coloquei no system32 do windows pra funcionar direito...

MensagemEnviado: 05 Jan 2008 18:08
por Meca
Obrigado pela dica Chipselect, apesar de eu ter deixado de lado já esse projetinho devido a necesidade de entregar um projeto d JAVA na facul, sua ajuda foi util, acho q vou tentar fazer uns testes depois, mesmo assim agradeço muito pela atenção e ajuda, FELIZ 2008 p/ vc e para todos do ASM51.

Obrigado pessoal