[Linux-parport] Trouble setting up an EPP connection
ofir
ofir.noy at xorcom.com
Wed Oct 13 06:10:13 EDT 2004
Hi all,
I write an application (in user space) that sends and receive data using
the parport driver. I want to use the EPP protocol.
I'm having trouble setting up the connection.
I basically use
mode = IEEE1284_MODE_EPP;
and then either:
ioctl( fd, PPSETMODE, &mode)
In which case "nothing happens" a read blocks, and a send operation
generates no response on the other side.
or:
ioctl( fd, PPNEGOT, &mode)
which fails with "Input/output error" from perror
Here are the details:
[PC A]
OS: Fedora core2 (kernel 2.6.5-1.358)
Port Type: Parallel Port ECP/EPP
Output of dmesg | grep parport :
parport0: PC-style at 0x378 [PCSPP,TRISTATE,EPP]
parport0: PC-style at 0x378 [PCSPP,TRISTATE,EPP]
lp0: using parport0 (polling).
parport0: PC-style at 0x378 [PCSPP,TRISTATE,EPP]
parport_negotiate returned: 1
[PC B]
OS: Debian (kernel 2.6.7-1-386)
Port Type: Parallel Port ECP/EPP
Output of dmesg | grep parport :
parport: PnPBIOS parport detected.
parport0: PC-style at 0x378, irq 7 [PCSPP,TRISTATE,EPP]
parport: PnPBIOS parport detected.
parport0: PC-style at 0x378, irq 7 [PCSPP,TRISTATE,EPP]
lp0: using parport0 (interrupt-driven).
The problem is that I can't set the negotiation mode for the communication.
1) Do I need to configure Linux in some way to enable the EPP capabilities on
the system?
2) Is there some thing I'm not doing right (program-wise)?
I included my source please take a look.
(The application serves as both the receiving and sending app.
Each instance of the app is set as receiver or sender depending on the
parameter it is run with.)
example:
(Setting a sending instance on parport1)
app -p /dev/parport1 -s
(Setting a receiving instance on parport0 [default])
app
The source code for the application:
#include <linux/parport.h>
#include <linux/ppdev.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#define FALSE 0
#define TRUE 1
int open_parport(char* device_name, int flags,int mode)
{
int fd = -1;
/* Open the device for IO */
if((fd = open(device_name,flags)) == -1)
{
perror(device_name);
return -1;
}
/* Claim device */
if ( ioctl (fd, PPCLAIM) )
{
perror ("PPCLAIM");
close (fd);
return -1;
}
/* Set the communication mode (protocol) for the device */
if ( ioctl(fd, PPSETMODE, &mode) )
{
perror ("PPSETMODE");
close (fd);
return -1;
}
/* I used PPNEGOT instead of PPSETMODE and got
"Input/output error" from perror
When I started using PPSETMODE the error
was gone but nothing was happening
if ( ioctl (fd, PPNEGOT, &mode))
or: {
perror("error: device not IEEE 1284 compliant");
close (fd);
return -1;
}
*/
return fd;
}
int main(int argc, char** argv)
{
int fd = 0;
int sending = FALSE; /* TRUE=send FALSE=receive */
int mode = IEEE1284_MODE_EPP;
int res_size = 0;
size_t i = 0;
size_t data_len = 30;
char device_name[1024] = {"/dev/parport0"};
unsigned char buffer[36];
if(argc > 1)
{
for(i = 1; i < argc ; i++)
{
switch(argv[i][1])
{
case 'p':
strcpy(device_name,argv[++i]);
break;
case 's':
sending = TRUE;
break;
}
}
}
if(sending) /* Sender */
{
/*Fill buffer with 'X' and 'O' for testing */
for(i = 0; i < data_len ; i++)
buffer[i] = (i%2) ? 'X' : 'O';
if((fd = open_parport(device_name, O_RDWR, mode)) == -1)
return -1;
if((res_size = write(fd,buffer,data_len)) == -1)
{
perror("Failed to write device");
exit(-1);
}
}
else /* Receiver */
{
if((fd = open_parport(device_name, O_RDONLY, mode)) == -1)
return -1;
if( (res_size = read(fd,buffer,data_len)) == -1)
{
perror("Failed to read device");
exit(-1);
}
buffer[res_size] = '\0';
printf("Buffer received: %s\n", buffer);
}
ioctl(fd, PPRELEASE);
close(fd);
return 0;
}
More information about the Linux-parport
mailing list