LinuxQuestions.org
Review your favorite Linux distribution.
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-18-2004, 08:17 PM   #1
KenHorse
LQ Newbie
 
Registered: Dec 2004
Posts: 5

Rep: Reputation: 0
Serial ports


I am currently using /dev/ttyS1 in a standalone binary that uses only Xon/Xoff for handshaking. This means DTR, RTS, etc aren't being used. The thing is, this binary obviously "opens and "closes" the serial port as part of its operation.

I'm hoping to set RTS to one state for 1 second , then reset it back to its original state, then call this binary. I want to use RTS as a "reset" line for an embedded processor that my existing binary sends a file to the processor's flash memory. I would have to do this external of the binary obviously.

I have a few questions regarding this:

1) I am pretty sure I can use ioctl() for setting and resetting RTS. But would the act of closing the device force RTS to a different state than it was left when port is closed (I need RTS to be high, until I specifically tell it to go low)

2) Is there anyway to manipulate RTS via a shell script?

Thanks in advance for any answers!

Last edited by KenHorse; 12-18-2004 at 08:18 PM.
 
Old 12-27-2004, 01:59 AM   #2
cppkid
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Ubuntu
Posts: 185

Rep: Reputation: 30
I don't think that closing the connection will force RTS to change its state, but when the ttyS1 goes free some other process can access it and modify, So try to keep the control. Why you want to close the handle??
Anyway you are right that you can use ioctl() for the purpose, here is how to do it. And i don't know about the shell script for the purpose.
Make the binary file and call it from your script Just kidding

In this code m_hCom is the handle to ttyS1

Code:
//________________________Set_RTS__________________
bool Set_RTS(void)
{
int nRet;
int status;
status = 0;
nRet = ioctl(m_hCom, TIOCMGET,&status);
	if(nRet < 0) return FALSE;
status |= TIOCM_RTS;
nRet = ioctl(m_hCom, TIOCMSET, &status);
	if(nRet < 0) return FALSE;
return TRUE;
}


//________________________Clr_RTS__________________
bool Clr_RTS(void)
{
int nRet;
int status;
status = 0;
nRet = ioctl(m_hCom, TIOCMGET,&status);
	if(nRet < 0) return FALSE;
status &= ~TIOCM_RTS;
nRet = ioctl(m_hCom, TIOCMSET, &status);
	if(nRet < 0) return FALSE;
return TRUE;
}
 
Old 12-27-2004, 09:49 AM   #3
KenHorse
LQ Newbie
 
Registered: Dec 2004
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by cppkid
[B]I don't think that closing the connection will force RTS to change its state, but when the ttyS1 goes free some other process can access it and modify, So try to keep the control. Why you want to close the handle??
Anyway you are right that you can use ioctl() for the purpose, here is how to do it. And i don't know about the shell script for the purpose.
Make the binary file and call it from your script Just kidding

The existing binary obviously opens the port as part of its operation. I don't have the source for it so I can't incorporate your code into it (thanks for the code by the way!) so I have no choice about closing the port before reopening it.

Here are the steps I'm trying to do:

1) Open ttyS0
2) Set RTS high
3) Wait 1 second
4) Reset RTS low
5) Close ttyS0
6) Run my other binary

I'll use your code and write a script to do all the steps above. One way to know if RTS is changed on closing is to try it!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to use serial ports in kernel? jamespayne Programming 24 06-24-2014 01:20 PM
Can only use one of my serial ports steaktc Linux - Hardware 1 11-23-2005 07:07 AM
Cannot get PCI Serial ports up paul.nel Linux - Hardware 2 11-10-2003 02:04 PM
accessing serial ports w/ c++ iggy_mon Programming 3 08-31-2003 08:05 PM
Serial Ports (tty´s) aqoliveira Linux - Hardware 4 06-21-2002 11:06 AM


All times are GMT -5. The time now is 03:55 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration