By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,732 Members | 1,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,732 IT Pros & Developers. It's quick & easy.

Parallel Port Access

P: n/a
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

Feb 11 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a
me2
On Fri, 10 Feb 2006 19:44:54 -0800, david.brown.0 wrote:
I'm trying to make a Java program access a parallel port.


The rxtx package has parallel port access, as well as others.

www.rxtx.org
Feb 11 '06 #2

P: n/a

<da***********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
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++ ?
Feb 11 '06 #3

P: n/a
On 10 Feb 2006 19:44:54 -0800, da***********@gmail.com wrote, quoted
or indirectly quoted someone who said :
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?


there are some third party libraries . See
http://mindprod.com/jgloss/serialport.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Feb 11 '06 #4

P: n/a
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.

Feb 12 '06 #5

P: n/a

da***********@gmail.com wrote:
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

Feb 12 '06 #6

P: n/a
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).

Feb 13 '06 #7

P: n/a
On 12 Feb 2006 18:42:47 -0800, da***********@gmail.com wrote, quoted
or indirectly quoted someone who said :
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.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Feb 13 '06 #8

P: n/a

da***********@gmail.com wrote:
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

Feb 13 '06 #9

P: n/a

da***********@gmail.com wrote:
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

Feb 13 '06 #10

P: n/a
On 10 Feb 2006 19:44:54 -0800, da***********@gmail.com wrote:
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

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Feb 13 '06 #11

P: n/a
On 10 Feb 2006 19:44:54 -0800, da***********@gmail.com wrote, quoted
or indirectly quoted someone who said :
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

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Feb 13 '06 #12

P: n/a

Roedy Green wrote:
On 10 Feb 2006 19:44:54 -0800, da***********@gmail.com wrote, quoted
or indirectly quoted someone who said :
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:


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

Feb 13 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.