[Tutor] Re: Where best to start? First program to: login, read from and close a serial line?

Derrick 'dman' Hudson dman@dman.ddts.net
Mon, 10 Jun 2002 21:06:08 -0500


--DIOMP1UsTsWJauNi
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Jun 09, 2002 at 11:22:55PM -0700, Bill Gillespie wrote:
| Hi Folks,
|=20
| I was very happy to find this resource. I'm a new guy and am just
| starting to learn to do some simple programming, and Python is my first
| "real programming" language. It's very exciting!
|=20
| My first programming project:=20
| At work we have a "floor and oil temperature control system". I would
| like to build a simple GUI, allowing us to interrogate, display and
| change these two values:=20
|=20
| 1) OIL set point=20
| 2) FLOOR set point
|=20
|=20
| The Tkinter (GUI) part looks learnable - but I don't know where to
| start in terms of=20
|=20
| --> logging into a remote machine=20
|           (in Xterm from a Linux machine - to a sun os machine)

What program do you usually use?  telnet?  ssh? =20

In unix-land it is really easy to piggy back off of stuff like this.
For example if you are using telnet, you can open a pipe to it like
this :

import os
tpipe_in , tpipe_out =3D os.popen2( [ "/usr/bin/telnet" , "the.host.name" ]=
 )

which gives you 2 file-like objects -- tpipe_in and tpipe_out -- which
are connected to the stdin and stdout of the telnet program.  In this
manner your python program can act just a like a person sitting at the
machine running telnet.

|   --> opening a serial line on it
|           (I normally just type "tip oftc" to connect <oil floor and  =20
|         temp cont>)

Opening a device (such as a serial port) is easy in unix.  I wrote a
(simple!) daemon a while ago to log data read from the serial port.
To open the serial port, use

the_port =3D open( "/dev/ttyS0" , "r+" )

(note: this opens the device on the local machine)

If you are using a command that you invoke through telnet, just feed
the text through the pipe you opened above.
=20
|    --> interrogating the embedded device on it,
|           (two seperate commands ask for current - or order a change) =20

If this is just a mattter of sending some text (command) and then
reading the output (text) back, just use the pipe you opened above.
It's as simple as working with plain old files on the local disk.
=20
|     --> and then logging out again.
|           ($. closes the connection) then I log out of the machine)

Send the sequence "$.\n" to the pipe's input, send the logout command,
and close both ends of the pipe.
=20
| Any advice on the general idea of what should take place will be most
| welcome.=20

Unix was well designed around the use of files and pipes.  Working
with a pipe is just as easy as working with any other file, and so is
working with various devices (such as the serial port) and network
sockets.  Read some UNIX texts on pipes and files to get a better
handle on that.

I would start with a simple console-based system.  You could have it
be interactive, or even just too dumb to do more than one thing.
Experiment with it and see how to get everything working and how to do
decent error handling.  As you get a better handle on that, build it
up to having a full GUI or whatever is actually necessary.  (GUI's are
complex, and if you can keep it down to a simple command line you'll
be better off, IMO)
=20
HTH,
-D

--=20

An anxious heart weighs a man down,
but a kind word cheers him up.
        Proverbs 12:25
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


--DIOMP1UsTsWJauNi
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj0FWxAACgkQO8l8XBKTpRQbmQCgk+kf/7MbGH7nefKPv3+QZACr
N+0An0zLY3FDf4wv1USlUh02XJvnlGSt
=n5pW
-----END PGP SIGNATURE-----

--DIOMP1UsTsWJauNi--