LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-08-2006, 04:05 AM   #1
pzydak
LQ Newbie
 
Registered: Dec 2006
Posts: 3

Rep: Reputation: 0
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
 
Old 12-08-2006, 07:06 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
This is just a guess...

a 'seek' is when a file pointer, i.e. the position in a file moves.
this doesn't make sense for a parallel port. So obviously write internally
does a seek on the second write to "seek" to the next byte in the "file", which in
a parport makes no sense. So maybe you should not use write?

I googled this:

http://tldp.org/HOWTO/IO-Port-Programming-9.html
http://www.die.net/doc/linux/man/man2/outb.2.html
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
illegal seek bijucnair Programming 7 06-30-2006 08:11 AM
Writing to parallel port 0x37a works, 0x378 don't Pier Linux - Hardware 3 06-27-2006 04:51 PM
bad group ID `0' for user `root': Illegal seek mdar Slackware 4 01-07-2006 11:09 AM
No control connection for command: Illegal seek mlse Linux - Networking 0 06-20-2005 03:21 AM
Illegal Seek error from Motion larry.barnes Linux - Software 0 05-01-2004 08:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration