LinuxQuestions.org
Visit Jeremy's Blog.
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 10-19-2005, 12:26 PM   #1
bobbens
Member
 
Registered: Sep 2004
Location: Barcelona
Distribution: Debian, FreeBSD, Gentoo
Posts: 586

Rep: Reputation: 30
alternate methods of parallel port access


Well i'm having trouble using ioperm and outb for some reason, my code looks fine but it just doesnt work. I sorta lost my test circuit in the process so i'm interfacing it directly to an LCD HD44780 module, which i have coded already and it has worked under w32, now i'm working on porting this to linux and i'm basically stuck in the converting my OutPort function from windows to linux, i don't get the expected output.

Basically my PORT_init function is like this:
Code:
int PORT_init(unsigned long nPort)
{
    int err;
    
    /* Get parallel port access permissions */
    err = ioperm(nPort,3,1);
    if(err){
	perror("ioperm");
        return -1;
    }
    OutPort(LPTD_DATA,SIG_D_LOW);

    return 0;
}

short OutPort(unsigned short nPort, unsigned char cByte)
{
    outb(cByte, nPort);
    return 0;
}
where LPTD_DATA is 0x378 and SIG_D_LOW is 0

Yet when i try to initialize my LCD using this i get no output using the same code that worked. I'm running this as root and get no seg faults. I was wondering if it might be easier to use /dev/lp0? since then i wouldnt have to hardcode the port addresses. I've been reading about this and it goes somewhat like this from what i've read:
Code:
fd = open("/dev/lp0", O_RDRW | O_NDELAY);
then i would have to seek and write/read bytes. Could anyone help me out trying this? I think it'd be a better idea since it's much more compatible and gives you the chance to run as non-root if you set the permissions ahead of time. Thanks.
 
Old 10-24-2005, 03:17 PM   #2
bobbens
Member
 
Registered: Sep 2004
Location: Barcelona
Distribution: Debian, FreeBSD, Gentoo
Posts: 586

Original Poster
Rep: Reputation: 30
*bump*


still need a response, or some link. Been searching online and i only find the same damn guide everywhere that just says something about using open and then using fseek (no idea how to use that) to get to the place you want to go (maybe 0x378 in my case?) and then you use read() and write() to manipulate the parallel port, of course the guide barely talks about this. Upon searching i find this same guide at five million different sites, so i don't really get anywhere, maybe trying a more specific search. Anyway if someone could just give me a quick example (maybe just how to write/read a byte to the data lines on the parallel port, using open + read/write no ioperm) i'de be extremely grateful. Thanks.
 
Old 10-24-2005, 07:25 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
I honestly don't know if you can do what you want from user space.

I'm certain that you can do it from a kernel driver.

This a book that tells you - in great detail - how:

Linux Device Drivers, Third Edition
O'Reilly, Jonathan Corbet, Alessandro Rubini, and Greg Kroah-Hartman
http://www.bookpool.com/sm/0596005903

'Hope that helps .. PSM
 
Old 10-25-2005, 04:52 AM   #4
bobbens
Member
 
Registered: Sep 2004
Location: Barcelona
Distribution: Debian, FreeBSD, Gentoo
Posts: 586

Original Poster
Rep: Reputation: 30
basically i only need to be able to send bytes through the parallel power which i believe can be done in user space. It's pretty simple, i'd be surprised if i cant access it without resorting to ioperm and stuff. All i have to do is send through the data lines a byte and through the status lines. not too complicated.
 
Old 10-25-2005, 05:50 AM   #5
Kerrysl
Member
 
Registered: Oct 2005
Location: Sydney, Australia
Distribution: Fedora 8, (previously FC6, FC5, FC4, FC3, & Mandrake 10)
Posts: 70

Rep: Reputation: 15
The programming is beyond me. I just do PHP not C or C++, but have you confirmed that your parallel port is actually working. Do you have any parallel hardware that you can test on (printer, scanner)?

I say that because I have a parallel scanner that is very picky about it's port. It will not work with my onboard parallel port, but does through a Netmos serial/parallel card. I needed to get a kernel patch to get that piece of hardware working properly, so that it correctly identified the parport.

Once you know the port is working, then you can look further into whether your signals are being detected.
 
Old 10-25-2005, 06:19 AM   #6
bobbens
Member
 
Registered: Sep 2004
Location: Barcelona
Distribution: Debian, FreeBSD, Gentoo
Posts: 586

Original Poster
Rep: Reputation: 30
Yeah it works. I'm mainly trying to port some old code i did for windows, in which it also worked. So unless for some reason it has broken on me recently, it should be working fine.
 
Old 10-25-2005, 06:53 AM   #7
Kerrysl
Member
 
Registered: Oct 2005
Location: Sydney, Australia
Distribution: Fedora 8, (previously FC6, FC5, FC4, FC3, & Mandrake 10)
Posts: 70

