EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  <19971998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  <19971998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: EPICS Channel Access in Python.
From: [email protected] (Noboru Yamamoto)
To: [email protected]
Date: Wed, 4 Jun 1997 21:18:03 +0900
Hi,

 Enclosed is a sample python program which displays windows on X-terminal.
Each window has a slider and a label which are both connected to EPICS channel.

 I also enclosed ca.py which implements EPICS channel class in python. ca.py
uses _ca module which are written in C. Python can retuns any value, includig
list called tuple in Python, as a return value of get().
Development status is quite preliminary but(or because of it) I appriciate
your comments.

Thank you,

Noboru Yamamoto
KEK, Accelerator Lab.
Noboru Yamamoto
KEKB Accelerator Control Group
KEK, JAPAN
Fax:+81-298-64-0321
Tel:+81-298-64-5309
e-mail:[email protected]
#
import ca
from Tkinter import *

class Simple(ca.channel,Frame):
	def __init__(self,name,master=None,*cnf):
		Frame.__init__(self,master)
		self.pack(expand=1,fill='both')
		ca.channel.__init__(self,name);self.pendio(0.1)
		self.get();self.pendio()
		l=Label(self,text="CA readback")
		l.pack()
		s=Scale(self,orient="horizontal",label=name)
		s.pack(expand=1,fill='x')
		s.set(self.val)
		b=Button(self,text="Quit",command=self.quit,text=`self.val`)
		b.pack()
		self.s=s
		self.b=b
		self.l=l
		self.monitor(self.update_scale)
		self.monitor(self.update_label)
		self.pendio()
		self.s.config(command=self.scale_change)

	def repeater(self): # in-efficient compared to alarm routin in C
		self.pendio(0.0005)
		self.after(20,self.repeater)		
	
	def scale_change(self,arg):
		v=self.s.get()
		if( v <> self.val):
			self.put(v)
			self.pend_event(0.0005)

	def update_label(self,val):
		self.val,self.stat=val
		self.l.config(text=`self.val`)

	def update_scale(self,val):
		self.val,self.stat=val
		self.s.set(self.val)

if(__name__ == "__main__"):
	Simple("FFTB:WS2",master=Tk())
	Simple("FFTB:WS3",master=Toplevel())
	Simple("FFTB:WS1",master=Toplevel()).mainloop()


import _ca

pendio=_ca.pendio #export pendio 
pend_event=_ca.pend_event
flush_io=_ca.flush

class channel:
	def __init__(self,name):
		self.chid=_ca.search(name)
		self.val=0.0
		self.evid=[]

	def __del__(self):
		self.clear_monitor()
		_ca.clear(self.chid)
		_ca.pendio(1.0)	

	def get(self):
		_ca.get(self.chid, self.update_val)

	def put(self,val=None):
		_ca.put(self.chid,val,self.val)

	def monitor(self,callback=None):
		if(not callback):
			raise No_Callback_Error
		self.callback=callback
 		self.evid.append(_ca.monitor(self.chid,self.callback))

	def clear_monitor(self,evid=None):
		if(not evid):
			for i in self.evid:
				print "clearing evid",i
				_ca.clear_monitor(i)
			self.evid=[]
		else:
			_ca.clear_monitor(evid)
		
	def pendio(self,wait=0.0005):
		_ca.pendio(wait)

	def pend_event(self,wait=0.0005):
		_ca.pend_event(wait)

	def flush(self,wait=0.0005):
		_ca.flush(wait)

	def update_val(self,valstat):
 		self.val,self.status=valstat

	def exec_callback(self,val):
		self.callback(self,val)





Replies:
Re: EPICS Channel Access in Python. Nick Patavalis

Navigate by Date:
Prev: Re: EDD/DM: Passing multiple arguments for color rule definition ? Deb Kerstiens
Next: Continous feedback control for stepper motors Benjamin Franksen
Index: 1994  1995  1996  <19971998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: EDD/DM: Passing multiple arguments for color rule definition ? Anna M. Estes
Next: Re: EPICS Channel Access in Python. Nick Patavalis
Index: 1994  1995  1996  <19971998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 10 Aug 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·