[PARPORT] ppdev user-spaced driver


chris fletcher (clfletch@nosc.mil)
Tue, 9 Nov 1999 15:53:21 -0800 (PST)


Hi,
   Thanks for the input about using the ppdev user-space driver. I put together a program to read a simple counter from the parallel port, however I still come up with a segmentation fault. The code is included below along with a sample of /dev,dmesg, and lsmod. It seems that the problem is about opening /dev/parport0 to read, but I don't see it. It's probably something really simple, so if you see anything unusual please give me some feedback thanks.

//negotiate.c
//ppdev user-spaced driver
//program to read from parallel port using patch-2_2_10-ppdev4 with kernel 2.2.10
#include <sys/time.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <getopt.h>
#include "parport.h"
#include "ppdev.h"

int main (int argc, char *argv[])
{
  int fd;
   char hbuffer[200];
   int data;
  int compat = IEEE1284_MODE_COMPAT;
  int mode = IEEE1284_MODE_EPP;
   int i;
   
  fd = open ("/dev/parport0", O_RDWR);

  if (fd == -1)
    {
      perror ("/dev/parport0");
      return fd;
    }

  if (ioctl (fd, PPSETMODE,&mode))
    {
      fprintf (stderr, "deviceid: cannot set transfer mode\n");
      close (fd);
      return 1;
    }

  if (ioctl (fd, PPCLAIM))
    {
      fprintf (stderr, "deviceid: cannot claim port\n");
      close (fd);
      return 1;
    }

  
  if (ioctl (fd, PPNEGOT, &compat))
    {
      fprintf (stderr, "deviceid: device not IEEE 1284 compliant\n");
      close (fd);
      return 1;
    }
  mode |= IEEE1284_DEVICEID;
  if (ioctl (fd, PPNEGOT, &mode))
    {
     fprintf (stderr, "deviceid: device not IEEE 1284 compliant\n");
     close (fd);
     return 1;
     }
 data=read(fd,hbuffer,100);
  printf("data %d\n",data);

 for(i=0;i<10;i++)
  printf("read data %x\n",hbuffer[i]);
  ioctl (fd, PPNEGOT);
  ioctl (fd, PPRELEASE);
  close (fd);
  return;
 }

>./negotiate //The read data is from a counter device connected to the
data 100
read data 44 // parallel port and should begin at one and count up
read data 44
read data 44
read data 44
read data 44
read data 44
read data 44
read data 44
read data 44
read data 44
Segmentation fault

>dmesg

parport0: PC-style at 0x378, irq 7 [SPP,ECP,ECPEPP,ECPPS2]
parport0: no IEEE-1284 device present.
lp0: using parport0 (interrupt-driven).
/dev/vmmon: Module vmmon registered with major=10 minor=165 tag=$Name: build-212 $
/dev/vmmon: vmx86 module initialized
vmnet0: bridge eth0 up
vmnet0: bridge eth0 attached
ppdev: user-space parallel port driver
ppdev0: registered pardevice
ppdev0: released pardevice because user-space forgot
ppdev0: unregistered pardevice
Unable to handle kernel NULL pointer dereference at virtual address 000001fc
current->tss.cr3 = 02dc7000, %cr3 = 02dc7000
*pde = 00000000
Oops: 0000
CPU: 0
EIP: 0010:[<c0120d00>]
EFLAGS: 00010082
eax: c2ef35bc ebx: c3ff3080 ecx: 000001f4 edx: c0c2c000
esi: c2ef3590 edi: 00000202 ebp: bffff778 esp: c2dcdf48
ds: 0018 es: 0018 ss: 0018
Process devpp (pid: 399, process nr: 58, stackpage=c2dcd000)
Stack: c09f6590 bffff778 c48401d8 c2ef35bc 00000000 c48401e1 c2ef3590 c242e5b0
       c0a5b980 c01249f3 c0a5b980 c242e5b0 c242e5b0 00000000 c09f6590 c0125b3b
       c242e5b0 c242e5b0 c242e5b0 c0124a71 c242e5b0 00000003 c242e5b0 fffffff7
Call Trace: [<c48401d8>] [<c48401e1>] [<c01249f3>] [<c0125b3b>] [<c0124a71>] [<c0124ad7>] [<c01091b0>]
Code: 8b 69 08 81 fd 2b 2f c3 a5 0f 85 dd 00 00 00 8b 69 0c 85 ed

>ls -l
crw-rw-rw- 1 root root 99, 0 Jul 22 16:05 parport0
crw-rw-rw- 1 root root 99, 1 Jul 22 16:05 parport1
crw-rw-rw- 1 root root 99, 2 Jul 22 16:05 parport2
crw-rw-rw- 1 root root 99, 3 Jul 22 16:05 parport3

>lsmod
Module Size Used by
ppdev 11064 1
parport_pc 5492 0
parport 6476 0 [ppdev parport_pc]
3c59x 17388 1 (autoclean)
dummy0 720 1 (autoclean)
serial 41940 0 (autoclean)
memstat 1412 0 (unused)

###############################################################

***************************************************************
end
Christopher L. Fletcher
Electrical Engineer
Space and Naval Warfare Systems Command (SPAWAR)
Systems Center San Diego
Code D857 Acoustics Branch
49575 Gate Rd
San Diego, Ca 92152-6435
619-553-3085
clfletch@spawar.navy.mil

-- To unsubscribe, send mail to: linux-parport-request@torque.net --
-- with the single word "unsubscribe" in the body of the message. --



This archive was generated by hypermail 2.0b3 on Tue 09 Nov 1999 - 18:55:30 EST