Replace ser_one.py

This commit is contained in:
jens 2021-11-29 19:25:22 +00:00
parent 03371143cd
commit ba13effe19

View File

@ -3,7 +3,8 @@ from tkinter.constants import W, X
import serial.tools.list_ports
import functools
import tkinter.ttk as ttk
from configparser import ConfigParser
import os
import labrobot as lrb
@ -81,7 +82,8 @@ b6.grid(row=2,column=0,sticky='nw')
b7 = ttk.Button(uprightframe,text='Get Position',width=12)
b7.grid(row=2,column=1,sticky='ne')
l1 = ttk.Label(uprightframe,text="Enter G-Code").grid(row=3,column=0)
e1 = ttk.Entry(uprightframe).grid(row=3,column=1)
e1 = ttk.Entry(uprightframe)
e1.grid(row=3,column=1)
b5 = ttk.Button(uprightframe,text='Send Code')
b5.grid(row=4,column=1,sticky="ne")
@ -91,29 +93,89 @@ b9 = ttk.Button(downrightframe,text='Up')
b9.grid(row=0,column=1,sticky='ne')
b10 = ttk.Button(downrightframe,text='Down')
b10.grid(row=0,column=2,sticky='ne')
b11 = ttk.Button(downrightframe,text='Top')
b11.grid(row=1,column=0,sticky='ne')
b13 = ttk.Button(downrightframe,text='Load')
b13.grid(row=1,column=1,sticky='ne')
b12 = ttk.Button(downrightframe,text='Dispense')
b12.grid(row=1,column=2,sticky='ne')
b14 = ttk.Button(downrightframe,text='Take Chem')
b14.grid(row=2,column=0,sticky='ne')
### Parts
###################### Parts
## init Labrobot
pip = lrb.LabPip(vol=1000,top=22)
pip.fe =5000
xoffset = tk.DoubleVar()
xoffset.set(15)
yoffset = tk.DoubleVar()
yoffset.set(1.6)
rows = tk.IntVar()
rows.set(5)
cols = tk.IntVar()
cols.set(10)
xspace = tk.DoubleVar()
xspace.set(10.8)
yspace = tk.DoubleVar()
yspace.set(18.3)
tipvol = tk.IntVar()
tipvol.set(1000)
zlevel = tk.DoubleVar()
tipup = tk.DoubleVar()
tiphub = tk.DoubleVar()
tipspeed = tk.IntVar()
akttip = tk.IntVar()
lpb = lrb.LabPipBlock(xoffset.get(),1,70,50,5,108,86)
chemX = tk.DoubleVar()
chemY = tk.DoubleVar()
chemVol = tk.DoubleVar()
chemZ = tk.DoubleVar()
deltaz = tk.DoubleVar()
tauch = tk.DoubleVar()
def conf_read():
config = ConfigParser()
config.read(os.path.join(os.path.dirname(__file__), "config.ini"),)
xoffset.set(float(config.get('tipblock','xoffset',fallback=0)))
yoffset.set(float(config.get('tipblock','yoffset',fallback=0)))
rows.set(int(config.get('tipblock','rows',fallback=0)))
cols.set(int(config.get('tipblock','cols',fallback=0)))
xspace.set(float(config.get('tipblock','xspace',fallback=0)))
yspace.set(float(config.get('tipblock','yspace',fallback=0)))
tipvol.set(int(config.get('tipblock','tipvol',fallback=0)))
zlevel.set(float(config.get('tipblock','zlevel',fallback=0)))
tipup.set(float(config.get('tipblock','tipup',fallback=0)))
tiphub.set(float(config.get('tipblock','tiphub',fallback=0)))
tipspeed.set(int(config.get('tipblock','tipspeed',fallback=0)))
chemX.set(float(config.get('chemblock','chemx',fallback=0)))
chemY.set(float(config.get('chemblock','chemy',fallback=0)))
chemVol.set(float(config.get('chemblock','chemvol',fallback=0)))
chemZ.set(float(config.get('chemblock','chemz',fallback=0)))
deltaz.set(float(config.get('chemblock','deltaz',fallback=0)))
tauch.set(float(config.get('chemblock','tauch',fallback=0)))
def conf_write():
config = ConfigParser()
config.read(os.path.join(os.path.dirname(__file__), "config.ini"),)
config.set('tipblock','xoffset',str(xoffset.get()))
config.set('tipblock','yoffset',str(yoffset.get()))
config.set('tipblock','rows',str(rows.get()))
config.set('tipblock','cols',str(cols.get()))
config.set('tipblock','xspace',str(xspace.get()))
config.set('tipblock','yspace',str(yspace.get()))
config.set('tipblock','tipvol',str(tipvol.get()))
config.set('tipblock','zlevel',str(zlevel.get()))
config.set('tipblock','tipup',str(tipup.get()))
config.set('tipblock','tiphub',str(tiphub.get()))
config.set('tipblock','tipspeed',str(tipspeed.get()))
config.set('chemblock','chemx',str(chemX.get()))
config.set('chemblock','chemy',str(chemY.get()))
config.set('chemblock','chemvol',str(chemVol.get()))
config.set('chemblock','chemz',str(chemZ.get()))
config.set('chemblock','deltaz',str(deltaz.get()))
config.set('chemblock','tauch',str(tauch.get()))
with open(os.path.join(os.path.dirname(__file__), "config.ini"),'w') as f:
config.write(f)
conf_read()
lpb = lrb.LabPipBlock(xoffset.get(),yoffset.get(),zlevel.get(),rows.get(),cols.get(),xspace.get(),yspace.get())
pip = lrb.LabPip(vol=tipvol.get(),top=tipup.get(),hub=tiphub.get(),fe=tipspeed.get())
chem = lrb.ChemLoc(chemX.get(),chemY.get(),chemZ.get(),chemVol.get(),deltaz.get(),tauch.get())
partframe = ttk.Frame(notebook)
#partframe.rowconfigure(0,weight=1)
@ -140,16 +202,82 @@ pe5.grid(column=1,row=5,sticky='e')
pl6 = ttk.Label(pipblockframe,text='Y offset').grid(column=0,row=1,padx=5)
pe6 = ttk.Entry(pipblockframe,textvariable=yoffset)
pe6.grid(column=1,row=1,sticky='e')
ttk.Separator(pipblockframe, orient=tk.HORIZONTAL).grid(row=6,sticky='ew')
pl7 = ttk.Label(pipblockframe,text='Tip Volume').grid(column=0,row=7,padx=5)
pl8 = ttk.Label(pipblockframe,text='Z uptake').grid(column=0,row=6,padx=5)
pe8 = ttk.Entry(pipblockframe,textvariable=zlevel)
pe8.grid(column=1,row=6,sticky='e')
ttk.Separator(pipblockframe, orient=tk.HORIZONTAL).grid(row=7,sticky='ew')
pl7 = ttk.Label(pipblockframe,text='Tip Volume').grid(column=0,row=8,padx=5)
pe7 = ttk.Entry(pipblockframe,textvariable=tipvol)
pe7.grid(column=1,row=7,sticky='e')
pe7.grid(column=1,row=8,sticky='e')
pl9 = ttk.Label(pipblockframe,text='Tip Top').grid(column=0,row=9,padx=5)
pe9 = ttk.Entry(pipblockframe,textvariable=tipup)
pe9.grid(column=1,row=9,sticky='e')
pl10 = ttk.Label(pipblockframe,text='Tip Hub').grid(column=0,row=10,padx=5)
pe10 = ttk.Entry(pipblockframe,textvariable=tiphub)
pe10.grid(column=1,row=10,sticky='e')
pl11 = ttk.Label(pipblockframe,text='Tip Speed').grid(column=0,row=11,padx=5)
pe11 = ttk.Entry(pipblockframe,textvariable=tipspeed)
pe11.grid(column=1,row=11,sticky='e')
ttk.Separator(pipblockframe, orient=tk.HORIZONTAL).grid(row=80,sticky='ew')
pl12 = ttk.Label(pipblockframe,text='Akt Tip').grid(column=0,row=81,padx=5)
pe12 = ttk.Entry(pipblockframe,textvariable=akttip)
pe12.grid(column=1,row=81,sticky='e')
ttk.Separator(pipblockframe, orient=tk.HORIZONTAL).grid(row=98,sticky='ew')
pb1 = ttk.Button(pipblockframe,text='Set')
pb1.grid(column=0,row=99,sticky='e')
pb2 = ttk.Button(pipblockframe,text='Save')
pb2.grid(column=1,row=99,sticky='w')
chemframe =ttk.LabelFrame(partframe,text='Chemicals')
chemframe.grid(column=1,row=0,sticky='wns',padx=5,pady=5)
cl1 = ttk.Label(chemframe,text='X pos').grid(column=0,row=0,padx=5)
ce1 = ttk.Entry(chemframe,textvariable=chemX)
ce1.grid(column=1,row=0,sticky='e')
cl2 = ttk.Label(chemframe,text='Y pos').grid(column=0,row=1,padx=5)
ce2 = ttk.Entry(chemframe,textvariable=chemY)
ce2.grid(column=1,row=1,sticky='e')
cl3 = ttk.Label(chemframe,text='Z Surface').grid(column=0,row=2,padx=5)
ce3 = ttk.Entry(chemframe,textvariable=chemZ)
ce3.grid(column=1,row=2,sticky='e')
cl4 = ttk.Label(chemframe,text='Volume').grid(column=0,row=3,padx=5)
ce4 = ttk.Entry(chemframe,textvariable=chemVol)
ce4.grid(column=1,row=3,sticky='e')
cl5 = ttk.Label(chemframe,text='DeltaZ/ml').grid(column=0,row=4,padx=5)
ce5 = ttk.Entry(chemframe,textvariable=deltaz)
ce5.grid(column=1,row=4,sticky='e')
### commands and bindings
pb2.config(command=conf_write)
def set_tipblock():
global lpb
lpb.xoffset = float(xoffset.get())
lpb.yoffset = float(yoffset.get())
lpb.rows = int(rows.get())
lpb.columns = int(cols.get())
lpb.deltax = float(xspace.get())
lpb.deltay = float(yspace.get())
lpb.z = float(zlevel.get())
lpb.akt = int(akttip.get())
global pip
pip.vol = int(tipvol.get())
pip.hub = float(tiphub.get())
pip.fe = int(tipspeed.get())
pip.top = float(tipup.get())
global chem
chem.xloc = float(chemX.get())
chem.yloc = float(chemY.get())
chem.vol = float(chemVol.get())
chem.zloc = float(chemZ.get())
chem.deltaz = float(deltaz.get())
chem.tauch = float(tauch.get())
pb1.config(command=set_tipblock)
def homeAll():
serialObj.write(b'<G28>\n')
b1.configure(command=homeAll)
def homeX():
@ -190,10 +318,37 @@ b10.configure(command=downTip)
def nextTip():
upTip()
serialObj.write(pip.get_tip(lpb.next()).encode('utf-8'))
akttip.set(lpb.akt)
downTip()
b8.configure(command=nextTip)
def load():
serialObj.write(pip.go_top().encode('utf-8'))
serialObj.write(pip.go_down().encode('utf-8'))
serialObj.write(pip.go_top().encode('utf-8'))
b13.config(command=load)
def dispense():
serialObj.write(pip.go_down().encode('utf-8'))
b12.config(command=dispense)
def top():
serialObj.write(pip.go_top().encode('utf-8'))
b11.config(command=top)
def takeChem():
print(chem.getXY())
pip.setXY(chem.getXY())
serialObj.write(pip.sendXY().encode('utf-8'))
pip.setZ(chem.load(1))
serialObj.write(pip.down().encode('utf-8'))
serialObj.write(pip.go_top().encode('utf-8'))
upTip()
b14.config(command=takeChem)
def checkSerialPort():
if serialObj.isOpen() and serialObj.in_waiting:
recentPacket = serialObj.readline()
@ -201,6 +356,7 @@ def checkSerialPort():
txt.insert('0.1',recentPacketString,'small')
while True:
root.update()
checkSerialPort()