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 03-29-2006, 04:01 PM   #1
Lotharster
Member
 
Registered: Nov 2005
Posts: 144

Rep: Reputation: 18
serial port direct pin programming


Hello!

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.
 
Old 03-29-2006, 08:57 PM   #2
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
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.
 
Old 03-30-2006, 10:47 AM   #3
Lotharster
Member
 
Registered: Nov 2005
Posts: 144

Original Poster
Rep: Reputation: 18
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.
 
Old 03-30-2006, 08:43 PM   #4
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
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.
 
Old 04-08-2006, 02:30 AM   #5
Regulus
Member
 
Registered: Dec 2004
Posts: 41

Rep: Reputation: 15
Hoi Lorharster,

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.

Regards,
Regulus
 
Old 04-08-2006, 08:23 AM   #6
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
You can go here and get my serial library to read/write the control lines

However the solution the original poster was looking for was a way to control the TX pin as if it was a general io port... this isn't possible.

Last edited by randyding; 03-19-2009 at 10:47 PM. Reason: web site is now gone, removed url
 
  


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
Problem of serial port programming fingerling54 Linux - Software 4 05-18-2005 03:22 PM
Need help to read a signal from the CTS pin of a serial port juan_de_margo Linux - Hardware 0 02-24-2005 03:36 AM
serial port programming!!! novice_din Programming 4 02-03-2005 08:50 PM
Programming the Serial Port karans Linux - Networking 2 11-03-2003 01:54 AM
Controlling serial port RTS pin from 'C' program dcarter Slackware 1 09-26-2003 07:01 PM

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

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