Parallel Port Access

D

david.brown.0

I'm trying to make a Java program access a parallel port. Java's comm
API does not provide me with the control I need. I need to be able to
write to the data and control pins and read the status pins. Any Java
people know a good solution? I'm trying to use JNI and create my own
library, but building the library gives me these errors:

ld: warning: cannot find entry symbol _start; defaulting to
0000000008048094
ParallelPort.o: In function `Java_ParallelPort_setAddress':
ParallelPort.cpp:(.text+0x96): undefined reference to `ioperm'
ParallelPort.cpp:(.text+0xaa): undefined reference to `ioperm'

Can anyone help me? Source follows.

ParallelPort.java
----------
public class ParallelPort {
static {
System.loadLibrary("ParallelPort");
}

public ParallelPort() {
setAddress(0x378); // default to lp0
}

public ParallelPort(int addr) {
setAddress(addr);
}

public native void setAddress(int addr);

public native int getAddress();

public native void sendData(int data);

public native int readStatus();

public native void sendControl(int control);
}

==========

ParallelPort.cpp
----------
#include "ParallelPort.h"
#include <jni.h>
#include <stdio.h>

#define extern static
#define REALLY_SLOW_IO
#include <asm/io.h> // port I/O
#undef extern

#include <sys/io.h> // for ioperm

jint DATA;
jint STATUS;
jint CONTROL;

JNIEXPORT void JNICALL Java_ParallelPort_setAddress(JNIEnv *env,
jobject obj,
jint addr) {
DATA = addr;
STATUS = addr + 1;
CONTROL = addr +2;

ioperm(DATA, 3, 1);
ioperm(0x80, 1, 1);
}

JNIEXPORT jint JNICALL Java_ParallelPort_getAddress(JNIEnv *env,
jobject obj) {
return DATA;
}

JNIEXPORT void JNICALL Java_ParallelPort_sendData(JNIEnv *env, jobject
obj,
jint data) {
outb(data, DATA);
}

JNIEXPORT jint JNICALL Java_ParallelPort_readStatus(JNIEnv *env,
jobject obj) {
return inb(STATUS);
}

JNIEXPORT void JNICALL Java_ParallelPort_sendControl(JNIEnv *env,
jobject obj,
jint control) {
outb(control, CONTROL);
}

==========

ParallelPort.h (Auto-generated with javah)
----------
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class ParallelPort */

#ifndef _Included_ParallelPort
#define _Included_ParallelPort
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: ParallelPort
* Method: setAddress
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_ParallelPort_setAddress
(JNIEnv *, jobject, jint);

/*
* Class: ParallelPort
* Method: getAddress
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_ParallelPort_getAddress
(JNIEnv *, jobject);

/*
* Class: ParallelPort
* Method: sendData
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_ParallelPort_sendData
(JNIEnv *, jobject, jint);

/*
* Class: ParallelPort
* Method: readStatus
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_ParallelPort_readStatus
(JNIEnv *, jobject);

/*
* Class: ParallelPort
* Method: sendControl
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_ParallelPort_sendControl
(JNIEnv *, jobject, jint);

#ifdef __cplusplus
}
#endif
#endif
 
J

Jim Langston

I'm trying to make a Java program access a parallel port. Java's comm
API does not provide me with the control I need. I need to be able to
write to the data and control pins and read the status pins. Any Java
people know a good solution? I'm trying to use JNI and create my own
library, but building the library gives me these errors:
<java error and code snipped>

Umm... why the heck are you asking about a Java issue cross posted to
c.l.c++ ?
 
D

david.brown.0

RXTX was the only thing that had any form of parallel port access, but
as far as I can see, its just a native library without a Java side
implementation. I've done some more searching and found a lot that can
access the serial port, but not the parallel port. I'm trying to drive
an LCD display, so I cannot use the serial port short of buying a
BasicStamp, which is well out of reasonable price range. Java people
keep trying to find something. C++ people, help me build a working
parallel port library, in case I can't find anything.
 
A

andy

RXTX was the only thing that had any form of parallel port access, but
as far as I can see, its just a native library without a Java side
implementation. I've done some more searching and found a lot that can
access the serial port, but not the parallel port. I'm trying to drive
an LCD display, so I cannot use the serial port short of buying a
BasicStamp, which is well out of reasonable price range. Java people
keep trying to find something. C++ people, help me build a working
parallel port library, in case I can't find anything.

In WinXP and Linux and most modern oses, the parallel port is in
protected memory owned by system and you cant access it directly. You
would need to either use DOS outside windows or Win95/98 3.1. or get a
device driver as mentioned previously. (Look on internet for those.
they are usually available for your preferrred language too). For older
systems(DOS in windows or Win95/98 3.1.) you can get at the hardware.
Methods are often not standard (I think?) and are actually C not C++.
You will have to study the documentation, for example in VC6.0 you can
choose various options as follows:

#include <conio.h>

const static unsigned short PortA = 0x378;
intval =_inp(Port);
unsigned char val = 1;
_outp(Port,val);

alternatively use assembler eg:

__int16 PrinStat= PrinterStatus; // Port + 1...its a long time ago?
unsigned char temp0;
__asm {
mov dx,PrinStat /* setup for input from status reg*/
in al,dx
mov temp0,al
}

More info on parallel port workings available e.g
http://www.lvr.com/jansfaq.htm

OTOH

More modern practise is to use USB or firewire, even Ethernet etc and
leave printer port alone as its old fashioned cumbersome with all its
wiring and required connectors and EMI dampening hardware and slow.
Some chips are set up to make use of e.g USB very simple. Software
compatible with their hardware is often free. See for example
http://www.ftdichip.com/
Honestly learning about USB or other fast serial comms will be
preferable in the long term. Even modern printers dont use parallel
port;-)

cheers
Andy little
 
D

david.brown.0

I'm just trying to control an LCD with 4x5 keypad, which maps perfectly
to the parallel port. I'm no electrical engineer. Plus the LCD
requires 4 or 8 bit parallel input (standard Hitachi-type).
 
R

Roedy Green

I'm just trying to control an LCD with 4x5 keypad, which maps perfectly
to the parallel port. I'm no electrical engineer. Plus the LCD
requires 4 or 8 bit parallel input (standard Hitachi-type).

if it does not talk back to you, perhaps you can drive it as if it
were a very stupid printer with a printer driver that just passes raw
"text" through.

see http://mindprod.com/jgloss/printing.html

Java lets you create PS files and pass them directly to a PS printer,
so there should be some way of creating text files and passing them
unmolested to a dumb printer.
 
A

andy

I'm just trying to control an LCD with 4x5 keypad, which maps perfectly
to the parallel port. I'm no electrical engineer. Plus the LCD
requires 4 or 8 bit parallel input (standard Hitachi-type).

Well. This thread is now Beyond off topic for a C++ language newsgoup.
I think you need to download the datasheets from Hitachi for the
particular LCD. I'd be amazed if they dont provide any driver
hardware/software frankly.

cheers
Andy Little
 
A

andy

I'm trying to make a Java program access a parallel port. Java's comm
API does not provide me with the control I need. I need to be able to
write to the data and control pins and read the status pins. Any Java
people know a good solution? I'm trying to use JNI and create my own
library, but building the library gives me these errors:

ld: warning: cannot find entry symbol _start; defaulting to
0000000008048094
ParallelPort.o: In function `Java_ParallelPort_setAddress':
ParallelPort.cpp:(.text+0x96): undefined reference to `ioperm'
ParallelPort.cpp:(.text+0xaa): undefined reference to `ioperm'

Actually the following links might explain whats going on. I'm guessing
you are using source code written for Linux or Unix on Windows? ioperm
lives in io.h in Linux, but doesnt exist in that header on Windows. You
could however try running Cygwin in Windows to get Unix like
functionality.

http://www.die.net/doc/linux/man/man2/ioperm.2.html
http://linux.about.com/library/cmd/blcmdl2_ioperm.htm
http://openwince.sourceforge.net/ioperm/

cheers
Andy Little
 
G

Gordon Beaton

ld: warning: cannot find entry symbol _start; defaulting to
0000000008048094
ParallelPort.o: In function `Java_ParallelPort_setAddress':
ParallelPort.cpp:(.text+0x96): undefined reference to `ioperm'
ParallelPort.cpp:(.text+0xaa): undefined reference to `ioperm'

It appears as though you are trying to compile your library code as if
it were a complete program. You need to compile it as a shared
library, perhaps something like this:

g++ -shared -fPIC ParallelPort.cpp -o libParallelPort.so

(you will likely need to add some -I paths to the above as well)

/gordon
 
R

Roedy Green

I'm trying to make a Java program access a parallel port. Java's comm
API does not provide me with the control I need. I need to be able to
write to the data and control pins and read the status pins. Any Java
people know a good solution? I'm trying to use JNI and create my own
library, but building the library gives me these errors:

Are you trying to do this on Windows or Linux. If Windows:

If you were writing your JNI in C++ called mouse.cpp then:

* must have previously generated the mouse.h file with
* javah.
* you must have
* e:\program files\java\jdk1.5.0_06\include\win32
* and e:\program files\java\jdk1.5.0_06\include\win32
* in tools | options | directories | include
* For project as a whole:
* In project | settings | general | no MFC
* In project | settings | link | output filename | should end in DLL

Look at any of my JNI projects for inspiration. All have well
commented source. including
http://mindprod.com/products1.html#FILETIMES
http://mindprod.com/products1.html#MOUSE
http://mindprod.com/products1.html#PENTIUM
http://mindprod.com/products1.html#SETCLOCK
 
A

andy

Roedy said:
Are you trying to do this on Windows or Linux. If Windows:

Contrary to what i said before, I now reckon he's using gcc in Linux
and getting a linker error because linker (ld) cant find definition of
ioperm.

FWIW ;-)

regards
Andy Little
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top