ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello.
I have a simple question in LINUX programming.
I am programming in C under LINUX and I need to send a signal to digital I/O
connector to turn on or off (1 or 0). I have never programmed using hardware
and have no idea how to send such signals.
After some searchings I have found some similar commands ioperm and outb, they work well but their range of ports doesnot include the ports I need (0x442 for instance).
Could You please suggest me a direction, or maybe piece of code?
If the only option is to make assembler code and include it in my program, please give me example of code in assembler and how to include it in c because I have never worked with it.
Thanks in Advance,
Leonid
Dave,
You are right,
The question is that I have never done it, not in C nor assembler, so what I need is just a simple advise or piece of code how can I write to that address,
Thanks
Sir,
I haven't done inp/outp since DOS days, however I'm seriously interested in your digital IO project board for something I want to do. Could you please tell us what digital IO board you are using and where to buy it so I can get one. I'll certainly be able to help you with the software part when I get my own and try it out.
This is totally untested on my linux box but is something I did several years ago on a unix like OS.
I had bought a card that would allow me to utilize the unused printer port on my computer. It did this by turning on a hardware switch that would run a motor.
Psudo code might look something like this
Code:
#define bit0 0
#define bit1 1
#define bit2 2
#define bit3 4
#define etc xxxx
path = open("printer"); //path to device
write(path, bit3; //turn on device
sleep(4); //wait til device does something
write(path, bit0); //turn off device
Dave,
The code You propose is right and should work in case You know the device and it is in /dev directory. I need to run a command similar to open(...) but instead the devise to write port address (0x442 like I mentioned) which I want to open and to right bits in it.
Thanks
Dear randyding,
I am not sure which information do You need, I will give You all I know about my motherboard. It is MB820, Socket 478 Pentium4, Intel 875P Chipset, Industrial Motherboard. The motherboard has digital I/O which includes 4 in 4 out ports.
Please tell me If You need more information I can look for it in users manual of the MB.
Anyway thanks in advance for any help
Leonid,
If your digital I/O device doesn't have a kernel module supporting it, I think you have to write your own. I think it wouldn't be an easy task if you have never done it before. Anyway, it you decide to do it, try to read the great book Linux device drivers.
Shy,
It sounds pretty strange, the problem is that I am a programmer with specializations in image processing, working for a small start-up, and there is only one issue connected to hardware. We have a lamp connected to digital I/O and during the run of my program I should to tell the lamp when to turn on or off. It is really a bad idea that for such small task I will have to read books about drivers.
I know the port number of the I/O. Shouldn't it be just sending signal to the port?
Maybe You have a simpler idea, like a command, assembly code, connecting the lamp to another place (or even lighting it manually ) but not spending days (or even weeks) on a task that I believe should be nothing for hardware people.
Thanks
Well, what is this 'digital I/O'? Does it use some standard interface (say, like serial port)? If so, kernel should defenitely have some piece of code to handle this, but I can not say right now what exactly because I have never had an experience working with 'digital I/O' if it's a separate (possibly new?) standard (like, say, usb or serial/parallel ports).
Shy,
It is like parallel port for printer for example. I have succeeded to connect the printer port using commands ioperm, inb, outb and the direct port number. The problem is that that commands don't support port addresses more than 0x3ff and my digital I/O address is 0x442, so I wonder if there is a command that is similar to outb() and will support that address. Regarding the interfaces I am not sure what does it use, but if You could tell me how to check it I would be glad to understand it more. All I have is motherboard manual that says the addresses of the digital I/O and a lamp connected to, that was never lighted there. As I mentioned if I connect it to 0x378 (which is printer port) everything works fine, but it is a really bad idea to use printer's port.
Originally posted by leonidg Dave,
The code You propose is right and should work in case You know the device and it is in /dev directory. I need to run a command similar to open(...) but instead the devise to write port address (0x442 like I mentioned) which I want to open and to right bits in it.
Thanks
I'm not sure what you are saying. What is stopping you from writing to address 0x442?
Also what tells you that it is mapped to that address?
Dave,
The problem is that I don't know commands to write to desired address except the outb() command, which works well for 0x378 but doesn't work for 0x442. The 0x442 comes from MB manual I believe, my boss found it.
Thanks
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.