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.
I'd like to control an external device (homemade hardware) which is connected to my serial port. To do so, I must be able to address the pins of the serial ports directly:
I have to switch on/off RTS, DTR and TxD. that way I transfer data bits into a shift register:
1) First I switch TxD (data) on/off, depending on the bit value
2) Then I switch DTR (clock) on and off again, which causes the data bit to be shifted nto the shift register.
Process 1) and 2) is repeated until all data bits are sent (and the shift register is full).
3) Now I use The RTS (strobe) to signal to the shift register that the outputs can be enabled.
Is there a ready-made protocol that would do this for me or do I really have to set the pins manually,? And if so, how do I do that with linux and c(++)?
Any help is appreciated.
If the question is not clear, feel free to ask.
Regards,
Lotharster
Last edited by Lotharster; 03-30-2006 at 02:54 AM.
The RTS and DTR are no problem, but the TX pin is not controllable in that manner. If you need more than 2 general purpose outputs, the parallel port will work much better. Also, the parallel port is +5 volts and the serial port is around +/- 10 and has lower current than the parallel port outputs.
The O'Reilly book called Linux Device Drivers has example software for controlling the parallel port, its a kernel driver.
I already thought about using the parallel port, but for two reasons I'd rather use the serial port:
1) I use my parallel port for my printer
2) The parallel port is directly connected to the mainboard, and quite easyly destroyed if a short-circuit happens.
I've found a pascal program to set the pins directy, but it only works for windows. I'm wondering if there's really no alternative for linux.
You can buy a PCI card that has 1 or more parallel ports.
There are many many 3rd party hardware project boards, some connect to the serial port and allow you talk serially to an on-board microcontroller. They gives you access to either +5V logic pins or solid state relays depending on you application. These serially controlled boards have a simple control protocol and runs on any OS that has serial io capability.
These devices are not that hard to build, sounds like you have a hardware background, take a look at the Microchip PIC controllers. They are cheap and can easily give you parallel io with a serial port interface. Or Google for hardare io boards and buy one for twenty bucks, there are a lot of options.
I have had a similar problem where I had to toggle the RTS of a device connected through a serial port on and off. After some Googling around I found a piece of C code on the web that did this, and it was not more than 20 lines of code or so.
Unfortunately, I've lost the program due to a disk crash and now have the same problem as you do. So if you've found a solution, or if anybody else knows one, please share it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.