Operating System - HP-UX
1834461 Members
3024 Online
110067 Solutions
New Discussion

Automating I/O over a serial port

 
SOLVED
Go to solution
Michael D'Aulerio
Regular Advisor

Automating I/O over a serial port


I just bought a routing switch which is configured via text commands over a serial port. I am using cu to open the serial port and connect to the switch. Does anyone know of a utility which can batch up a set of commands and send them over the serial port to the switch. I'm trying to automate the switch setup, reduce workload on operators and eliminate typos and user errors. Thanx.
Email: michael.n.daulerio@lmco.com
8 REPLIES 8
doug mielke
Respected Contributor

Re: Automating I/O over a serial port

/etc/gettydefs can send commands to a port, and setup in /etc/inittab.
Michael D'Aulerio
Regular Advisor

Re: Automating I/O over a serial port

Thanks Doug. That's not exactly what I'm looking for. I don't want to set the port up with a getty for users to log into. I want to use the port to send text out to the switch connected to it.
Email: michael.n.daulerio@lmco.com
A. Clay Stephenson
Acclaimed Contributor

Re: Automating I/O over a serial port

You really don't need anything fancy at all.
echo "my stuff" > /dev/ttyd0p3.

The problems arise when you need to assert lines like DTR,CTS, or DCD. You need to either hard-wire the desired pins with a custom cable or run a process that asserts these settings along with baudrate, wordlength,parity, & stopbits. The good news is that the port settings are independent of the process so that if you have a process which holds the port open and asserts the proper signals then a separate echo can send anything you like.
If it ain't broke, I can fix that.
doug mielke
Respected Contributor

Re: Automating I/O over a serial port

Sorry,
I remember back in my propriatary hardware days having to tweek a vendor specific gettydefs / Dialer combination to send commands to set up concentrators, but I'm likely forgetting the details.

Maybe a script with commands redirected > /dev/serialxx, otherwise I'll be quiet now... :^)
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Automating I/O over a serial port

Here is a thread that may help you. In in I discuss the use of 'holdport' whichs opens a port and sets speed. The C source is also attached in that thread.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x6c7dabe92dabd5118ff10090279cd0f9,00.html

You would compile it like this:
cc holdport.c -o holdport
then use it like this:
holdport -t /dev/ttyd0p3 -s 19200
to set up a port at 19200 baud.
After holdport, you can then do something
like this, if necessary.
'stty -crts rtsxoff ctsxon < /dev/ttyd0p3'.

You can then simply echo any characters you like to the port.

If it ain't broke, I can fix that.
Michael D'Aulerio
Regular Advisor

Re: Automating I/O over a serial port

Clay,

Thanks for your suggestions, especially the holdport program. Just what I was looking for. I also found an article on the web site that said that you can set port parameters as long as a process has the port open. You also mentioned that in your earlier response. I came up with the following and its working for me.
First, I opened the port via 'cu -ltty0p0' and then ran 'stty -g I then closed the cu session and opened the port via 'cat < /dev/tty0p0'.
Then I ran 'stty $port_settings < /dev/tty0p0' where port_settings was the string returned from 'stty -g'. This set the port parameters the same as 'cu'.
I was then able to 'echo $string > /dev/tty0p0' and see the output in the window I was running 'cat' in.
Not the cleanest way to do things but it's working.
I'm going to compile the holdport program and try that out next. Thanks again.
Email: michael.n.daulerio@lmco.com
Darren Prior
Honored Contributor

Re: Automating I/O over a serial port

Hi,

An alternative to the other good suggestions above is to use Kermit. You don't have to use other programs, it's already installed on your systems and you don't need to worry about stty settings.

Initially you can just run Kermit and manually step through the commands to configure the port and send the text commands to your switch. When you're happy with this, put the commands into a file and run kermit -y

regards,

Darren.
Calm down. It's only ones and zeros...
Michael D'Aulerio
Regular Advisor

Re: Automating I/O over a serial port

Thanks Darren. I'll have to try kermit. I also found a program called 'expect' that lets you set up batch files. It requires Tcl/Tk version 8.2 or newer. Works pretty well.
Email: michael.n.daulerio@lmco.com