Find the answer to your Linux question:
Results 1 to 2 of 2
Hello, I am a new user and want to generate a TTl pulse by parallel port finally. Presently I am trying to get high and low values at the data ...
  1. #1
    Just Joined!
    Join Date
    Mar 2009
    Posts
    6

    Accessing Parallel Port: outb and ioperm Problem

    Hello,

    I am a new user and want to generate a TTl pulse by parallel port finally. Presently I am trying to get high and low values at the data pin.

    But I am getting segmentaion error.

    My question are:
    How do I remove this error?
    with base = 0x378 means I can access the first data pin? Is it? and 0x379 means second data pin and so on?

    Please help me out.
    thanks

    Code:


    /* Generate pulse by parallel port
    with min and max exposure time
    Exposure time is controlled by the width of the pulse
    */


    #include <stdio.h>
    #include <sys/io.h>


    int base=0x378;
    int result;
    int value;

    int main( )
    {

    // /*s The line below is used to change the privelege level
    // gives access with associated risks
    // */
    // result = iopl(3); /* Returns 0 on success , 3 = Modes*/
    // {printf ("IOPERM %d\n\n", result);}

    /* The two lines below gives access to the addresses else you get
    'Segmentation Fault' that is accessing restricted addresses.
    If success then you get 0 else -1
    */

    result = ioperm(base,8,0); // 1 = on
    {printf ("IOPERM = %d\n\n", result);}

    // while(1)
    // {

    printf("High\n");
    int value = 0xff;
    printf("outb(%02X,%04X)\n",value,base);
    outb(value,base);


    printf("Low\n");
    value = 0x00;
    printf("outb(%02X,%04X)\n",value,base);
    outb(value,base);

    //usleep(10000000); //Adds wait
    // }
    }

  2. #2
    Just Joined!
    Join Date
    Mar 2009
    Posts
    6

    This program works

    /* Generate pulse by parallel port with min and max exposure time.
    Exposure time is controlled by the width of the pulse */

    #include <stdio.h>
    #include <sys/io.h>

    int base=0x378;
    int value,i;

    int permission()
    {
    /* The line below gives access to the addresses else you get
    'Segmentation Fault' that is accessing restricted addresses.
    If success then you get 0 else -1
    */
    return ioperm(base,1,1);
    }

    int main( )
    {

    // Get permission to access
    permission();

    // Infinite pulses
    // while(1)

    // Ten pulses of equal duration , 50 % duty cycle
    for (i=0;i<11;i++)
    {
    printf("High\n");
    int value = 0xff;
    printf("outb(%02X,%04X)\n",value,base);
    outb(value,base);

    usleep(10); //Waits for micro secs
    /*
    printf("Low\n");
    value = 0x00;
    printf("outb(%02X,%04X)\n",value,base);
    outb(value,base);

    usleep(10); //Waits for micro secs*/

    }
    printf("Number of pulses %d\n",i-1);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...