[Tutor] serial connection was: adding a listbox

Deirdre Hackett Deirdre Hackett" <deirdrehac@lycos.co.uk
Mon Feb 24 11:12:01 2003


This is a multi-part message in MIME format.

------=_NextPart_000_00ED_01C2DC20.20F53440
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Are you a windows user?
I suppose I shouldn't have presumed you were.
I used this module myself for my own project.
I downloaded python 2.2.
I also downloaded Mark Hammond's win32 extension from
http://starship.python.net/crew/mhammond/
and then download the pyserial module which can be found
at: http://sourceforge.net/project/showfiles.php?group_id=46487
Then follow the instructions on: http://pyserial.sourceforge.net/

Install them in the order they are above and the code I gave earlier should
work.
I have attached a program that although should not do anything for you
should at least give you an idea.
Hope I have been clear and that it works out for you.
Deirdre

------=_NextPart_000_00ED_01C2DC20.20F53440
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_00ED_01C2DC20.20F53440--