illegal seek when writing to parallel port
Hi,
I try to write a simple C code to comunicate with a data aquisition system using the parallel port. I have brief description of its commands. I can give one command to the device and the device react properly. I also get "Succes" from the write function which I use to write to the parallel port. But if in the same program I try to send two commands with a time delay, both commands are executed by the device but the second write function (used to send the command to the device trough the parallel port) respond with "Illegal seek" error. I don't know why.
Both commands are ok. I can write two programs and use one of that commands and I don't get any error.
Here is my code which cause problems:
int main(int argc, char *argv[])
{
unsigned char status, control, data;
int fd;
int mode;
char buffor[16];
//Open the parallel port
fd = open ("/dev/parport0" , O_RDWR);
if (fd == -1) {
perror ("open");
return 1;
}
//gain exclusive access for the port
if (ioctl (fd, PPEXCL)) {
perror ("PPEXCL");
close(fd);
return 1;
}
if (ioctl (fd, PPCLAIM)) {
perror ("PPCLAIM");
close(fd);
return 1;
}
//assign mode
mode = IEEE1284_MODE_EPP;
//set the desired mode
if (ioctl (fd, PPNEGOT, &mode)) {
perror ("PPNEGOT");
close(fd);
return 1;
}
//Reset of the device (write()respond with "SUCCES")
if (write(fd,"C",1)) {
perror ("WRITE C");
}
//Waiting some time for the device
usleep(10000000);
//Switch on the calibration mode
//write() cause "Illegal seek"
if (write(fd,"E",1)) {
perror ("WRITE E");
}
close(fd);
return 0;
}
I looked for a solution but I didn't find. Anyone can help me or suggest something?
Pzydak
|