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