package meas;
Code: Select all
public class Meas {
public static native boolean open();
public static native boolean on();
public static native boolean off();
public static native boolean close();
}
Code: Select all
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class meas_Meas */
#ifndef _Included_meas_Meas
#define _Included_meas_Meas
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: meas_Meas
* Method: open
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_meas_Meas_open
(JNIEnv *, jclass);
/*
* Class: meas_Meas
* Method: on
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_meas_Meas_on
(JNIEnv *, jclass);
/*
* Class: meas_Meas
* Method: off
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_meas_Meas_off
(JNIEnv *, jclass);
/*
* Class: meas_Meas
* Method: close
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_meas_Meas_close
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
#include <sys/types.h>
#include <fcntl.h>
#include <meas_Meas.h>
#define BASEPORT 0x378 /* lp1 */
int tem;
/*
* Class: meas_Meas
* Method: open
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_meas_Meas_open(JNIEnv *env, jclass clz) {
//set permissions to access port
if (ioperm(BASEPORT, 3, 1)) {
perror("ioperm");
exit(1);
}
tem = fcntl(0, F_GETFL, 0);
fcntl(0, F_SETFL, (tem | O_ASYNC));
}
/*
* Class: meas_Meas
* Method: on
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_meas_Meas_on(JNIEnv *env, jclass clz) {
outb(255, BASEPORT);
}
/*
* Class: meas_Meas
* Method: off
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_meas_Meas_off(JNIEnv *env, jclass clz) {
outb(0, BASEPORT);
}
/*
* Class: meas_Meas
* Method: close
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_meas_Meas_close(JNIEnv *env, jclass clz) {
fcntl(0, F_SETFL, tem);
outb(0, BASEPORT);
//take away permissions to access port
if (ioperm(BASEPORT, 3, 0)) {
perror("ioperm");
exit(1);
}
}