1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| import time
import sys
import serial, glob
import Tkinter as tk
from socket import *
IP = "0.0.0.0"
MODE = "Unknow"
ports = glob.glob('/dev/ttyA*') + glob.glob('/dev/ttyU*')
print "ports trouves:",ports
def find_tibbo():
s = socket(AF_INET, SOCK_DGRAM) #UDP with DGRAM
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
s.sendto('X', ('<broadcast>', 65535))
data , addr = s.recvfrom(1024)
print "RECU: ", data, " depuis:",addr #pour debug
s.close()
return addr[0]
def do_find_tibbo():
'''dans ce cas, on récupère la variable par son nom tk'''
ip = find_tibbo()
ip_label.config(text=ip)
def find_mod(IP):
print "l'IP passee est:",IP
s = socket(AF_INET, SOCK_STREAM) #TCP with STREAM
s.connect((IP,10001))
time.sleep(.1)
s.send("MODE?\n")
time.sleep(.1)
mode = s.recv(1024)
print mode
s.close()
return mode
def do_find_mode():
''' on récupère la variable par son nom tk '''
# print IP n'afficherait que la variable globale 0.0.0.0
# print "the label is", ip_label.cget("text") ca, ca marche
mod = find_mod(ip_label.cget("text"))
mod_label.config(text=mod)
def send_value(value):
IP = ip_label.cget("text")
s = socket(AF_INET, SOCK_STREAM) #TCP with STREAM
s.connect((IP,10001)) #port 10001
time.sleep(.05)
s.send("ATT 0 "+ value +"\n")
print "0 fait"
s = socket(AF_INET, SOCK_STREAM) #TCP with STREAM
s.connect((IP,10002)) #port 10002
time.sleep(.05)
s.send("ATT 1 "+ value +"\n")
print "1 fait"
s = socket(AF_INET, SOCK_STREAM) #TCP with STREAM
s.connect((IP,10003)) #port 10003
time.sleep(.05)
s.send("ATT 2 "+ value +"\n")
print "2 fait"
s = socket(AF_INET, SOCK_STREAM) #TCP with STREAM
s.connect((IP,10004)) #port 10004
time.sleep(.05)
s.send("ATT 3 "+ value +"\n")
print "3 fait" + value
s.close()
def value5():
send_value("005")
def value10():
send_value("010")
def sortie():
app.destroy()
def readserie():
#print "je lis\n"
ser =serial.Serial('/dev/ttyAMA0',9600,timeout=1)
string = ser.read(10)
if len(string) != 0:
print (string)
if __name__ == '__main__': #
app = tk.Tk()
app.geometry('400x400+800+300')
app.title('subrack controler')
tk.Label(text='Search for IP address').place(x=18,y=15)
ip_label = tk.Label(text=IP) # l'adresse IP
ip_label.place(x=250,y=15)
tk.Button(text = 'Go',command=do_find_tibbo ,fg = "blue").place(x=200,y=10)
tk.Label(text='Search for mode').place(x=18,y=45)
mod_label = tk.Label(text=MODE)
mod_label.place(x=250,y=45)
tk.Button(text= 'Go',command=do_find_mode ,fg = "blue").place(x=200,y=40)
tk.Label(text='send 0.5dB').place(x=18,y=75)
tk.Button(text= 'Go',command=value5 ,fg = "red").place(x=200,y=70)
tk.Label(text='send 1.0dB').place(x=18,y=105)
tk.Button(text= 'Go',command=value10 ,fg = "red").place(x=200,y=100)
tk.Button(text= 'QUIT',command=sortie).place(x=195,y=340)
app.after(500,readserie)
tk.mainloop() |