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:

import serial
import string
import time

parmfile = open('command_1.txt')

ser = serial.Serial('/dev/ttyS1', 9600, timeout=1)
ser.setRTS(1)
ser.setDTR(1)

i = 0
while i == 0:
  line = parmfile.readline()
  line = string.rstrip(line)
  #print line
  if line == "":
    i = 1
    break
  
  else:
    
    ser.write(line + "\r")
    #ser.write("\r\n")
    print "Sending: " + line

    
   
    time.sleep(1)
    data_in = ser.read(100)
    print "Response: " + data_in
    time.sleep(.2)
    
    
print "Closing Serial Port\n"    
ser.close()
  

The 'command_1.txt' file is literally a text file with
lines of text like such:

command1 on
command2 off
command3 %4
command5 on

etc....



-Joe

  

--- Hans Dushanthakumar
<[EMAIL PROTECTED]> wrote:

> Just to make sure that I understood it right,
> 
> Does this snippet mimic the problem that you have?
> Ive hardcoded "line".
> 
> ========x=================
> import serial
> import time
> ser=serial.Serial(0,57600,timeout=0.1)
> i=0
> line = ["Hi","There","Hans"]
> while i <= (len(line)-1):
>     
>     ser.write(line[i] + "\r")
>     print "Sending: " + line[i]
>     time.sleep(1)
>     data_in = ser.read(100)
>     print "Response: " + data_in
>     time.sleep(.2)
>     i = i + 1
>     
> print "Closing Serial Port\n"    
> ser.close()
> =========x============================= 
> 
> Cheers
> Hans

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to