473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Parallel Port Access

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
12 8587
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

<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
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
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

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
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
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

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

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
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joseph Suprenant | last post by:
I am looking to read a byte or write a byte on the parallel port in linux. I am using red hat 7.3. I tired using this but i couldnt get anywere. { unsigned char value; __asm__ volatile ("inb...
6
by: Novice Experl | last post by:
I'd like to write a simple application that interfaces with the parallel port, and changes the data on it according to keyboard input. I hope I can get it to run under windows xp and / or windows...
4
by: David | last post by:
I'm wondering if python is capable of fairly precise timing and also sending data out the parallel port. For example ; making a 7.5 KHz square wave come out of one of the data pins on the...
9
by: MNQ | last post by:
Hi All I want to use my parallel port of my PC to control some external devices. I am writing a program in ANSI C using the PacificC compiler. What I need to know is how to access the parallel...
4
by: MSDousti | last post by:
Hi, everyone. I have written this code in Tubo C++ 3.0 earlier, and now I want to port it to VC.NET: int out=0; out=(out & 0xDF); outportb(0x378,out); .... As you see, it seeks to parallel...
5
by: john | last post by:
Hi, I am trying to use "_outp " function to write to parallel port . I am using microsoft visual C++6.0. I am using it like this _outp ( 956, 255) . I am using decimal numbers. The thing is...
3
by: nik | last post by:
hello frinds, last night i am using C prog to get output at my parallel port the following source code is #include<dos.h> #include<conio.h> #include<process.h> void main() { outportb(...
6
by: abhi | last post by:
Hello, I want to create a small project which will display scrolling text on LED that will be attached to Parallel port. I want to create this project in C language(possibly in Mingw) on Windows...
4
by: Soren | last post by:
Hi, I want to control some motors using the parallel port.. however, my laptop does not have any parallel ports (very few do). What I do have is a USB->Parallel converter... I thought about...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.