[Tutor] My serial prog and prob
Deirdre Hackett
Deirdre Hackett" <deirdrehac@lycos.co.uk
Thu Feb 6 10:46:01 2003
This is a multi-part message in MIME format.
------=_NextPart_000_009B_01C2CDF7.6B776C40
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
This is a profram to read in a string from the serial port. I want to take
in the information and store if (for the moment ) in an array of some type.
I am getting bogged down and can't move forward.
I would appreciate any advice on where i am going wrong.
The data comes in as
' - 2345 4565 - 5678 '
Thanks Deirdre
------=_NextPart_000_009B_01C2CDF7.6B776C40
Content-Type: text/plain;
name="tkinter4.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="tkinter4.txt"
from Tkinter import *
from threading import *
import timer
import time
import array
from Numeric import *
import serial
root = Tk()
ser = serial.Serial(0, timeout=1)
data = []
def send():
ser.write("*99p\r")
def take_in_data():
xinput = ""
yinput = ""
zinput = ""
input = ser.readline()
xinput = input[:9]
yinput = input[9:18]
zinput = input[18:27]
xsplit = xinput.split()
ysplit = yinput.split()
zsplit = zinput.split()
x2string = ""
for n in range(len(xsplit)):
x2string += xsplit[n]
y2string = ""
for n in range(len(ysplit)):
y2string += ysplit[n]
z2string = ""
for n in range(len(zsplit)):
z2string += zsplit[n]
if x2string > 3:
xcommasplit = x2string.split(',')
if y2string > 3:
ycommasplit = y2string.split(',')
if z2string > 3:
zcommasplit = z2string.split(',')
x3string = ""
for n in range(len(xcommasplit)):
x3string += xcommasplit[n]
y3string = ""
for n in range(len(ycommasplit)):
y3string += ycommasplit[n]
z2string = ""
for n in range(len(zcommasplit)):
z3string += zcommasplit[n]
data.append(int(x2string))
data.append(int(y2string))
data.append(int(z2string))
#data.append(input)
for n in range(10):
t = Timer(0.05, send)
t.start()
#print n
a = Timer(0.05, take_in_data)
a.start()
#print input
#for b in range(10):
#print data[b]
ser.close()
root.mainloop()
------=_NextPart_000_009B_01C2CDF7.6B776C40--