[Tutor] question about serial coms
remailer at ka3nam.com
Tue Nov 15 04:43:01 CET 2005
I think so, what I'm doing is opening a text file,
reading line 1 and writing that text to the serial
port. Then read line 2 and so on... So it mimics a
string rather than a list or dictionary. But I would
think this would give you a similiar result. I can try
it to confirm.
Here is the entire code:
parmfile = open('command_1.txt')
ser = serial.Serial('/dev/ttyS1', 9600, timeout=1)
i = 0
while i == 0:
line = parmfile.readline()
line = string.rstrip(line)
if line == "":
i = 1
ser.write(line + "\r")
print "Sending: " + line
data_in = ser.read(100)
print "Response: " + data_in
print "Closing Serial Port\n"
The 'command_1.txt' file is literally a text file with
lines of text like such:
--- Hans Dushanthakumar
<Hans.Dushanthakumar at navman.com> wrote:
> Just to make sure that I understood it right,
> Does this snippet mimic the problem that you have?
> Ive hardcoded "line".
> import serial
> import time
> line = ["Hi","There","Hans"]
> while i <= (len(line)-1):
> ser.write(line[i] + "\r")
> print "Sending: " + line[i]
> data_in = ser.read(100)
> print "Response: " + data_in
> i = i + 1
> print "Closing Serial Port\n"
More information about the Tutor