Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7965331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:07:30+00:00 2026-06-04T06:07:30+00:00

I want to write a simple c program to do the following. Open a

  • 0

I want to write a simple c program to do the following. Open a connection to a parallel port, make pin 2 high, make pin 2 low and close the connection. I am using JNI for this, so my Java source file is as follows.

package meas;

public class Meas {

    public static native boolean open();

    public static native boolean on();

    public static native boolean off();

    public static native boolean close();

}

Note that a Java file should control the parallel port, i.e. decide when it should be high or low.
Then, I extracted a c header file using javah.

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

Then I implemented this for Linux:

#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);
    }
}

I am not a C export, so the code above may look weird. But that does not really matter. What matters is that I want to implement this for Windows also. The goal is to get a dll, just like I already have a libMeas.so for Linux. I already have MinGW working and all but the problem is that on Windows you can’t use sys/io.h. Searching on google for documentation on how to do this results in tutorials on how to write data on the parallel port. I do not want this, I just want to make pin 2 high or low. My guess is that this should be fairly simple. Can anyone point me in the right direction on how to do this for windows (using the same header file)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:07:33+00:00Added an answer on June 4, 2026 at 6:07 am

    I got it working with a dll obtained from http://logix4u.net/parallel-port/16-inpout32dll-for-windows-982000ntxp. With this dll there also came a c header file with only two functions. Inp32() and Out32(). Which can be used to read and write words directly to the parallel port, quite the same as the deprecated _inp() and _out() functions in conio.h. So it basically means I can directly access the parallel port in user mode.

    Btw. you have to dig a little to find the binaries on logix4u.net; it can be found here: http://logix4u.net/parallel-port/parallel-port/index.php?option=com_content&task=view&id=26&Itemid=1 it seems there also exists a 64 bit version of this dll which supports windows vista and hopefully windows 7.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a simple program which shows my internet activity over a
I want to write a simple program that takes a moderately sized wav file
I want to write a simple program that determines whether the number the user
I'm trying to write a very simple program, I want to print out the
I want to write a simple web framework myself using WSGI, Python. I am
I want to write a simple program that detect USB Wifi plugged computer and
I want to write a simple program, that writes console input to file with
I want to write a simple program which can customize iphone icons like their
My question is language independent. I want to write a simple unit convertor program.
I'm trying to write a simple program using WinSnmp in C++. There is very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.