Home
SpecClient user's guide
Contents
1. BLISS HE Beamline Instrument Software Support SpecClient user s guide Author Matias Guijarro Date 18 06 04 Contents Te ARO GACT Oi T 3 PI FIASCO My pe T 3 SE AEC AUTOS ous sia sana ed I es UI ERU MEN NE ceo mt HIE E UE 3 Za Getting STARTS aa pei ono d buscas bec cone cd re iN o PU RR E ERU ha eb pen kateb ta eb eec cd REG 4 2 1 Impor ni SpeeGliefitsnie eee td b REED IRI NEUE IE NONSE RU RN saa cM Pret eR Halka 4 2 2 Moving Bs TIVO LOT cs teen a ee ue d Dn died a pad ante a ostendi d 5 Dana 5 2 4 EXecutitto COMA A 6 24 a A A DAN 6 2 4 2 Executing macro FINCH OMS o qi aer sectn Coeur da eec oq vas ate co aw e oN codd 7 2 4 3 Executing arbitrary SUING 5 ase io rae a 7 20 SPEC OO CES oreet O aar 7 2 6 Reading and writing Spec Vat DIES qd emeuted diede elo equa DEINEN Be A a Ten ipa 8 2 Embedano pec Cli ina UL addi eg od Dae sd IES 10 31 Disp tehino dA Se RETE TL E 10 3 2 Phe asynchronous Motor class sonder a dae tabo nda 10 Did Asynchronous Spec AAA A tai a e MO n dtu Ud d d se 11 3 4 Executing commands asynchronously cec ttes pe rta see id 11 oo Watching o O uii pida bas qain E e nhau Ed 11 4 SD GDEDVETE a obse A qud nnde bu adn A caasa Dorm A 13 57 AOS OUT REP 14 5 1 What happens when importing SpeeC I nb neat tenete nba pede rer be tte ro ed 14 52 SEETOSEIDE A e cb abbat tested D BOT nappe Ud DR ba MARRE 14 5 31 08 to TOta UNS TCS iae ene pni qid eibi itte d i n dpi Paci ord
2. SpecServer TO BE DOCUMENTED Sorry for the inconvenience 13 5 Logging SpecClient offers some logging features relying on the logging package of the standard Python 2 3 distribution The next paragraphs show how to set logging on or off or to redirect logging messages to files 5 1 What happens when importing SpecClient When importing the SpecClient package a new SpecChent logger is created If there is no root logging handler previously created the messages will go to stdout If there is one root logger no specific handler will be created and messages will be dispatched as the other ones 5 2 Set logging on off By default logging is enabled To set logging off just call the setLoggingOff method of the SpecClient package Pta 2 3 58 Gil Mes 13 2004 Tasas 22 lECC 25955 3 200105159 SUS AO E a Type help copyright credits or license for more information gt gt gt import SpecClient gt gt gt SpecClient setLoggingOff FIG 16 turn logging off Alternatively turning logging on is achieved by calling set LoggingOn 5 3Log to rotating files You may prefer to send logging messages to rotating files In this case call the setLogFile method with a filename as first argument logging messages will be send to this file If the file gets bigger than 1 MB a second file will be created with a different suffix If there is more than 5 these files the first one will be overwritten and s
3. iL ill gt gt gt FIG 6 counting The returned value is the counter s value after counting You can get a counter s value by calling the get Value method gt gt gt c getValue dl DAD FIG 7 obtaining a counter s value 2 4 Executing commands The SpecCommand class encapsulates a Spec command in a Python object The SpecCommand constructor takes the following arguments command name host porf string representing a Spec version to connect to optional timeout If timeout occurs when attempting to connect a SpecClientTimeoutError exception is raised Once you have created a SpecCommand object you can execute the corresponding Spec command by calling the object and giving the command arguments as if it were a Python function 2 4 1 Executing macros We are going to create a mvemd object representing the z macro in Spec and then move a motor using the command iilo 2 953 wi May 13 2004 14245222 LECC 2 95 3 20030535 GUSE on lube Type help copyright credits or license for more information gt gt gt mvcmd SpecCommand SpecCommand mv boom spec 500 SS wmwewwol iim 3 2 0 gt gt gt from SpecClient import SpecMotor gt gt gt tth SpecMotor SpecMotor tth boom spec gt gt gt tth getPosition 12 gt gt gt FIG 8 defining a new command and executing it with arguments Class SpecCommand Module SpecCommand Package SpecClient You
4. Spec version gt gt gt anycmd SpecCommand SpecCommand boom spec 500 gt gt gt anycmd executeCommand 12 3 15 222 FIG 10 executing a command string 2 5 Spec objects Spec objects act like a remote Spec version Spec objects can execute any command as if it were a method of the Python object Spec objects also define their own methods for obtaning informations from a remote Spec version The constructor takes only a ost porf string representing the remote Spec version and host to connect to gt gt gt from SpecClient import Spec gt gt gt spec Spec Spec boom spec FIG 11 creating a Spec object Class Spec Module Spec Package SpecClient Spec objects can execute any command SS Tv OS MO 0 gt gt gt spec p hello 1 gt gt gt FIG 12 executing commands with Spec objects The same rules as for SpecCommand objects apply when executing a macro function or Spec builtin function if the remote Spec is an old release you have to specify the function keyword argument Note that the return values are not significant when executing macros in case of error a SpecClientError exception is raised Spec objects also have some own methods The getMotorsMne method returns a list of all the motor mnemonics defined in the connected Spec version gt gt gt spec getMotorsMne 19185 7 esu osu So seo Vespa LSU isl Vos semp ees Vids aoo
5. can notice that the reply you get after command execution is 0 You cannot rely on the reply code when executing mactos A SpecClientError exception is raised if a problem occured during macro execution The recommended way is then to use a try except clause when executing commands 2 4 2 Executing macro functions Executing macro functions and Spec builtin functions is much the same as with macros The main difference is that reply values are significant There is another point depending on the Spec server version you ate connected to Two cases you are connected to a Spec server gt X Spec is able to determine if it is executing a macro or a function There is nothing to do otherwise it is ought to you to indicate if you are executing a macro or a function using the function keyword argument when calling the command Latest Spec release gt gt gt from SpecClient import SpecCommand gt gt gt motor mne SpecCommand SpecCommand Cities mas ocom Sose gt gt gt motor mne 5 ssf DR Before gt gt gt from SpecClient import SpecCommand gt gt gt motor mne SpecCommand SpecCommand motor mast boom spec gt gt gt motor mas 5 Eumciciom 11 ssf D FIG 9 executing a function 2 4 3 Executing arbitrary strings Any SpecCommand object can execute arbitrary strings not only the command defined in the constructor Be very careful when executing arbitrary strings in a remote
6. have a general purpose Python module to interface Spec with the rest of the world Later development on the Bliss Framework project showed that the former specclient module did not suit well with to the specific needs of the project and a different module has been written AsyncSpecClient It emphasized on an asynchronous behaviour for communicating with Spec and relied on the signals and slots callback mechanism provided by the Qt GUI toolkit The new SpecClient package merges the good ideas of the two previous modules in one unified piece of software 1 2 Features The SpecClient package does not depend on a higher level toolkit or library It is directly usable in a simple Python script or in the Python interpreter in an interactive session It is easy to bind with any GUI toolkit for creating Spec client graphical user interfaces The following functionalities are implemented Access to the hardware controlled by Spec motors and counters Ability to execute commands and get results Variables watching Errors notification The SpecClient package can be used in two ways for scripting embedded in a GUI Generally speaking the expected behaviour when writting scripts is that Spec objects and methods could be used a bit like if the user were in front of the Spec terminal window connecting to Spec would block until the connection 1s effectively established in the same way that we wait for the prompt when startin
7. host PERON 2 Sro Gal Mex 13 15 22 ECC 2 95 3 20030515 Susa om lobaube2 gas Masia copa Weis ou Wilike emse i more information gt gt gt from SpecClient import SpecMotor gt gt gt m SpecMotor SpecMotor tth boom spec 500 FIG 3 creating a new SpecMotor object You can obtain the absolute position of a motor using the getPosition method You can move it using the move method gt gt gt m getPosition 1225 gt gt gt m move m getPosition 1 gt gt gt m getPosition SS gt gt gt FIG 4 getting a motor position and moving 2 3 Counting Counting in the SpecClient package can be achieved using SpecCounter objects Each SpecCounter object represents a counter in the remote Spec version Creating a SpecCounter object is much like the same as for a SpecMotor object eo 2 555 Gl Men 13 2004 14345322 ECC 2 95 3 2003035 Susa Om lbabs2 Bros med optage ri con itor more information gt gt gt from SpecClient import SpecCounter gt gt gt c SpecCounter SpecCounter sec boom spec 500 gt gt gt FIG 5 creating a SpecCounter object Class SpecMotor module SpecMotor package SpecClient Class SpecCounter module SpecCounter package SpecClient The c object now refers to the counter sec in the spec Spec version running on boom We can count a certain number of seconds on this counter object SSS Genuae
8. import SpecEventsDispatcher self timer Qtimer self POOE Aes ITO root after 20 QObject connect self timer SpecEventsDispatcher dispatch SIGNAL timeout SpecEventsDispatcher dispatch self timer start 20 root mainloop FIG 15 installing the SpecClient dispatcher in a GUI loop 3 2 The asynchronous motor class The SpecClient package provides a motor class specially designed to be derivated SpecMotorA You should use this class as a base class for your own GUI oriented motor class In this scheme you define particular actions and behaviour changing colors putting to enabled disabled state etc by overriding methods of the SpecMotorA class The methods will get called by the SpecClient events dispatcher while events are coming from the remote Spec server The SpecMotorA constructor takes the following arguments Spec motor name host uversion string representing the Spec version to connect to The two arguments are optional if not specified the SpecMotorA object 1s created but does nothing You can connect to Spec later by calling the connectToSpec method with the same arguments Methods to be overriden connected called when the remote Spec version gets connected e disconnected called when the remote Spec version gets disconnected motorLimitsChanged limit called when the motor limits change in Spec imif can be low or high limit use getLimits to
9. e same arguments for differed connection The SpecCommandA class behaves vety much like the SpecCommand class see 2 5 The only difference is that it is designed to be subclassed and that it is not blocking In order to provide custom waiting according to your GUI needs message to user disabling control etc and getting results back just override the following methods beginWait called when the command has just been send replyArrived reply called when reply from Spec has arrived reph is a SpecReply object with two main members data returned value and error boolean 3 5 Watching variables Watching variables asynchronously is done with the SpecVariableA class The constructor takes the following arguments vatiable name host uversion string representing the Spec version to connect to Class SpecCommandA Module SpecCommand Package SpecClient Class SpecVariableA Module SpecVariable Package SpecClient 11 The two arguments are optional You can connect to Spec later by calling the connect ToSpec method with the same arguments The methods supposed to be overriden are connected called when the remote Spec gets connected e disconnected called when the remote Spec gets disconnected update value called when the variable value changed Other useful methods getValue return the current variable value setValue value write the variable value 12 4
10. ena ten uds 14 Figures FIG 116s Tit ine Se Ce tb paca sai edet pipa niae ont eda dabat uite Gh i 4 FIG 2 importing an element from the SpecClient paca 4 PIG Creating a new Spee Motor Objects qudm Quee tua AU biu qu Bila Borde i n aus 5 FIG 4 getting a motor position and oye sedes serpit tidem ign igiene Da egit trop is 5 FIG 5 cheating a SpecCounter Object seniseid A ETUR RR a ettet 5 PISOS TL cc M 6 PIG 7 obtaining a counter S value an tacere be rst o A o e Pe Fred AA 6 FIG 8 defining a new command and executing it with arguments sse 6 FIG 9 executing TUDCUOfE esiste Parr aed uda eni A NAR UNDE SERRE etiaai cte 7 FIG 10 executing a Command String ii ini a 7 FIG LI creating a SDecobIeck cusa enecitoniet NAAA aa T FIG 12 executing commands with Spec oDIects s t estar nai iii 8 FIG 13 the getMotorsMhbe Method mitin aii 8 FIG 143 creating a Spec Variable ODE ina A de 8 FIG 15 installing the SpecClient dispatcher in a GUI loop eem is 10 FIG 162 turn logging OFT ai eian a a i etie inel A ska a pea 14 FIG TPs log to rotating li ert rtl oe teet Pepe PM a Caste deci 14 1 Introduction This document is a short guide to the SpecClient package a set of Python modules for interacting with remote Spec servers 1 1 History At the same time as the new client server features were implemented in Spec a specclient Python module was written to test the new capabilities It was the first attempt to
11. er py SpecChannel py SpecReply py SpecWaitObject py SpecConnection py SpecMessage py SpecEventsDispatcher py SpecServer py FIG 1 files in the SpecClient package When importing elements from the SpecClient package you should use a from import statement in Python from SpecClient import SpecMotor FIG 2 importing an element from the SpecClient package You can also use the wildcard to automatically import the key elements of the package The key elements of the package are the following modules SpecMotor SpecCounter SpecCommand Spec e SpecVariable Starting from bere you will learn how to use the SpecChent package through studying small pieces of code You are strongly encouraged to try them one by one Before continuing please start a Spec version in Server mode S command line flag and a Python interpreter 2 2 Moving a motor Moving a motor from the Python interpreter can be achieved using the SpecMotor class Each SpecMotor object represents a motor in the remote Spec version The SpecMotor constructor takes the following arguments Spec motor name bost version string representing the Spec version to connect to optional timeout in milliseconds If timeout occurs while trying to connect Spec a SpecClientTimeoutError exception is raised Let s create a SpecMotor object bound to a motor named b controlled by a spec Spec version running on the boom
12. g Spec Moving a motor should block until the motor has finished moving and so on Blocking while doing something else is good On the contrary when embedding SpecClient in a GUI you almost never want an operation to block Instead you want to launch things and being informed of changes in order to update your widgets accordingly In this case moving a motor can be viewed as a background task emitting notifications when the motor starts moving or stops The GUI main loop is never interrupted so your graphical interface still behaves normally The SpecClient package usually contains two set of classes ones synchronous dedicated to scripting and others asynchronous for using with a GUI Asynchronous classes ate suffixed with A For example SpecMotor is the synchronous class representing a motor in Spec and SpecMotorA is the asynchronous flavout 1 Due to actual Spec limitations the errors notification support remains poorly supported 2 Getting started This section is a quick step guide to the main aspects of the SpecClient package After two introductory chapters we will learn how to use the SpecClient package by studying examples If you are interested in embedding SpecClient in a GUI please read section 3 Embedding SpecClient in a GUT 2 1 Importing SpecClient The SpecClient package contains different files SpecClient E D SpecMotor py SpecCounter py SpecCommand py Spec py SpecVariable py SpecConnectionsManag
13. get a low limit high limit tuple Class SpecMotorA Module SpecMotor Package SpecClient 10 motorPositionChanged absolutePosition called when motor position has changed absolutePosition is the updated absolute motor position syncQuestionAnswer specSteps controllerSteps called when answer to the famous sync question is required Return 1 for YES 0 for NO motorStateChanged state called when the motor changed state The possible motor states are global to the SpecMotor module and can be one of NOTINITIALIZED UNUSABLE READY MOVESTARTED MOVING ONLIMIT The other useful methods in the class are e getPosition return the current motor absolute position e getState return the current motor state e getLimits return a low limit high limit tuple e getDialPosition return the current motor dial position move position move the motor to a new absolute position stop abort moving WARNING due to Spec behaviour calling stop on a motor will stop ALL the moving motors 3 3 Asynchronous SpecCounter Does not exist for the moment Sorry for the inconvenience 3 4 Executing commands asynchronously The SpecCommandA class permits to execute commands asynchronously The constructor takes the following parameters command name host uersion string representing the Spec version to connect to Both arguments are optional You can call the connect ToSpec method with th
14. m muc mus olas Violas y Bro si SORT o SM ssh om ising Sswo see A Wewe Adr wow del Calo S5 Jyoti dL 14 Y SANG mono egy eer olia V 7 Exe 1E y MEROS Viens Vanity mao most tomar oli wow mur wel gt gt gt FIG 13 the getMotorsMne method You also have getVersion and getName 2 6 Reading and writing Spec variables Reading and writing Spec global variables can be easily achieved using SpecVariable objects It is a thin wrapper around SpecChannel objects provided for convenience PENON 2d Gil Wes 1S 2004 EEAS ECE 2595 3 201030535 Susie om inb Type help copyright credits or license for more information gt gt gt from SpecClient import SpecVariable gt gt gt toto SpecVariable SpecVariable toto boom spec FIG 14 creating a SpecVariable object The constructor takes at least two arguments e name of the Spec variable host porf string for connecting to the required Spec version optional timeout in milliseconds If timeout occurs when attempting to connect a SpecClientTimeoutError exception is raised SpecVariable objects have 4 methods Class SpecVatiable Module SpecVariable Package SpecClient isConnected returns wether the remote Spec is connected or not getValue reads the corresponding channel and returns the value of the variable setValue value writes value to the corresponding channel wai
15. o on Python 2 3 3 41 May 13 2004 14 45 22 ICCC 2 95 53 20010315 Sur om T n gas aed eooayriclae Weirechhes or VU sceyewmee ox more information gt gt gt import SpecClient SSS SypecClicumt seuibeogmile uu speceliewnnr leg FIG 17 log to rotating files 14
16. tUpdate waitValue timeout waits for channel to be updated the two arguments are optional If you want to wait for a specific value assign a value to the waitValue keywotd argument If you want to set a timeout specify it in milliseconds with the timeout keyword argument 3 Embedding SpecClient in a GUI SpecClient is designed to be used with a GUI The following paragraphs show how to take advantage of this feature when embedding SpecClient in a Graphical User Interface 3 1 Dispatching events Internally the SpecClient package uses events to trigger actions when receiving messages from Spec For example when a remote Spec server gets connected a connection event is emitted by the corresponding SpecConnection object Then the listenning objects act accordingly i e a SpecChannel object can register when the connection is established The events machinery 1s implemented in the SpecEventsDispatcher module within the SpecClient package In particular the module defines a dispatch function In order for events to be dispatched from event emitters to event receivers you should call SpecEventsDispatcher dispatch ata regular interval Generally 20 milliseconds is a good polling interval you are free to use another value however When embedding SpecClient in a GUI this is commonly achieved inside a timer object or using the GUI main loop idle time Tk Qt from SpecClient import SpecEventsDispatcher from SpecClient
Download Pdf Manuals
Related Search
Related Contents
CAMagic_Mobile 25 Manual hashcat user manual 原子力防災活動資機材備品 Copyright © All rights reserved.
Failed to retrieve file