Newbie - help request with serial line (termios?) setup in Python 2.2
Bill Gillespie
billintucson at yahoo.com
Sun Aug 4 01:44:33 EDT 2002
Chris Liechti <cliechti at gmx.net> wrote in message news:<Xns9258CF6662B33cliechtigmxnet at 62.2.16.82>...
> billintucson at yahoo.com (Bill Gillespie) wrote in
> news:4860ce4f.0207271004.4cbc8880 at posting.google.com:
> > I'm trying to open a serial line on a SunOs using python 2.2.
> > I'm new to programming, and fairly new to unix/linux. I have the two
> > pink Oreilly Python books and have read a couple of tutorials - but I
> > am a newbie.
>
> welcome
>
> > After much googling (there is not a lot of novice python/unix/termios
> > info out there) - this is what I think? I should be doing....
> >
> > Open the line
> > Configure the line? termios??
> > Communicate with the line (ASCII charachters < > at 4800)
> > Close the line
>
> ok, i make it short... you could use my library http://pyserial.sf.net
> if, for some reason, you still want to do it by hand, you can at least look
> at the sources.
>
> (you may need to specify the port by name:
> s = serial.Serial('/dev/ttyC43', baudrate=4800, timeout=1))
>
> chris
I had some great help from the author of PySerial on this. There was
no
need to interact with termios at all. All I had to do was install this
module (PySerial) and set up my serial line with the proper:
buad rate,
stop bits,
and
data bits,
Anyone who needs to interact with a serail line using linux as I am -
can use this very helpful module (PySerial).
Links and a code example of the interaction I had - below....
------------------------------------------------------------
Web site:
http://pyserial.sourceforge.net/
(setup and usage help overview)
CVS repository:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/pyserial/pyserial/
************************************************************************
Setting up and opening the serial line on a Sun:
ser=serial.Serial('/dev/ttyC43', 4800, 7,1,timeout=1) for cin ttyC43
ser=serial.Serial('/dev/ttyC43', 4800, timeout=1) for cin ttya
************************************************************************
>>> import serial
>>>
>>> ser=serial.Serial('/dev/ttyC43', 4800, 7,1,timeout=1)
>>>
>>> ser.write('dump_oftc\r')
>>>
>>> ser.readlines(400)
['dump_oftc 116 150 99 168 304 XXX 175 242 166 174
172 173 163 234 233 236 OK\r\n']
>>>
>>>
>>>
>>> ser.write('oftv\r')
>>>
>>> ser.readlines(400)
['oftv \r\n', 'OGS OGR OXS OXR OPR OSP AMB spr tb1\r\n', '58 74
97 167 152 40 172 238 cp=234 \r\n', '\r\n', 'FGS FGR FT1 FT2
FT3 spr spr spr tb2\r\n', '82 87 168 174 161 231 234 237
cp=241 \r\n', '\r\n', 'OK\r\n']
....................................
finding the current set point for oil
.....................................
>>> ser.write('osetpoint?')
>>>
>>> ser.write('\r')
>>>
>>> ser.readlines(400)
['osetpoint? 5 OK\r\n']
>>>
.......................................
Finding the current setpoint for floor
......................................
>>> ser.write('fsetpoint?')
>>>
>>> ser.write('\r')
>>>
>>> ser.readlines(400)
['fsetpoint? -5 OK\r\n']
......................................
end code examples....
Many thanks to Chris Liecht for his help,
and making this software available!
Cheers,
Bill
More information about the Python-list
mailing list