Rep: Reputation: 15
Quote:
Originally posted by bobbens
Yeah it works. I'm mainly trying to port some old code i did for windows, in which it also worked. So unless for some reason it has broken on me recently, it should be working fine.
No I don't mean "does your hardware work", I mean "does your hardware work IN LINUX".

I had a Joystick that worked in Windows but did not work in Linux. It took a lot or research and trial and error and eventually hacking of joystick module file to get that working. So confirm that your port works in Linux for something basic and then test your code on it.
 
Old 10-25-2005, 07:01 AM   #8
bobbens
Member
 
Registered: Sep 2004
Location: Barcelona
Distribution: Debian, FreeBSD, Gentoo
Posts: 586

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by Kerrysl
No I don't mean "does your hardware work", I mean "does your hardware work IN LINUX".

I had a Joystick that worked in Windows but did not work in Linux. It took a lot or research and trial and error and eventually hacking of joystick module file to get that working. So confirm that your port works in Linux for something basic and then test your code on it.
well i remember getting a parallel port printer working in linux a while back, i was testing it because i was printing funny with usb, so i hooked it up via parallel port and it kept on printing funny, so i trashed it. So about it working, i'm pretty sure it is.
 
Old 10-25-2005, 07:14 AM   #9
Kerrysl
Member
 
Registered: Oct 2005
Location: Sydney, Australia
Distribution: Fedora 8, (previously FC6, FC5, FC4, FC3, & Mandrake 10)
Posts: 70

Rep: Reputation: 15
can you post the output of "/sbin/lspci"?
 
Old 10-25-2005, 08:47 AM   #10
bobbens
Member
 
Registered: Sep 2004
Location: Barcelona
Distribution: Debian, FreeBSD, Gentoo
Posts: 586

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by Kerrysl
can you post the output of "/sbin/lspci"?
Code:
0000:00:00.0 Host bridge: nVidia Corporation nForce2 AGP (different version?) (rev c1)
0000:00:00.1 RAM memory: nVidia Corporation nForce2 Memory Controller 0 (rev c1)
0000:00:00.2 RAM memory: nVidia Corporation nForce2 Memory Controller 4 (rev c1)
0000:00:00.3 RAM memory: nVidia Corporation nForce2 Memory Controller 3 (rev c1)
0000:00:00.4 RAM memory: nVidia Corporation nForce2 Memory Controller 2 (rev c1)
0000:00:00.5 RAM memory: nVidia Corporation nForce2 Memory Controller 5 (rev c1)
0000:00:01.0 ISA bridge: nVidia Corporation nForce2 ISA Bridge (rev a4)
0000:00:01.1 SMBus: nVidia Corporation nForce2 SMBus (MCP) (rev a2)
0000:00:02.0 USB Controller: nVidia Corporation nForce2 USB Controller (rev a4)
0000:00:02.1 USB Controller: nVidia Corporation nForce2 USB Controller (rev a4)
0000:00:02.2 USB Controller: nVidia Corporation nForce2 USB Controller (rev a4)
0000:00:04.0 Ethernet controller: nVidia Corporation nForce2 Ethernet Controller (rev a1)
0000:00:06.0 Multimedia audio controller: nVidia Corporation nForce2 AC97 Audio Controler (MCP) (rev a1)
0000:00:08.0 PCI bridge: nVidia Corporation nForce2 External PCI Bridge (rev a3)
0000:00:09.0 IDE interface: nVidia Corporation nForce2 IDE (rev a2)
0000:00:1e.0 PCI bridge: nVidia Corporation nForce2 AGP (rev c1)
0000:01:07.0 USB Controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 61)
0000:01:07.1 USB Controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 61)
0000:01:07.2 USB Controller: VIA Technologies, Inc. USB 2.0 (rev 63)
0000:01:07.3 FireWire (IEEE 1394): VIA Technologies, Inc. IEEE 1394 Host Controller (rev 46)
0000:01:09.0 Ethernet controller: Intel Corporation 82557/8/9 [Ethernet Pro 100] (rev 01)
0000:02:00.0 VGA compatible controller: ATI Technologies Inc RV350 AP [Radeon 9600]
0000:02:00.1 Display controller: ATI Technologies Inc RV350 AP [Radeon 9600] (Secondary)
 
  


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
Allow program to access parallel port LongName Linux - Newbie 5 08-27-2004 06:08 PM
Parallel port pin access Robert0380 Linux - Hardware 5 07-29-2003 04:11 PM
NFS on an alternate port Syncrm Linux - Networking 0 12-11-2002 09:33 PM
urgent help please (parallel port access) yahya Programming 1 08-12-2002 12:36 PM
urgent help please ( parallel port access) yahya Linux - Software 1 08-12-2002 12:32 PM

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

All times are GMT -5. The time now is 01:41 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