LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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-06-2018, 03:59 PM   #1
amarcuz
LQ Newbie
 
Registered: Nov 2010
Posts: 4

Rep: Reputation: 0
Bash script to raise DTR or CTS on RS232


Good afternoon all,

Newbie here at using Serial or Parallel communication, but, I need some education is someone could help me.

I have a need to generate either a bash script or a c executable to energize a coil on a relay to drop power to my remote DSL modem when TCP/IP communication is lost.

I have the code working well to detect loss of TCP/IP communication, but have no idea how to write a shell script or c executable to cause the DTR or CTS lines (RS232) to go high and trigger a low current low voltage coil via a call from my bash script.

Could a kind soul assist me as to what I could modify on 01000111 script to cause my desired effect for say 2-5 sec interval so that the DSL modem would reboot?


Many thanks for any advise, examples or ideas on how I can do this.
 
Old 10-06-2018, 09:34 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
Please post your thread only once. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. Your reference to 01000111 where you also posted is a quiet 10 year old thread, so let's allow it to remain that way and continue your discussion here.

If I understand your question, you do not want to carry on any communication over the serial port, instead you only want to toggle the handshaking lines to control an external device...?

In that case, a quick search of LQ threads turns up this C solution, manually controlling RTS/CTS. You will likely find others using LQ's search function from the right sidebar, and many more including shell based variations using your search engine of choice.

I think that from a shell script you would use stty to change the state with the device driver. See man stty for its use, and follow the SEE ALSO links from that page for other serial I/O functions.

Once you have decided on a language and method to toggle the line, it should be easy to wrap it into a loop or function to provide the desired timing delay.

Good luck!

Last edited by astrogeek; 10-06-2018 at 10:17 PM. Reason: added stty
 
Old 10-08-2018, 01:09 PM   #3
amarcuz
LQ Newbie
 
Registered: Nov 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Serial port configuration

My apologies for the double post.


Read the two provided posts. Compiled and ran Hko posted c code all with no errors.
When running his code I got an error opening STTY. I then remembered (from long ago) that UNIX/Linux used the STTY connections for consoles, so I ran dmesg and extracted the info on the STTY's. Lo and behold a I suspected STTY0 is taken up by console 0.

Are the console setting still holding even when video output is through a VGA port?

Running minicom -s -c on I can see that the physical RS232 port is configured for tty8 115200 8N1.

Modified Hko c code to reference tty8 (later part of his code) but still no go.


What am I missing?

Many thanks
A
 
Old 10-09-2018, 01:57 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,873
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Also check this post
https://www.linuxquestions.org/quest...0/#post1658463
 
  


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
Need Help with Bash script for RS232 communication SuperDude123 Programming 1 09-30-2013 08:43 PM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
Script to raise the alarm akhtar.bhat Programming 4 11-04-2008 11:49 PM
Serial Port : How do I raise DTR ttumelty Programming 3 08-26-2005 04:17 AM
USB>RS232 versus PCMCIA>RS232 jayhel Linux - Laptop and Netbook 2 08-04-2005 06:09 PM

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

All times are GMT -5. The time now is 08:52 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
Open Source Consulting | Domain Registration