All pastes #396387 Raw Edit

Stuff

public text v1 · immutable
·published 2007-03-15 18:38 UTC
rendered paste body
#! /usr/bin/env python
from struct import *
from Tkinter import *
import os
import struct
from ctypes import *
#from ctypes import byref
import numpy
#------------ leave it alone for now -------------
rtf0=open('/dev/rtf0','w')
#-------------------------------------------------

#typedef struct {
#  enum etype command;
#  int command_num;		/* identifies command 	*/
#  int freq;			/* for STEPPERS_FREQ 	*/
#  unsigned int steps_x;		/* step da fare		*/
#  unsigned int steps_y;
#  unsigned int steps_z;
#  unsigned int steps_a;
#  unsigned char dir;		/* byte con le direzioni x y z a 	*/
#} COMMAND_STRUCT;

format='20piiiiiii'
class App:

    def __init__(self, master):

	self.bit_dir_x = IntVar()
	self.bit_dir_y = IntVar()
	self.bit_dir_z = IntVar()
	self.bit_dir_a = IntVar()
	self.command_stepper_on = IntVar()
	self.command_stepper_go = IntVar()
        
#Struttura del comando inviato al modulo via FIFO	
	self.command = StringVar()
	self.command.set("STEPPERS_OFF")
	self.command_num = IntVar()
	self.command_num.set(1)
	self.step_x = IntVar()
	self.step_x.set(10010)
	self.step_y = IntVar()
	self.step_y.set(2340)
	self.step_z = IntVar()
	self.step_z.set(56670)
	self.step_a = IntVar()
	self.step_a.set(5320)
	self.direction = IntVar()
	self.direction.set(7)
	
        frame = Frame(master)
        frame.pack(fill=X)
	
	self.lbl_freq = Label(frame, text="Frequenza = ").grid(row=0, column=0)
	self.frequenza = IntVar()
	self.frequenza.set(10000)
        self.entry_freq = Entry(frame,textvariable=self.frequenza).grid(row=0, column=1)
	#self.entry_freq=StringVar()
	#self.entry_freq.insert(self,"0")
	
	self.hi_there = Checkbutton(frame, text="ON",variable=self.command_stepper_on, indicatoron=0,command=self.on).grid(row=0, column=2)
	
	self.lbl_step_x = Label(frame, text="Step X = ").grid(row=1, column=0)
        self.entry_step_x = Entry(frame,textvariable=self.step_x).grid(row=1, column=1)

	self.dir_x = Checkbutton(frame, text="Dir X",variable=self.bit_dir_x, indicatoron=0, command=self.command_dir_x).grid(row=1,column=2)
	
	self.lbl_step_y = Label(frame, text="Step Y = ").grid(row=2, column=0)
        self.entry_step_y = Entry(frame,textvariable=self.step_y).grid(row=2, column=1)
	self.dir_y = Checkbutton(frame, text="Dir Y",variable=self.bit_dir_y, indicatoron=0, command=self.command_dir_y).grid(row=2,column=2)
	
	self.lbl_step_z = Label(frame, text="Step Z = ").grid(row=3, column=0)
        self.entry_step_z = Entry(frame,textvariable=self.step_z).grid(row=3, column=1)
	self.dir_z = Checkbutton(frame, text="Dir Z",variable=self.bit_dir_z, indicatoron=0, command=self.command_dir_z).grid(row=3,column=2)
	
	self.lbl_step_a = Label(frame, text="Step A = ").grid(row=4, column=0)
        self.entry_step_a = Entry(frame,textvariable=self.step_a).grid(row=4, column=1)
	self.dir_a = Checkbutton(frame, text="Dir A",variable=self.bit_dir_a, indicatoron=0, command=self.command_dir_a).grid(row=4,column=2)
 		
        self.hi_there = Button(frame, text="GO!",command=self.go).grid(row=5, column=2)
	
	self.button = Button(frame, text="QUIT", fg="red", command=self.esci).grid(row=5, column=0)

    def go(self):
        print "Ramp running"
	self.command.set("STEPPERS_GO")
	self.update()
	
    def esci(self):
	rtf0.close()
	root.destroy()
	
    def on(self):
	if self.command_stepper_on.get()== 1:
	  self.command.set("STEPPERS_ON")
          print "Steppers ON"
	  self.update()
	else:
	  print "Steppers OFF"
	  self.command.set("STEPPERS_OFF")
	  self.update()

    def command_act(self):
	RawData=struct.pack(format, self.command.get(), self.command_num.get(), self.frequenza.get(), self.step_x.get(), self.step_y.get(), self.step_z.get(), self.step_a.get(), self.direction.get())
	#print "RawData = ", RawData
  	rtf0.write(RawData)

    def command_dir_x(self):
	self.update()
	
    def command_dir_y(self):
	self.update()

    def command_dir_z(self):
	self.update()	

    def command_dir_a(self):
	self.update()
		
    def update(self):
	self.direction.set(self.bit_dir_x.get() +(self.bit_dir_y.get()*2) +(self.bit_dir_z.get()*4) +(self.bit_dir_a.get()*8))
	self.command_act()
        print "Direzione = ", self.direction.get()
	print "Frequenza = ", self.frequenza.get()
	print "Motori = ", self.command.get()
	print "Dir x = ", self.bit_dir_x.get()
	print "Step x = ", self.step_x.get()
	print "Dir y = ", self.bit_dir_y.get()
	print "Step y = ", self.step_y.get()
	print "Dir z = ", self.bit_dir_z.get()
	print "Step z = ", self.step_z.get()
	print "Dir a = ", self.bit_dir_a.get()
	print "Step a = ", self.step_a.get()
	print " "
	
root = Tk()

app = App(root)

root.mainloop()