Presentation is loading. Please wait.

Presentation is loading. Please wait.

16th Oct 08 Tom Cobb - Python at DLS 1 Uses of Python at Diamond Light Source.

Similar presentations


Presentation on theme: "16th Oct 08 Tom Cobb - Python at DLS 1 Uses of Python at Diamond Light Source."— Presentation transcript:

1 16th Oct 08 Tom Cobb - Python at DLS 1 Uses of Python at Diamond Light Source

2 16th Oct 08 Tom Cobb - Python at DLS 2 Content Python in IOCs –Simulations for Asyn Drivers Python in Client Applications –CA Bindings –PyQt GUI Design Python in the Build System –EDM Screen Builder –Dependency Checker –Future Developments

3 16th Oct 08 Tom Cobb - Python at DLS 3 Simulations for Asyn Drivers Most useful simulations written at the lowest possible level Aim - Writing a simulation in a high level language like Python Problem - Driver level typically written in C Solutions: –Attach Python simulated device to real Asyn port –Create simulated Asyn port that communicates with the Python simulation process Driver Support Asyn Port Device Support Record Support EPICS Database Real Device Client Tools Driver Support Asyn Port Device Support Record Support EPICS Database Simulated Device Client Tools Asyn Port Device Support Record Support EPICS Database Simulated Driver Support Client Tools

4 16th Oct 08 Tom Cobb - Python at DLS 4 Python Serial or TCP/IP Device Uses Linux pseudo serial ports or Python TCPServer Subclass serial_device and implement reply method Supports terminators, unsolicited messages, scheduled functions from dls.serial_sim import serial_device class my_serial(serial_device): # set a terminator Terminator = “\r\n” # and internal value val = 1 def reply(self, command): # return reply to if command==“?”: return self.val else: self.val=command return "OK"

5 16th Oct 08 Tom Cobb - Python at DLS 5 Asyn Device Support in Python Python wrapper for Asyn Port Subclass pyDrv and implement write and read Supports type conversion, registration of multiple Asyn interfaces, callbacks, scheduled functions from pyDrv import pyDrv class my_asyn(pyDrv): # supported list of asyn cmds commands = ["A","B","C","D"] # internal dictionary of values vals = {"A":1,"B":"BE","C":3.4, "D":[1,2]} def write(self,cmd,signal,val): # write to dict self.vals[cmd] = val def read(self,cmd,signal): # return value from dict return self.vals[cmd]

6 16th Oct 08 Tom Cobb - Python at DLS 6 Running Python in a Linux IOC Use “Python” function to start the interpreter and run snippets of Python code The above excerpt from st.cmd creates instances of the code from the last two slides Python("from my import my_serial,my_asyn") # start a virtual serial port Python("a = my_serial()") Python("a.start_serial('env_a')") # name of port stored in environment var drvAsynSerialPortConfig('port_a','$env_a') Python("b = my_asyn('port_b')")

7 16th Oct 08 Tom Cobb - Python at DLS 7 Python CA Bindings Python wrapper for libca.so using ctypes Type returned from caget() is converted to a Python type with extra fields Extensively used in GUI design caput(pvs, values, repeat_value=False, timeout=5, wait=False, throw=True) caget(pvs, timeout=5, datatype=None, format=FORMAT_RAW, count=0, throw=True) camonitor(pvs, callback, events=DBE_VALUE, datatype=None, format=FORMAT_RAW, count=0, all_updates=False, notify_disconnect=False)

8 16th Oct 08 Tom Cobb - Python at DLS 8 Front End GUI – SVG Graphics

9 16th Oct 08 Tom Cobb - Python at DLS 9 Operators make use of the CA bindings to make their own GUI panels Some also display Archiver data

10 16th Oct 08 Tom Cobb - Python at DLS 10

11 16th Oct 08 Tom Cobb - Python at DLS 11

12 16th Oct 08 Tom Cobb - Python at DLS 12 Build system Substitution files and EDM screens generated from spreadsheet source

13 16th Oct 08 Tom Cobb - Python at DLS 13 Python EDM screen builder Write and read EDM screens Attributes accessible in a dictionary-like manner Used to create summary screens, autofill the synoptic, and optimise screens from dls.edm import EdmObject # make a blank screen screen = EdmObject(“Screen”) # make a rectangle object rectangle = EdmObject(“Rectangle”) # change its height rectangle[“h”] = 80 # add it to the screen screen.addObject(rectangle) # make another rectangle r2 = rectangle.copy() r2[“y”] = 60 screen.addObject(r2) # write the screen out text = screen.read() open(“/tmp/e.edl”,“w”).write(text)

14 16th Oct 08 Tom Cobb - Python at DLS 14 Dependency Checker Parses RELEASE tree Shows updates, clashes, SVN logs Creates a consistent updated tree Allows editing and dependency checking of the updated trees Changes written back to RELEASE

15 16th Oct 08 Tom Cobb - Python at DLS 15 Future Plans? Replace spreadsheet with XML source Suitable editor for this XML source Python “builder” objects that know how to create substitution files, startup scripts, summary screens Use the XML source to create instance of these objects that define an IOC


Download ppt "16th Oct 08 Tom Cobb - Python at DLS 1 Uses of Python at Diamond Light Source."

Similar presentations


Ads by Google