perl-spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · contents 1 spectra...

156
Perl-Spectra Version May 2, 2017 by Thorsten Kracht

Upload: others

Post on 26-May-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Perl-SpectraVersion May 2, 2017

by

Thorsten Kracht

Page 2: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Contents

1 Spectra meets Perl 7

1.1 General remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

1.2 Calling Perl scripts from SPECTRA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

1.3 Calling Perl functions from SPECTRA or from a Perl script . . . . . . . . . . . . . . . . . . . . . . 10

1.4 A global user hash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2 News 12

3 Devices, Symbols and Markers 14

4 Motors 16

4.1 Motor parameters, moves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

4.1.1 Flags: backlash, relative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

4.2 Hooks: before/after move command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

4.3 Motor definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

4.4 Asynchronous moves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

4.5 Slits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

4.6 Accessing stepping motors by functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

4.7 Virtual motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

4.7.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

4.7.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

5 Scans 23

5.1 Scan Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

5.2 Scan Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

5.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

5.4 Using profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

5.5 Symbols used in scan macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

6 Functions 28

6.1 General remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

6.2 Miscellaneous Spectra Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

6.2.1 activate(), deactivate() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

6.2.2 autoscale() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

6.2.3 attribute() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

6.2.4 book name(), book slot(), book subindex() . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

6.2.5 calc() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

6.2.6 ceil(), floor() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

6.2.7 cleanup() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

6.2.8 cls() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

6.2.9 date(), date and time(), doty(), doty2date(), time stamp nexus() . . . . . . . . . . . . . . . . 30

6.2.10 delete() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

6.2.11 display() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

6.2.12 dump() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

6.2.13 flag() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

6.2.14 linear regression(), parabolic regression() . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

6.2.15 get last error() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

6.2.16 gra command() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

6.2.17 key(), keyw() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

Page 3: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.2.18 max(), min() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

6.2.19 postscript(), print() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

6.2.20 read() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

6.2.21 read line() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

6.2.22 roi() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

6.2.23 run() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

6.2.24 secnds() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

6.2.25 spectra dir() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

6.2.26 symbol alias() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

6.2.27 ssa() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

6.2.28 version() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

6.2.29 yesno(), noyes() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

6.2.30 Special Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

6.3 Miscellaneous Online functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

6.3.1 Util::append scan info file() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

6.3.2 awe() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

6.3.3 create scan name() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

6.3.4 define() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

6.3.5 device(), n device() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

6.3.6 device record() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

6.3.7 device type() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

6.3.8 doris(), doris is sync run(), doris state(), doris wait for sync run() . . . . . . . . . . . . . . 36

6.3.9 elcomat(), elcomat ascii() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

6.3.10 get counters(), get motors(), get timers(), etc. . . . . . . . . . . . . . . . . . . . . . . . . . 36

6.3.11 get devices(), get modules() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

6.3.12 log() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

6.3.13 mpa3() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

6.3.14 petra(), petra is sync run(), petra state(), petra wait for sync run() . . . . . . . . . . . . . . 37

6.3.15 privilege() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

6.3.16 protect() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

6.3.17 module name() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

6.3.18 ortec972() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

6.3.19 search device() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

6.3.20 TkITableBlank(), TkITablePop() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

6.3.21 trainno() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

6.3.22 Spectra::was beamlos doris() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

6.3.23 Spectra::was beamlos petra() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

6.3.24 Spectra::was injection() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

6.3.25 waveform(), dso() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

6.3.26 vhq205l(), HV power supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

6.3.27 vhsc005n(), HV power supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

6.4 Miscellaneous Utility Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

6.4.1 Util::display text() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

6.4.2 Util::info() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

6.5 ADC/DAC, MCA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

6.5.1 VFC ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

6.5.2 MCA() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

6.5.3 Another MCA example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

6.5.4 SDD7 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

6.5.5 XIA DXP-XMAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

6.5.6 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

6.6 Counter/timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

6.7 Diffractometer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

6.7.1 diff h, diff k, diff k, diff psi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

6.7.2 diff psirefx, diff psirefy, diff psirefz (Tango) . . . . . . . . . . . . . . . . . . . . . . . . . . 48

6.7.3 diff mode, diff asn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

6.7.4 diff mu, diff omega, diff chi, diff phi, diff gamma, diff delta, diff two theta . . . . . . . . . 49

6.7.5 diff get r0, diff set r0, ˜r1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

6.7.6 diff compute u (Tango) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

6.7.7 diff angles() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

Page 4: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.7.8 diff ang2h, diff ang2k, diff ang2l, diff ang2psi . . . . . . . . . . . . . . . . . . . . . . . . . 49

6.7.9 diff hkl2two theta, diff hkl2omega, diff hkl2chi, diff hkl2phi, diff hkl2mu, diff hkl2gamma,

diff hkl2delta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

6.7.10 diff calc angles() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

6.7.11 diff hkl() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

6.7.12 diff gk1, diff gk2, diff gk3, diff gw1, diff gw2, diff gw3 . . . . . . . . . . . . . . . . . . . 50

6.7.13 attribute( name =¿ ”ub matrix”, ...) (non-Tango) . . . . . . . . . . . . . . . . . . . . . . . . 51

6.7.14 Absorber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

6.8 Encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

6.9 Image Plate Scanner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

6.10 Hexapod (Beamline L) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

6.11 LCX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

6.12 MARCCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

6.13 Monochromator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

6.13.1 Hook: Before/after energy moves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

6.13.2 mostab() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

6.14 Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

6.14.1 check motor registers() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

6.14.2 Encoder (OMS-MAXV) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

6.14.3 CutOrMap (OMS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

6.15 NeXus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

6.16 Perkin Elmer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

6.17 Photonic Science . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

6.18 Pilatus-300k . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

6.18.1 The startup procedure, P09 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

6.19 Prosilica . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

6.20 The pulse generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

6.21 Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

6.22 Tango . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

6.22.1 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

6.22.2 Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

6.22.3 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

6.22.4 State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

6.22.5 isAlive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

6.22.6 Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

6.22.7 is tango() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

6.22.8 is device() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

6.23 Undulator/wiggler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

6.24 Functions for G1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

6.25 Functions for W3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

7 Working with GQEs 69

7.1 Base class methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

7.2 ARRAY Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

7.2.1 ARRAY Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

7.2.2 An ARRAY Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

7.3 CONST Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

7.3.1 CONST Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

7.3.2 A CONST Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

7.4 SCAN Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

7.4.1 Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

7.4.2 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

7.4.3 SCAN items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

7.4.4 SCAN data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

7.4.5 The calc() method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

7.4.6 Smart update of the graphics window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

7.5 TAG Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

7.5.1 TAG Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

7.5.2 A TAG Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

7.6 TEXT Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

7.6.1 TEXT Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

Page 5: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

7.6.2 A TEXT Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

7.7 UB Matrix Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

7.8 GKS - Default Graphical Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

7.8.1 GKS Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

7.9 A Simple Plotting Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

8 Data Busses 92

8.1 The Low Level VME Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

8.2 The ADS Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

8.2.1 Example: ReadLong . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

8.2.2 Example: WriteDouble, ReadDouble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

8.3 The GPIB Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

8.4 The Canbus Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

8.5 The Modbus Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

8.5.1 Modbus example: a virtual motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

8.5.2 Modbus example: configuration of a motor . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

8.6 The Low Level CAMAC Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

9 The Low Level Spectra Interface 99

10 Examples 101

10.1 Centering Slits using a Profile and SSA, P02 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

10.2 PE image series, incl. loop over SDD positions, P02 . . . . . . . . . . . . . . . . . . . . . . . . . . 103

10.3 Converting .fio to .dat files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103

10.4 ROIs from many files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

10.5 SSA for many .fio Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

10.6 Asynchronous Move, P09 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

10.7 Asynchronous Moves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

10.8 MCA() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

10.9 Scans (measurements) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

10.9.1 DUMMY Scan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

10.9.2 Single Motor Scan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

10.9.3 2D Scan, Single Motor Scan with Outer Loop . . . . . . . . . . . . . . . . . . . . . . . . . 109

10.9.4 2D Scan, Flipping the Scan Direction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110

10.9.5 3D Scan, Flipping the Scan Direction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

10.9.6 Alignment of 8 Motors, SLAC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

10.9.7 spirale.pl, using profile, P10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

10.9.8 Lenses, using profile, P03 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

10.9.9 Photonic Science Camera, using profile, P03 . . . . . . . . . . . . . . . . . . . . . . . . . . 115

10.9.10 Motor Regions Scan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

10.9.11 Energy Scan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

10.9.12 EXAFS Scan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

10.9.13 Combined Move (CM) Scan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

10.9.14 Omega-2Theta Scan, 2Theta-Omage Scan . . . . . . . . . . . . . . . . . . . . . . . . . . . 118

10.9.15 2Theta Scan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118

10.9.16 hkl Scans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118

10.9.17 Scan/Reflection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

10.9.18 Slit Scan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

10.9.19 Continuous Move Scan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

10.9.20 Om-tt scan with outer loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

10.9.21 Sweep with outer loop motor, P10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

10.10SCAN (GQE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

10.10.1 Passing data by array references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

10.10.2 Passing data by direct assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

10.10.3 Passing data as a buffer reference (fast) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

10.10.4 Linear regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

10.10.5 Data conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

10.10.6 read()/write() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

10.11Virtual motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

10.11.1 A very trivial example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

10.11.2 A trivial example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126

Page 6: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

10.11.3 Two Motors uniformly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127

10.11.4 Centralized VMs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

10.11.5 FMB-DCM: ExitOffset, Tango . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

10.11.6 FMB-DCM: DCM Z (Jack) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

10.11.7 Undulator Gap, Tango . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131

10.11.8 Mirror height . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132

10.11.9 Mirror angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

10.11.10HKL rotation (BW5) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

10.11.11Slit (haspp02ch1a) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136

10.11.12Temperature controller hasg3, TCU200 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137

10.11.13A solution for the 24 bits problem of the OMS-VME58, large moves, limits . . . . . . . . . . 141

10.12 Virtual counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

10.12.1 Pilatus, Single Shot, P03 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

10.12.2 Pilatus, Multiple Frames, P03 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

10.12.3 Lima . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

10.12.4 ADQ1600, P01, XFEL-WP76 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

10.12.5 Keithley 6517a, Current Attribute, Tango . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

10.12.6 Keithley 617, NON-Tango . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

10.12.7 Encoder raw position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

10.12.8 Send an email, if a counter shows a signal . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

10.12.9 Lecroy DSO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

10.13 Lissajou Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

Page 7: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

List of Figures

7.1 calc(): sin/cos/tan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

10.1 A linear regresseion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

Page 8: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Chapter 1

Spectra meets Perl

The scripting language Perl is used for all kinds of applications. Many of us know it from CGI programming or from

developing computer administration tools. Furthermore, a lot of small Perl scripts are created for daily purposes like

directory scans or string replacements in ASCII files and so on.

The fact that Perl is widely used was certainly one of the main reasons to chose it as the new macro language for

Spectra. Apart from that: “Perl is a language for getting things done” or “Perl was designed to make easy jobs easy”

as the authors of [1] put it. These statements are probably correct for several reasons. To mention just a few:

• Perl is extremly good in list processing, including hashes.

• Perl has an excellent implementation of regular expressions.

• Perl is extendable. There is a long list of freely available Perl modules. An important module is PerlTk, the

interface to Tk GUIs.

• Perl has packages forr separating name spaces and object class definitions.

• Perl has an implementation of dynamically scoped variables: closures.

• Perl is an interpreter that can be linked to C code.

Spectra is now available as a Perl module and Perl scripts can be called from Spectra. That means: all Perls features

like data types, statements, control structures, operators, and functions can be used by a Spectra programmer.

This note focusses on the Spectra-Perl interface. It hardly describes Spectra features. See the Spectra and Online

manuals for details about these programs.

Documentation about Perl can be found on the web or in books, e.g.: “Programming Perl” by Larry Wall, Tom

Christansen and Randal L. Schwartz, “Advanced Perl Programming” by Sriram Srinivasan and “Perl Cookbook” by

Tom Christiansen and Nathan Torkington, all printed by O’Reilly.

Page 9: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

1.1 General remarks

• There is a Perl startup file: /online dir/TkIrc.pl. The file was originally invented to do the initialisations

for online -tki. However it turned out that it is also necessary for the other Online sessions. Among other

things, TkIrc.pl loads the Tango configuration file online.xml. See the online -tki manual for more

informations about TkIrc.pl.

• There is no change in the Spectra command line syntax. All gra-files execute as before.

• gra-style commands can be executed from within Perl:

Gra_command( "create test 0 10 100") or die "error message";

• All arrays begin at index 0. Spectra uses the Fortran convention (arrays begin at index 1) because most scientific

programs were written in Fortran when Spectra was launched. That means in Spectra the first y-value of a Scan

GQE (graphical queue element) is accessed by SPECTRA> test(1) = 12. In Perl-Spectra we write (taken

from the example 10.10.2):

use Spectra;

use GQE;

$t1 = SCAN->create( name => "t1",

start => "0",

stop => "10",

np => "$size") or die " Failed to create t1 ";

#

# ... set the y-values to sinus() ...

#

for $i (0 .. ($size - 1))

{

$t1->{y}[$i] = sin( $t1->{x}[$i]);

}

Notice that $i starts at 0.

• GQE parameters are changed or retrieved by the methods set or get.

use Spectra;

use GQE;

$t1 = TEXT->create( name => ’test’);

$col = $t1->get( ’colour’);

$ret = $t1->set( string => ’ein Text’, colour => ’red’);

Page 10: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

1.2 Calling Perl scripts from SPECTRA

SPECTRA> perl file.pl [arg1 [arg2 ...]]

The @ARGV array passes the command line arguments to the script. Information can be transferred in the opposite

direction by symbol definitions:

#!/usr/bin/perl

#

# this script demonstrates how the command line arguments can be

# accessed and how some information is fed back to Spectra

#

# Usage:

#

# SPECTRA> perl hello_world.pl 1 2 3

#

use Spectra;

my $status = 1;

print "\n Hello world \n\n";

$len = @ARGV;

print " The list of command line arguments: @ARGV, length = $len\n";

$SYM{ RETURN_VALUE} = "@ARGV" if $len;

prtc();

$status;

The function prtc() is resolved by the Spectra.pm module.

Page 11: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

1.3 Calling Perl functions from SPECTRA or from a Perl script

The verb eval invokes a Perl function that has been loaded before. Suppose we defined the package compton and the

function pilatus start in /online dir/TkIrc.pl:

#

# part of a Perl file, e.g.: /online_dir/TkIrc.pl

#

package compton;

sub pilatus_start

{

my ( $scan_name, $sample_time, $sindex) = @_;

...

}

This function is invoked by the following .gra code:

!

! part of a .gra file or Online command line

!

eval compton::pilatus_start( $Spectra::SYM{ scan_name},

$Spectra::SYM{ sample_time},

$Spectra::SYM{ sindex})

Or it can be invoked from a Perl script:

use Spectra;

my $ret = compton::pilatus_start( $Spectra::SYM{ scan_name},

$Spectra::SYM{ sample_time},

$Spectra::SYM{ sindex});

Page 12: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

1.4 A global user hash

The Spectra module defines the hash %user_h and initializes in use Spectra;. This features has been introduced

to allow users to savely pass information between different Perl scripts, e.g.:

#!/usr/bin/perl -w

use strict;

use Spectra;

$Spectra::user_h{ user_var} = "some-value";

Page 13: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Chapter 2

News

This section lists the most recent changes.

May 2, 2017

Latest LaTex run of this manual.

2.5.2017

New feature: If the environment variable SPECTRA NOGRAPHIC is set, no graphics terminal will be opened.

Has been implemented to use Spectra from croan jobs.

19.1.2011

New function: tng hasAttr() returns 1, if the Tango device has a specific attribute.

24.7.2008

New functions: get modules(), get devices() return strings that consist of blank-space-separated device names.

24.7.2008

New function: read output register().

16.1.2008

New item for the function flag(): priviledge.

22.11.2007

New variable: the array @Spectra::DEV contains the names of the devices.

22.11.2007

New functions: device( $i) and n device(), return a device name and the number of devices.

16.11.2007

New functions: device type() and device record();

10.8.2007

Created functions that communicate to Tango servers, see 6.22.

8.8.2007

Changed the graphical layout for Online to: set gks/at mode=1. This setting is the default for -tki.

8.8.2007

Setting a point in a scan, e.g.: $s1-¿y[100] = 12 no longer changes the current index of the SCAN.

8.8.2007

Accessing SCAN GQE data is now documented (7.4.4).

7.5.2007

Most of the examples move to s dedicated chapter 10.

29.1.2007

Virtual motors (VMs) can call other VMs and VMs can be moved with other motors.

22.1.2007

New functions: doris is sync run() and doris wait for sync run().

Page 14: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

18.1.2007

New function: doris state() returns string that describes the current state of DORIS, e.g.: “Syn Run”.

18.12.2006

New function: get first active scan() returns the name of the first active SCAN or “0”, if no active SCAN exists.

15.5.2006

Timer mode: the scan() function uses the preset timer flag of the TkI interface as the default. The preset

parameter overrides the TkI value.

5.5.2006

New functions: get motor slew min, set ˜, ˜ max

5.5.2006

New GQE item: ’name’, can be read, $ret = $s1-¿get( ’name’); or altered, $s1-¿set( name =¿ ’whatever’);.

1.3.2006

New feature for SCAN GQEs: doty => 1. The x-values are understood as day-of-the-year values. Big tic marks

receive date strings.

6.1.2006

Introduced the functions hkl2two theta( $h, $k, $l[, $par]), hkl2omega, hkl2chi, hkl2phi. They return angles that

correspond to the supplied hkl values. See section 6.7.9 for details.

6.1.2006

Introduced the function hkl( h =¿ 1, k =¿ 1, l =¿ 1, psi =¿ 90). See section 6.7.11 for details.

6.1.2006

The functions h(), k(), l(), psi() return the components of the q-vector.

Page 15: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Chapter 3

Devices, Symbols and Markers

The array @Spectra::DEV contains the names of the devices.

#!/usr/bin/perl

my $ndev = @Spectra::DEV;

foreach my $i ( 0 .. ($ndev - 1))

{

print " $i $Spectra::DEV[ $i]\n";

}

The hash %SYM contains the Spectra symbol table. The following example demonstrates how the symbols are set, read

and deleted:

#!/usr/bin/perl

use Spectra;

#

# symbols are defined by:

#

$SYM{ s1} = "this is a test";

#

# the next statement is an example for a read access:

#

print " Symbol s1 has the value \"$SYM{ s1}\"\n";

#

# listing all symbols:

#

print "\n List all symbols: \n";

foreach $sym (keys %SYM)

{

print " $sym = $SYM{ $sym} \n";

}

#

# deleting symbol s1:

#

delete $SYM{ s1};

The array @MAR contains the markers.

#!/usr/bin/perl

use Spectra;

#

# set 3 marker

#

@MAR = (1, 2, 3);

Page 16: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

$len = @MAR;

print " Defined 3 marker: @MAR, len $len\n";

#

# clear the marker array

#

@MAR = ();

$len = @MAR;

print " cleared marker, len $len\n";

Page 17: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Chapter 4

Motors

There are two ways to address stepping motor parameters: via functions Spectra::get motor unit position( ”MOT1”)

or using an OO-style syntax, like $m1-¿get( ”position”). We start explaining the second choice since it is the recom-

mended way.

4.1 Motor parameters, moves

In the following piece of code motor objects are created (Motor->locate()) and references to these objects are

stored in the symbols $m11 and $m12. These symbols allow us to address the motor parameters using the methods

get() and set().

#!/usr/bin/perl

#

# stepping motor example, OO style

#

$m11 = Motor->locate( name => "mot11");

$m12 = Motor->locate( name => "mot12");

#

# fetch motor parameters

#

print "\n";

print " name " . $m12->get( "name") . "\n";

print " Position " . $m12->get( "position") . "\n";

print " Accel " . $m12->get( "acceleration") . "\n";

print " Base " . $m12->get( "base") . "\n";

print " Slew " . $m12->get( "slew") . "\n";

print " Settle time " . $m12->get( "settle_time") . "\n";

print " Unit_backlash " . $m12->get( "unit_backlash") . "\n";

print " Unit_limit_min " . $m12->get( "unit_limit_min") . "\n";

print " Unit_limit_max " . $m12->get( "unit_limit_max") . "\n";

print " Step_limit_min " . $m12->get( "step_limit_min") . "\n";

print " Step_limit_max " . $m12->get( "step_limit_max") . "\n";

print " Step_register_controller " . $m12->get( "step_register_controller") . "\n";

print " Step_register_internal " . $m12->get( "step_register_internal") . "\n";

print " Ramp_units " . $m12->get( "ramp_units") . "\n";

print " Ramp_steps " . $m12->get( "ramp_steps") . "\n";

print " Moving " . $m12->get( "moving") . "\n";

print " Move time " . $m12->get( " move_time => "$units") . "\n";

#

# fetch the current positions of mot11 and mot12

#

$pos11 = $m11->get( "position");

$pos12 = $m12->get( "position");

#

$new_pos11 = $pos11 + 1;

Page 18: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

$new_pos12 = $pos12 + 1;

#

$m11->set(position => $new_pos1);

$m12->set(position => $new_pos2);

#

# and move them back, one after the other

#

$m11->set(position => $pos11);

$m12->set(position => $pos12);

#

# or simultaneously

#

$ret = move( "mot11" => $new_pos11,

"mot12" => $new_pos12);

#

# single step moves, ’right’ is equivalent to ’down’

#

$m12->set( step_down => ’yes’);

$m12->set( step_left => ’yes’);

$m12->set( step_right => ’yes’);

$m12->set( step_up => ’yes’);

#

# setting motor parameters

#

$m12->set( acceleration => 200000);

$m12->set( base => 20);

$m12->set( slew => 20000);

$m12->set( settle_time => 0.2);

$m12->set( unit_backlash => 0.5);

$m12->set( unit_limit_min => "...");

$m12->set( unit_limit_max => "...");

$m12->set( step_limit_min => "...");

$m12->set( step_limit_max => "...");

$m12->set( step_register => "...");

#

# calibration

#

$m12->set( position_calibrate => "...");

$m12->set( position_calibrate => "...",

noconfirm => "yes");

4.1.1 Flags: backlash, relative

Sometimes it is convenient to disable the backlash correction:

#!/usr/bin/perl

$m11 = Motor->locate( name => "mot11");

$m12->set( position => 0.1,

backlash => 0);

If needed, motors can be move relative to the current position.

#!/usr/bin/perl

$m11 = Motor->locate( name => "mot11");

$m12->set( position => 0.1,

relative => 1,

backlash => 0);

Page 19: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

4.2 Hooks: before/after move command

Sometimes it is necessary that some action is taken before a motor starts to move and that some other action is taken

after it finished a move. A hook has been implemented that allows you define a command that is executed before the

move starts (bmc) and a second command that is exeecuted after the move (amc). Here is an example:

mot1_bmc= "perl [online_dir]bmc.pl mot1"

mot1_amc= "perl [online_dir]amc.pl mot1"

vm1_bmc= "perl [online_dir]bmc.pl vm1"

vm1_amc= "perl [online_dir]amc.pl vm1"

For each motor can be different scripts. In our example the scripts are trivial. They just produce some output. The

BMC script is:

#!/usr/bin/perl -w

# file /online_dir/bmc.pl

use strict;

use Spectra;

Spectra::log( "BMC: $ARGV[0] is at " . gmup( $ARGV[0]));

1;

And the AMC script looks like this:

#!/usr/bin/perl -w

# file /online_dir/amc.pl

use strict;

use Spectra;

Spectra::log( "AMC: $ARGV[0] is at " . gmup( $ARGV[0]));

1;

The function Spectra::log()writes to online.log and to the log-window, if Online has been started as “online

-tki”.

4.3 Motor definitions

Motors may be introduced to Online by:

#!/usr/bin/perl

#

use Spectra;

use Motor;

my $status = 0;

my $m;

$m = Motor->define( name => "MOT1",

device => "stepping_motor", module => "OMS58",

base => 0xf000, vector => 0x0, channel => 0) or goto finish;

$m->set( step_register => 0,

position_calibrate => 8694.81,

slew => 10000,

base => 20,

acceleration => 20000,

conversion => 22.2222,

unit_backlash => 180.0002,

settle_time => 0.21,

unit_limit_min => -30121.64,

unit_limit_max => 65878.26,

noconfirm => 1,

nolog => 1) or goto finish;

define( name => VM1,

Page 20: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

device => "STEPPING_MOTOR",

module => "VMOTOR") or goto finish;

$status = 1;

finish:

$status;

4.4 Asynchronous moves

This example shows how motors are moved asynchronously:

#!/usr/bin/perl

#

# stepping motor example, amove()

#

use Spectra;

use Motor;

my $m2 = Motor->locate( name => "mot2");

my $pos = $m2->get( position);

my $pos_new = $pos + 2;

#

# start an asynchronous move

#

amove( mot2 => "$pos_new");

while( Spectra::check_motors_moving())

{

print "\033[5;1f MOT2 is at " . $m2->get( position) . "\n";

#

# space bar terminates move

#

if( Spectra::key() == 32)

{

print "\033[2J\033[5;1f Interrupted\n";

Spectra::stop_all_moves();

goto finish;

}

}

#

# backlash correction

#

Spectra::complete_all_moves();

finish:

4.5 Slits

Slits are defined by symbols that appear in /online dir/exp ini.exp. The symbol names consist of a generic

part, the prefix, and the specification of the jaw:

!

! exp_ini.exp

!

! the following definitions introduce two slits: sl1 and sl2

!

sl1_top = mot1

sl1_bottom = mot2

sl1_left = mot3

Page 21: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

sl1_right = mot4

sl2_top = mot5

sl2_bottom = mot6

sl2_left = mot7

sl2_right = mot8

slit_names = (sl1, sl2)

The symbol slit names is needed for the ONLINE TkI.

The slit degrees of freedom (d.o.f.) are referenced by a function-like syntax: slit( PREFIX, JAW). The available

keywords are: cx, cy, dx, dy, top, bottom, left, right. c stands for center and d for the opening.

The coordinate frame is oriented in this way: z is in the direction of the photons, y upwards and x completes

the right handed system. The slit( PREFIX, right) motor moves into the negative x-direction.

Here is an example slit code:

use Spectra;

use Motor;

my ($pos, $uli, $ula, $ubl, $acc, $base, $slew, $st);

my $cx = Motor->locate( name => "slit( sl1, cx)");

my $top = Motor->locate( name => "slit( sl1, top)");

#

# the following calls are available for all slit d.o.f.

#

$pos = $cx->get( "position");

$uli = $cx->get( "unit_limit_min"); # read-only

$ula = $cx->get( "unit_limit_max"); # read-only

$ubl = $cx->get( "unit_backlash"); # read-only

#

# since $top, since it refers to a single motor,

# it can be treated like a normal motor.

#

$uli = $top->get( "unit_limit_min");

$ula = $top->get( "unit_limit_max");

$ubl = $top->get( "unit_backlash");

$acc = $top->get( "acceleration");

$base = $top->get( "base");

$slew = $top->get( "slew");

$st = $top->get( "settle_time");

$top->set( slew => "...",

acceleration => "...");

#

# slit move

#

my $pos_new = $pos + 0.1;

my $ret = $cx->set( position => "$pos_new");

#

# single step slit moves

#

my $ret = $cx->set( step_down => ’yes’);

my $ret = $cx->set( step_left => ’yes’);

my $ret = $cx->set( step_right => ’yes’);

my $ret = $cx->set( step_up => ’yes’);

Mind that the meaning of the unit backlash of the center (cx, cy) and the opening (dx, dy) is not non-

ambiguous, since two motors are involved. In order not to move the motors too close to the limits, the function

$cx->get( "unit_backlash") returns twice the absolute value of the larger backlash.

Page 22: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

4.6 Accessing stepping motors by functions

The following example uses functions:

#!/usr/bin/perl

#

# stepping motor example, using functions

#

use Spectra;

#

# fetch motor parameters

#

print "\n";

print " Name mot12 \n";

print " Position " . gmup( "mot12") . "\n";

print " Accel " . gma( "mot12") . "\n";

print " Base " . gmb( "mot12") . "\n";

print " Slew " . gms( "mot12") . "\n";

print " Settle time " . gmst( "mot12") . "\n";

print " Unit_backlash " . gmub( "mot12") . "\n";

print " Unit_limit_min " . gmuli( "mot12") . "\n";

print " Unit_limit_max " . gmula( "mot12") . "\n";

print " Ramp_units " . gmru( "mot12") . "\n";

print " Ramp_steps " . gmrs( "mot12") . "\n";

#

# change motor parameters

#

$ret = smb( "mot12", 20); # base rate

$ret = sms( "mot12", 50000); # slew rate

#

# fetch the current positions of mot11 and mot12

#

$pos11 = gmup( "mot11");

$pos12 = gmup( "mot12");

#

$new_pos11 = $pos11 + 1;

$new_pos12 = $pos12 + 1;

$ret = move( "mot11" => $new_pos11,

"mot12" => $new_pos12);

#

# single steps movements

#

$ret = step_up( "mot11", "mot12");

$ret = step_down( "mot11", "mot12");

#

# calibration

#

$ret = calibrate( name => "mot11",

unit => 1.234,

nolog => 1, # optional, def.: 0

noconfirm => 1, # optional, def.: 0

keeping_limits => 0); # optional, def.: 1

See the section 6.14 for the complete list of motor functions.

4.7 Virtual motors

4.7.1 Description

Virtual motors (VMs) are available for the VME version of Online only. They are defined by, e.g.:

Page 23: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

ONLINE> def vm1

This definition needs to be executed once. The VM is stored in the device list which is automatically loaded during the

startup of the following Online sessions.

Virtual motors can be moved or scanned.

ONLINE> move vm1 1.5

ONLINE> * = gmup( vm1)

ONLINE> scan vm1

VMs are implemented as Perl scripts that respond to the following methods: set position, get position,

get limit min, get limit max and calibration. The scripts are stored in /online_dir, e.g.:

/online_dir/vm1.pl

VMs can have before- and after-move commands defined like other motors.

Virutal motors can be moved with other motors in a single function call:

Spectra::move( vm1 => 11,

vm2 => 12,

mot2 => 13,

mot3 => 14);

This command is executed in the following way: First vm1 is moved to 11 units. After vm1 reached its final position

vm2 is moved to 12 units. Afterwards mot2 and mot3 are move simultaneously.

For mixed movements the following statements apply:

• VMs are moved one after the other.

• VMs are moved in alphabetic order.

• Stepping motors are moved after the VMs completed their moves.

• DC motors, M663, M665 and piezo motors are treated like VMs.

4.7.2 Examples

The virtual motor examples can be found in section 10.11.

Page 24: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Chapter 5

Scans

The function scan() invokes various types of scans, e.g.:

$ret = Spectra::scan( type => ’motor’,

device => ’mot1’,

start => 0,

stop => 10,

delta => 1,

comment => ’A Test Scan’);

5.1 Scan Types

The supported types are:

type =¿ ”motor”

The default scan type, a device has to supplied:

type =¿ ”motor”,

device =¿ ”mot1”

or

type =¿ ”motor”,

device =¿ ”dummy”

type =¿ ”cm”

Combined motor scans. Two motors are simultaneously moved. The scan ranges may be different. device,

device cm and factor have to be supplied. Suppose we have a factor of 2. In this case the scan range of

device cm is twice as big as the range of device.

type =¿ ”cm”,

device =¿ ”mot1”,

device cm =¿ ”mot2”,

factor =¿ 2

type =¿ ”slit”

A slit scan. The complete list of slit degrees of freedom is: cx, cy, dx, dy, left, right, top and bottom.

type =¿ ”slit”,

device =¿ ”(slit1, cx)”.

type =¿ ”energy”

Energy scans.

type =¿ ”exafs”

exafs file =¿ ’whatever.exa’

EXAFS scans are energy with the scanning range being divided into intervals which have different resolutions

and sample times. The exafs file is an optional argument. It is easiest created by the Prepare regions widget.

type =¿ ”diff mu”

type =¿ ”diff omega”

type =¿ ”diff chi”

Page 25: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

type =¿ ”diff phi”

type =¿ ”diff gamma”

type =¿ ”diff delta”

type =¿ ”diff psi”

type =¿ ”diff two theta”

Diffractometer angle scans.

type =¿ tt om, om tt

2theta-omega or omega-2theta scans. In case of tt om the x-coordinate of the data is the 2theta position.

type =¿ de om, om de

delta-omega or omega-delta scans. In case of de om the x-coordinate of the data is the delta position.

type =¿ “hkl”

Scans in reciprocal space, need start hkl and stop hkl parameters. An exampe can be found in 10.9.16.

type =¿ “reflection”

Centers a reflection, see the example in 10.9.17.

5.2 Scan Parameters

The scan limits are specified using the following keywords: start, stop, delta, range and np.

Other useful keywords are:

auto beam =¿ 0

If set to ’1’, the scanning procedure is suspended during synchrotron injection phases and continues automatically

afterwards.

auto return =¿ 1

This flag determines where the motors are moved after the scan: 0 no return, 1 return to the position where the scan

started. 2, 3 and 4 are meaningful only, if there was a simple-scan-analysis (SSA). They select midpoint, cms or

peak.

comment =¿ ”someComment”

A line of text that is displayed in the plot and written into the output file.

continuous =¿ 0

If set to 1, selects continuous scans.

noalpha =¿ 0

If set to 1, the default , the xterm window is not updated.

noconfirm =¿ 1

If this flag is 1, the default, the output is written to a disk file without prompting the user for confirmation.

nodisplay =¿ 0

If set to 1, no graphics is displayed.

nolog =¿ 0

EXAFS feature: If set to 1, the flux ratios will be displayed on a linear scale.

preset =¿ 0

If set to 1, the timer runs in the preset mode. If the Perl script is executed in the TkI environment, the Select Scan

Devices value of this flag serves as the default.

generic macro name =¿ ”genericPart”

The generic part of the scan scripts, e.g. : generic macro name => "auto scan" selects ’before auto scan.pl’,

etc. auto scan is the default.

generic macro name gra =¿ ”genericPart”

The generic part of the .gra scan scripts, e.g. : generic macro name gra => "auto scan" selects ’be-

fore auto scan.gra’, etc. auto scan is the default.

param =¿ 12,

hkl scan feature, the psi angle.

range =¿ 10,

np =¿ 11

A way to specify a scan range. The first point of the scan is at current position - range/2.

regions =¿ ’yes’

regions file =¿ ’whatever.exa’

Select the regions scan type and optionally a regions file.

repeats =¿ 3

The number of repeats.

Page 26: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

sample time =¿ 0.2

The sample time [s], alias st.

scan name =¿ ”scanName”

The scan name. Normally scan names are automatically constructed of a generic part, which is defined by the symbol

generic scan name, and a number.

scan par =¿ 2

A scan parameter. Continuous scans use it for the sweep time.

ssa =¿ 0

If set to 1, a simple scan analysis is executed. It is applied to the SCAN GQE which is referred to by scan name. For

non-EXAFS scans it is the first counter.

start =¿ 10,

stop =¿ 20,

delta =¿ 1

A way to specify a scan range.

start =¿ 10,

stop =¿ 20,

np =¿ 11

A way to specify a scan range.

title =¿ ”someComment”

Alias for comment.

update =¿ 1

A number that specifies the update cycle.

wait time =¿ 0.2

The scanning procedure hibernates for this amount of time after the motors are stopped before it starts the measure-

ments.

5.3 Examples

Examples for scans can be found in section 10.9.

5.4 Using profiles

Normally the function Spectra::scan() uses the devices (timer, counters, MCAs, etc) as they are selected by an online

-tki widget. Sometimes it is preferable to qualify the measurement fully in the function call. Here is an example (other

examples can be found in 10.9):

Spectra::scan( device => "dummy",

start => 2,

stop => 2.1,

delta => 0.01,

st => 0.1,

title => "A Test Scan",

profile =>

{ timer => [ qw( t1)],

counter => [ qw( c1 c2 idoris hhe1)],

mca1 => { channels => 1024},

mca2 => { channels => 4096},

sca1 => { mca => "mca1",

min => 1000,

max => 2000},

flags => [ qw( write_to_disk 1

display_deadtime 1

bell_on_scan_end 1)],

before_during_function => sub {

Spectra::move( mot2 => $Spectra::SYM{ position});

}});

Notice that scan types and parameters can be selected as described in sections 5.1 and 5.2.

Page 27: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

The new feature is the profile parameter which contains the devices, flags and a function which is executed at the

beginning of the during-macro.

When Online finds the profile parameter it stores the current device selection in the file /online dir/Profile-temp.db. In

a next step the device selection is cleared and all flags are set to their defaults. Then the scan is executed using the

specifications of the profiel parameter. After the scan finished, the original status is restored.

Here is a list of flags that can be set:

automatic beamshutter, default: 0, Scan-¿Flags

Online uses was injection() instead of start and wait for timer() in the during-macro. Details about the automatic beam

shutter mode can be found in the online -tki manual ().

auto filter, default: 0, Scan-¿Flags

Some details about this feature are explained in the online -tki manual ().

automatic filter script, default: 0, Scan-¿Flags

The details about this feature are explained in the online -tki manual ().

auto return, default: 1, Scan-¿Flags

0 No auto return

1 Auto return

2 If SSA returned 1, goto midpoint

3 If SSA returned 1, goto CMS

4 If SSA returned 1, goto highest point

5 Return to start-of-scan

bell on scan end, default: 1, Scan-¿Flags

Rings the bell at the end of the scan.

coarse, default: 0, Diff-¿Alignment

Selects coarse scans during the diffractometer alignment.

continuous raw, default: 0, Scan-¿Flags

This flag can be used with continuous scans. It allows you to use VCs and MCAs in a continuous scan at the cost of

reduced temporal coverage. See the explanations in the online -tki manual ().

create info file, default: 0, Scan-¿Flags

An info file is created for each scan.

create ps file, default: 1, Scan-¿Flags

A postscript file is created.

display deadtime, default: 1, Scan-¿Flags

The deadtime is display at the top of the Scan widget.

mca doris digital, default: 1, MCA-¿Options

The MCA widget reads the DORIS current from a Web server.

doris wait for sync run, default: 0, widget: Scan-¿Flags

Place a call to Spectra::wait for sync run() into the during-macro. This function queries a Web server for

the current accelerator state. It returns, if the state is ’Sync Run’.

exafs log, default: 1, Scan-¿Options-¿Scan Parameters

The EXAFS signal is displayed using a log. scale.

fio comments, default: 0, widget: Scan-¿Flags

Online evaluates the function Spectra::fio comments() and copies the return value, a string, into the output

file. In general the string consists of several lines, e.g.: ”line1 \n line2 \n line3 \n”. If lines do not begin ’!’, they are

treated as ’official’ comments. These comments are accessible by the comment() function and they are copied into

.fio files. Mind that only up to 10 official comment lines are allowed. However, Spectra::fio comment()

may return lots of lines that begin with ’!’. The file /online dir/TkIrc.pl may contain the definition of

Spectra::fio comments().

fio parameters, default: 0, widget: Scan-¿Flags

Online evaluates the function Spectra::fio parameters() and copies the return value, a string, into the output

file. The string has the following format: ”parname1 = val1 \n parname2 = val2 \n parname3 = val3 \n”. The file

/online dir/TkIrc.pl may contain the definition of Spectra::fio parameters().

include motor positions, default: 1, Scan-¿Flags

The motors positions are stored in the .fio file.

include regions, default: 0, Scan-¿Flags

The regions are stored in the .fio file.

mca y log, default: 0, Scan-¿Options-¿Select Scan Devices

MCAs are displayed using a log y-scale.

Page 28: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

mostab analog, default: 0, Misc-¿MOSTAB

If set to 1, the DORIS current is fed into the front panel of the MOSTAB via cable.

mostab i1, default: 0, Misc-¿MOSTAB

If it is 0, no DORIS signal is used for the MOSTAB, neither analog nor digital.

mostab peakSearch, default: 0, Misc-¿MOSTAB

Triggers the peak search of the MOSTAB in the before-macro, Mostab(”p”).

normalize counts, default: 0, Scan-¿Options-¿Select Scan Devices

The counter contents are divieded by the sample time.

preset, default 0, Scan-¿Options-¿Select Scan Devices

If set to 1, the timer runs in preset mode, i.e. no sample time is supplied, instead the timer is loaded with a value that is

decremented by a flux signal.

print ps file, default: 0, Scan-¿Flags

The postscript file is automatically printed.

sca net, default: 0, Scan-¿Options-¿Select Scan Devices

If enabled, the SCAs are calculated from the RIOs by subtracting a linear background.

scan x log, default: 0, Scan-¿Flags

The x-scale is logarithmic.

scan y log, default: 0, Scan-¿Flags

The y-scale is logarithmic.

smartListboxUpdate, default: 0, Scan-¿Flags

stack plots, default: 0, Scan-¿Options-¿Scan Parameters

A repeated continuous scan option, no display during sweeps

use mostab, default: 0, Scan-¿Flags

The MOSTAB operation is described on the online -tki manual ().

write to disk, default: 1, Scan-¿Flags

The disk file is created without prompting for confirmation.

zip mca files, default: 0, Scan-¿Options-¿Select Scan Devices

The directory that contains the MCA files is zipped.

5.5 Symbols used in scan macros

Online maintains some symbols that can be used in the scan macros (before-, during- and after-some-name).

$Spectra::SYM delta

The current step width, not valid for regions scans.

$Spectra::SYM np total

The total number of scan points.

$Spectra::SYM rindex

The current repeat index. Starts at 1.

$Spectra::SYM repeat total

The total no. of repeats.

$Spectra::SYM repeat flag

1 for repeated scans, 0 otherwise.

$Spectra::SYM position

$Spectra::SYM position setpoint

The actual position and the nominal position.

$Spectra::SYM sample time

The sample time.

$Spectra::SYM scan name

The scan name.

$Spectra::SYM sindex

The current index, starts at 1, is less or equal np total.

$Spectra::SYM start

$Spectra::SYM stop

The limits.

$Spectra::SYM wait time

Page 29: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Chapter 6

Functions

6.1 General remarks

The functions that are explained in this section, are defined in the package Spectra. Therefore a complete name

needs the prefix Spectra::, like in $ret = Spectra::cls();. This syntax is always correct.

However, some users may find it convenient to drop the prefix, in order to save keystrokes. Therefore most of the

function names are ’exported’, allowing to say, e.g. : $ret = cls();. The problem is that not all function names have

been exported since some of them conflict with Perl intrinsic names, like read(), open(), close(), print(), etc. To

conclude: You are always on the save side, if you refer to function by the complete name, i.e. including the prefix

Spectra::.

6.2 Miscellaneous Spectra Functions

6.2.1 activate(), deactivate()

activate(), deactivate()

Activates/deactivates GQEs:

Spectra::activate(); all GQEs

Spectra::activate( name =¿ ”scan1”); single SCAN

6.2.2 autoscale()

autoscale()

Calculates the window limits and tic distances for SCANs. Valid parameter are name, x, y, noreverse and window:

Spectra::autoscale(); all GQEs

Spectra::autoscale( name =¿ ”scan1”); single GQE

Spectra::autoscale( y =¿ ’yes’); all GQEs, y-axis only

Spectra::autoscale( window =¿ ’yes’); roughly keeping window limits.

6.2.3 attribute()

This function gets/sets the attributes of the graphical queue elements (GQEs).

#!/usr/bin/perl -w

use strict;

use Spectra;

Spectra::delete();

Spectra::Gra_command( " create t1 0 10 100");

Spectra::cls();

print "\n";

print " x_max = " . Spectra::attribute( name => "t1",

get => "x_max") . "\n";

Spectra::attribute( name => "t1",

x_max => 9.99);

Page 30: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

print " x_max = " . Spectra::attribute( name => "t1",

get => "x_max") . "\n";

print "---\n\n";

6.2.4 book name(), book slot(), book subindex()

The book is the structure that orders the graphical queue elements (GQEs). It is a 2-dimensional array, addressed by

a slot number and a subindex. SCAN, ARRAYs and the like have a non-zero slot number and a subindex that is zero.

TEXTs, TAGs, etc. share the slot number with the SCAN they belong to. Apart from the indices GQEs have names.

The functions book name(), book slot() and book subindex() return the book information.

#!/usr/bin/perl -w

use strict;

use Spectra;

Spectra::delete();

Spectra::Gra_command( " create t1 0 10 100");

Spectra::cls();

print "\n";

print " book_name(1) = " . Spectra::book_name( "1") . "\n";

print " book_name(t1) = " . Spectra::book_name( "t1") . "\n";

print " book_slot(t1) = " . Spectra::book_slot( "t1") . "\n";

print " book_slot(1) = " . Spectra::book_slot( "1") . "\n";

print " book_subindex(t1) = " . Spectra::book_subindex( "t1") . "\n";

print "---\n\n";

#

# the output:

# book_name(1) = T1

# book_name(t1) = T1

# book_slot(t1) = 1

# book_slot(1) = 1

# book_subindex(t1) = 0

6.2.5 calc()

Section 7.4.5 shows how calculations with scans can be done.

6.2.6 ceil(), floor()

ceil(), floor()

$ret = Spectra::ceil( 1.9);

6.2.7 cleanup()

cleanup()

Deletes GQEs which are recorded on disk and which are not active, then compresses the queue:

Spectra::cleanup();

6.2.8 cls()

cls()

Clear the graphical and the text screen:

Spectra::cls();

Spectra::cls( graphic =¿ ’yes’);

Spectra::cls( text =¿ ’yes’);

Page 31: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.2.9 date(), date and time(), doty(), doty2date(), time stamp nexus()

date(), date and time(), time()

$ret = Spectra::date and time();

doty()

Returns the day-of-the-year ([0,365] or [0,366]):

$ret = Spectra::doty();

doty2date()

Converts a real number [0,365[ or [0,366[ to a list containing the data. The function uses the current date to decide

whether it is a leap year or not:

my $doty = Spectra::doty();

my ( $mday, $mon, $year, $hour, $min, $sec) = Spectra::doty2date( $doty);

time stamp nexus)

$ret = Spectra::time stamp nexus();

6.2.10 delete()

delete()

Deletes non-preserved queue elements and calls GQE::Cleanup() for a garbage collection:

Spectra::delete(); delete all GQEs

Spectra::delete( name =¿ ”scan1”); delete a single GQE

Spectra::delete( name =¿ ”scan1.*”); delete a slot

6.2.11 display()

Spectra::display()

Display the active GQEs.

Spectra::display( cls =¿ ’yes’);

The graphical screen is cleared before the display.

Spectra::display( over =¿ ’yes’);

No clear-screen, no axes, no TEXTs. An example can be found in 10.13.

Spectra::display( update =¿ ’yes’);

This parameter is an Online feature: The whole plot is re-displayed only, if one SCAN changes its window limits.

Otherwise the new data points are just filled in. See also section 7.4.6.

Spectra::display( vp =¿ ’yes’);

This flag tells Spectra to display all active GQEs in separate viewports.

6.2.12 dump()

dump(), restore()

Dumps/restores the whole Spectra queue to/from a disc file. Optional arguments: file name and noconfirm:

Spectra::dump( file name =¿ ”test”, noconfirm =¿ ”yes”);

Spectra::restore( file name =¿ ”test”, noconfirm =¿ ”yes”);

6.2.13 flag()

flag()

$ret = Spectra::flag( ”debug”);

$ret = Spectra::flag( ”error on”);

$ret = Spectra::flag( ”interrupt move”);

$ret = Spectra::flag( ”motor logging”);

$ret = Spectra::flag( ”online”);

$ret = Spectra::flag( ”perltk”);

$ret = Spectra::flag( ”privilege”);

Page 32: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

$ret = Spectra::flag( ”simulation”);

6.2.14 linear regression(), parabolic regression()

The following function returns the coefficients of the fit f = a bx. The parameter t is the quality of the fit t =

chi**2/d.o.f (d.o.f = np - 2).

linear regression()

$a = Spectra::linear regression( ”test”, ”a”);

$b = Spectra::linear regression( ”test”, ”b”);

$t = Spectra::linear regression( ”test”, ”t”);

The following function returns the coefficients of the fit f = a + bx + cx**2. The parameter t is the quality of

the fit t = chi**2/d.o.f (d.o.f = np - 2).

parabolic regression()

$a = Spectra::parabolic regression( ”test”, ”a”);

$b = Spectra::parabolic regression( ”test”, ”b”);

$c = Spectra::parabolic regression( ”test”, ”c”);

$t = Spectra::parabolic regression( ”test”, ”t”);

6.2.15 get last error()

get last error()

Returns the last error messages:

Spectra::get last error();

6.2.16 gra command()

gra command()

Execute a Spectra/Online command:

Spectra::gra command( ”create test 0 10 100”);

6.2.17 key(), keyw()

key(), keyw()

$let = Spectra::keyw();

6.2.18 max(), min()

min(), max()

$bigger = Spectra::max( $val1, $val2);

6.2.19 postscript(), print()

post( ”/dina4/print/nocon”)

Creates a Postscript file and prints it on the default printer.

print()

The same as Gra command( ”post/print/nocon/dina4”);

$ret = Spectra::print();

6.2.20 read()

read( name =¿ ’filename’, format =¿ ’keyword’, ...)

Reads a disk file. The formats are fio (default) and gqe:

Spectra::read( name =¿ ’si 111’, format =¿ ’fio’);

Page 33: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.2.21 read line()

$ret = Spectra::read line( ”Enter¿ ”);

6.2.22 roi()

$ret = Spectra::roi( $scan name, $x min, $x max);

6.2.23 run()

run( ”file.pl”)

run( ”file.gra”)

Executes a script, .pl or .gra:

Spectra::run( ”test.pl”);

6.2.24 secnds()

Returns the number of seconds since image start.

6.2.25 spectra dir()

Returns the directory path of the Spectra image:

print ” spectra-dir: ” . Spectra::spectral dir() . ”\n”;

may produce

/home/experiment/Spectra/bin

6.2.26 symbol alias()

Returns the symbol name(s) that point to a string. If more than one symbol points to a string, a comma-separated list is

returned.

use Spectra;

$Spectra::SYM{ "sym1"} = "abc";

print " the alias of ’abc’ is " . Spectra::symbol_alias( "abc") . "\n";

#

# returns ’SYM1’

#

$Spectra::SYM{ "sym2"} = "def";

$Spectra::SYM{ "sym3"} = "def";

print " the alias of ’def’ is " . Spectra::symbol_alias( "def") . "\n";

#

# returns ’SYM2, SYM3’

#

6.2.27 ssa()

The simple scan analysis:

($ssa_status, $cms, $midpoint, $int, $bg_int,

$fwhm, $peak_x, $peak_y, $bg_l, $bg_r) =

Spectra::ssa( name => "ScanName",

stbr => xval, # optional

x_min => xval, # optional

x_max => xval); # optional

The meaning of the qualifiers:

stbr The signal to background ratio. $ssa status is zero, if the signal is not stbr times above the background.

Page 34: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

x min, x max The SSA is calculated for the points inside the specified limits.

The ssa() function returns:

$ssa status return status. $cms contains the reason, if $ssa status == 0. Reason: 0: ok, 1: np ¡ 6, 2: signal-to-background, 3:

no y(i) ¿ 0., 4, 5: midpoint calc, 6: max. outside x-range

$cms center of mass

$midpoint the midpoint between those points which are at 50% of the peak

$int integral

$bg int integral of the background

$fwhm full width half maximum

$peak x x-coord. of the highest point

$peak y y-coord. of the highest point

$bg l left background

$bg r right background

6.2.28 version()

Returns the Spectra link time.:

print ” version: ” . Spectra::version() . ”\n”;

produces

version: 8 11:28:31 CET 2005

6.2.29 yesno(), noyes()

$ret = Spectra::yesno( ”Write to disk”);

6.2.30 Special Functions

The section contains functions that are not of general interest:

get first active scan()

Returns the name of the first active SCAN or “0”, if no active SCAN exists:

$name = Spectra::get first active scan();

Spectra::Exp init()

Initialises an Online session. This function is intended to be used by scripts that are not invoked during an Online

session.

Spectra::get free line(), Spectra::get free slot()

$ret = Spectra::get free slot();

Spectra::Gra init()

Initialises a Spectra session. This function is intended to be used in scripts that are not invoked during a Spectra session.

Note that Spectra does not open a graphics terminal, if the environment variable SPECTRA NOGRAPHIC has been

set.

Spectra::Gra input()

Calls the Spectra command line interface,

memory free(), memory total(), meminfo()

memstat()

Return the ratio used/total memory. $ratio = Spectra::memstat();

scan number()

Returns the last scan number.

search symbol(), search scan(), search gqe()

Return 1, if the specified GQE exists.

Page 35: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Code Reason

1 Scan terminated due to beam loss condition (Min C1)

Table 6.1: Gra errno() Codes

sigbus(), sigfpe(), sigint(), sigsegv()

Raise signals.

gra errno( $code), gra errno()

gra errno() returns a reason code that has been set when an error occured. The code is cleared when the function

returns. Table 6.2.30 displays the codes that are set by Online. Users may also set a reason code and make use of it.

Page 36: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.3 Miscellaneous Online functions

6.3.1 Util::append scan info file()

Util::append scan info file( ”some text”);

Appends a line to the scan info file, if the ’Create info file’ option of the Flags popup-menu of the Scan widget is

selected.

6.3.2 awe()

$ret = awe( 9);

Reads the AWE encoder, via GPIB.

6.3.3 create scan name()

create scan name(), create scan name( ”generic part”)

Returns a valid scan name. If no argument is supplied, the function evaluates $SYMgeneric scan name to find the

generic part of the scan name, def.: hasylab. This function is intended to be used by Perl scripts (user code) that

execute scans explicitly without relying on Spectra scan procudures:

$ret = Spectra::create scan name();

6.3.4 define()

$ret = Spectra::define();

Introduces devices to Online, e.g.:

$ret = define( name => "mot1",

device => "stepping_motor",

module => "oms58",

base => "0xf000",

vector => 0,

channel => 0);

$ret = define( name => "mca1",

device => "mca",

module => "mca_8701",

base => "0x7000",

base2 => "0xd00000",

vector => 0,

channel => 0);

$ret = define( name => "dso1",

device => "dso",

module => "lc424",

host => "hasvuvosz2m",

port => 1861);

$ret = define( name => "dso2",

device => "dso",

module => "lc584",

gpib => 7);

$ret = define( name => "c1",

device => "counter",

crate => 1,

slot => 23,

channel => 0);

Page 37: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.3.5 device(), n device()

$ret = device( $i);

Returns the name of the i-th device. i starts at 0.

$ret = n device();

Returns the number of devices.

6.3.6 device record()

$ret = device record( ”T1”);

for local devices: name T1 device TIMER module DGG2 base 0x1000 channel 0

for Tango devices: name T1 device TIMER module DGG2 server //node:10000/bw4/exp/t1

Example:

my %h_local = split " ", Spectra::device_record( "mot1");

if( defined( $h_local{ server}))

{

print " name $h_local{ name} at $h_local{ server} \n";

}

6.3.7 device type()

$ret = device type( ”T1”);

Returns: TIMER.

6.3.8 doris(), doris is sync run(), doris state(), doris wait for sync run()

$ret = doris();

The Doris current. If there is a connection timeout, a 0 is returned but no error is generated. If the flag FLAG USE DORIS CURRENT

is found to be 0, Online doesn’t not contact the server but returns 0.

$ret = doris is sync run();

Returns 1, if DORIS is in the state ”Sync Run”.

$ret = doris state();

The DORIS state, e.g.: “Sync Run”. If there is a connection timeout, an empty string is returned but no error is

generated.

$ret = doris wait for sync run();

Returns 1, if DORIS is in the state ”Sync Run”. If not, Online waits for DORIS to enter this state. The wait procedure

may be interrupted by ”STOP” (-tki) or by pressing the space bar. In this case the function returns 0. If the wait state

ends with ”Sync Run”, Online waits for TIME HEATUP (or 30) seconds before it returns 1.

6.3.9 elcomat(), elcomat ascii()

$ret = elcomat( ”x”);

$ret = elcomat( ”y”);

The serial line interface is set to 2400 Bd. I/O is done via /dev/ttyS0.

$ret = elcomat ascii( ”ttyS0”, ”x”);

$ret = elcomat ascii( ”ttyS0”, ”y”);

The serial line interface is set to 19200 Bd.

6.3.10 get counters(), get motors(), get timers(), etc.

get counters()

get encoders()

get mcas()

get motors()

get timers()

get vfcadcs()

Returns an array of all devices of a specified class, e.g.:

@list = Spectra::get motors();

Page 38: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.3.11 get devices(), get modules()

get devices( ”deviceType”)

get modules( ”moduleName”)

Return a string that consists of blank-separated device names that belong to the specified device type or module type

class, e.g.

$ret = Spectra::get devices( “TIMER”);

$ret = Spectra::get modules( “DGG2”);

6.3.12 log()

log( ”line-of-text”)

The line-of-text is written to ./online.log, /onine dir/online.log and the log widget, if TkI is

active. Trailing white space is removed. Note that there are also the functions Util::info() and Util::display text(), see

6.4.2 and 6.4.1.

6.3.13 mpa3()

This function controls the MPA3 detector electronics.

$ret = mpa3( ”halt”);

$ret = mpa3( ”save”, ”fileName”);

$ret = mpa3( ”start”);

$ret = mpa3( ”start”, ”time”);

$ret = mpa3( ”status”);

fileName: full path specification’

status: returns 1, if ’on’

time: in seconds

e.g.:

$ret = Spectra::mpa3( ”start”, ”3”);

sleep(3);

while(1)

last if( !Spectra::mpa3( ”status”);

last if( Spectra::key() == 32);

Spectra::wait( 0.1);

$ret = Spectra::mpa3( ”save”, ”d:/data/probe 00012 00001”);

If a new set point is specified, Online also starts the ramp and waits for the voltage to reach the final value.

6.3.14 petra(), petra is sync run(), petra state(), petra wait for sync run()

$ret = petra();

The Petra current. If there is a connection timeout, a 0 is returned but no error is generated. If the flag FLAG USE PETRA CURRENT

is found to be 0, Online doesn’t not contact the server but returns 0.

$ret = petra is sync run();

Returns 1, if PETRA is in the state ”Betrieb-¿Experimente”.

$ret = petra state();

The PETRA state, e.g.: “Betrieb-¿Experimente”. If there is a connection timeout, an empty string is returned but no

error is generated.

$ret = petra wait for sync run();

Returns 1, if PETRA is in the state ”Betrieb-¿Experimente”. If not, Online waits for PETRA to enter this state. The

wait procedure may be interrupted by ”STOP” (-tki) or by pressing the space bar. In this case the function returns 0. If

the wait state ends with ”Betrieb-¿Experimente”, Online waits for TIME HEATUP (or 30) seconds before it returns 1.

Page 39: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.3.15 privilege()

$ret = Spectra::privilege()

Returns the current privilege flag.

$ret = Spectra::privilege( flag =¿ 1)

$ret = Spectra::privilege( flag =¿ ”yes”)

$ret = Spectra::privilege( flag =¿ 0)

$ret = Spectra::privilege( flag =¿ ”no”)

Sets/clears the privilege flag. Notice that the privilege flag can only be set, if the user is listed in /online dir/online experts.lis.

e.g.:

$ret = privilege( flag =¿ 1);

6.3.16 protect()

$ret = Spectra::protect( mot1 =¿ 1, mot2 =¿ 1)

$ret = Spectra::protect( mot1 =¿ 0, mot2 =¿ 0)

Sets/clears the motor protection flags. The function returns an error, if the privilege flag is not set.

6.3.17 module name()

$ret = module name( ”C1”);

Returns a string like: V260.

6.3.18 ortec972()

$ret = ortec972( ”hasts3”, 4311, ”SHOW GAIN COARSE” );

$ret = ortec972( ”hasts3”, 4311, ”SET GAIN COARSE”, 3 );

Coarse gain: 0 - 7 (gain = 2.5× 2val)

$ret = ortec972( ”hasts3”, 4311, ”SHOW GAIN FINE” );

$ret = ortec972( ”hasts3”, 4311, ”SET GAIN FINE”, 2121 );

Fine gain: 1841 - 4095

$ret = ortec972( ”hasts3”, 4311, ”SHOW SHAPE” );

$ret = ortec972( ”hasts3”, 4311, ”SET SHAPE”, 1);

Shapes: 1, 2

$ret = ortec972( ”hasts3”, 4311, ”ENABLE LOCAL” );

$ret = ortec972( ”hasts3”, 4311, ”ENABLE REMOTE”);

$ret = ortec972( ”hasts3”, 4311, ”SHOW REMOTE”);

$ret = ortec972( ”hasts3”, 4311, ”ENABLE PUR” );

$ret = ortec972( ”hasts3”, 4311, ”DISBALE PUR”);

$ret = ortec972( ”hasts3”, 4311, ”SHOW PUR”);

Port numbers at hasb1: 4311, 4312, 4313.

6.3.19 search device()

$ret = Search device( ”C1”);

Returns 1, if the specified device exists.

6.3.20 TkITableBlank(), TkITablePop()

Updating the motor positions in the TkI toplevel table might take too much time. This can be avoided with the help of

the functions TkITableBlank() and TkITablePop() which turn the table to blank or back to the initial state.

Page 40: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

#!/bin/env perl

use Spectra;

Spectra::TkITableBlank();

Spectra::move( "exp_mot65" => 6);

Spectra::move( "exp_mot65" => 5.9);

Spectra::TkITablePop();

6.3.21 trainno()

$ret = trainno();

A VUV-FEL feature, the current train number.

6.3.22 Spectra::was beamlos doris()

$ret = Spectra::was beamloss doris( $currentMin, $waitTime);

The function returns 0, if the current is above currentMin [mA]. Otherwise it waits for the current to rise above

currentMin, waits for waitTime seconds and returns 1.

6.3.23 Spectra::was beamlos petra()

$ret = Spectra::was beamloss petra( $currentMin, $waitTime);

The function returns 0, if the current is above currentMin [mA]. Otherwise it waits for the current to rise above

currentMin, waits for waitTime seconds and returns 1.

6.3.24 Spectra::was injection()

This function is intended to be used at automatic beamshutter beamlines. It detects an injection and waits for the beam.

$ret = Spectra::was injection( ”c id”, ”t id”, ”sample time”, ”counts min”, ”wait time”);

Alias: wi()

counts min: minimum count rate per second

wait time: heat-up time

The timer t id is opened for sample time seconds. The function returns 0, if the beam was not lost in the meantime.

Counter c id (gated by t id) is used to monitor the beam. It is read after time intervals of 1 second, until sample time

is reached. The counter is never resetted by this function as long as the beam stays.

If the count rate falls below counts min, Online waits for the beam (rate ¿ counts min). After a sufficient intensity

was found, Online waits for wait time seconds before control is returned. This allows the optical components to

heat up.

The function returns 1, if there was an injection.

The user may interrupt the wait states by pressing the space bar. In this case Online sets INTERRUPT SCAN to 1 and

sets the abort flag causing command files to be exited.

If Online detects that the contents of c id is 0 when wi() is called, it resets all counters after the beam is back and

repeats wi().

6.3.25 waveform(), dso()

These function operate the digital sampling oscilloscopes of LeCroy.

Spectra::waveform( dso id, [$chan, [,$np [, $sparsing [, $offset]]]])

Alias: Wf()

Reads the waveform data structures and copies them to a GQE.

Page 41: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

chan: the channels that are transfered. The following values are allowed: 1, 2, 3, 4, ALL, 12, 123, TA, TB, TC, default:

ALL

np, the number of points: [1,100000], default: 1000

sparsing, interval between the points, def.: 1

offset, first point, def.: 0

$ret = Spectra::wf( ”dso1”, 1, 1024, 1, 0);

Dso()

Sends/receives strings to/from the DSO.

$ret = Spectra::dso( ”dso1”, ”C1:VDIV 50 MV”);

DSOs are defined by:

define/dev=DSO/mod=LC424/host=hasvuvosz2m/port=1861 dso1

def/dev=dso/mod=lc584/gpib=7 dso2

An example of how to operate a DSO via the virtual counter interface can be found here 10.12.9.

6.3.26 vhq205l(), HV power supply

This function controls the VHQ205L HV power supply of ISEG (2x 5 kV, 1 mA).

Write:

$ret = vhq205l( ”hv1”, $keyword, $value);

Read:

$ret = vhq205l( ”hv1”, $keyword);

Keywords:

actual current, R

actual value, R

current limit, muA, R/W

data ready, R

D0 voltage A

D1 current A

D2 voltage B

D3 current B

hw limits, front panel switches position, R

D0..D3 current

D4..D8 current

modul, R

ramp, V/s [2,255], R/W

register 1, R

D0 Output voltage channel A is zero

D1 Control switch, 0 -¿ DAC, 1 -¿ manual

D2 Output polarity, 1 -¿ positive

D3 HV on (0)/off (1)

D4 Kill switch, 0 -¿ disabled

D5 Output voltage derivative, 1 -¿ rising

D6 Status V-out, 1 -¿ V-out changing

D7 Error on channel A, 1 -¿ error

D8 ... channel B

register 2, R

D0 Timeout error

Page 42: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

D1 I-out ¿ I-max

D2 V-out reached set point

D3 A front panel switch has been changed

D4 Ratio V-setpoint/V-max ¿ 1

D5 External INIHIBT is/was active

D6 Exceed/ed V-max or I-max

D7 Quality of V-out not garanteed

D8 ... channel B

set point, R/W

e.g.:

$ret = vhq205l( ”hv12”, ”actual value”);

$ret = vhq205l( ”hv12”, ”set point”, ”1234”);

If a new set point is specified, Online also starts the ramp and waits for the voltage to reach the final value.

6.3.27 vhsc005n(), HV power supply

This function controls the VHSC005 HV power supply of ISEG (12x -500 V, 15 mA).

Write:

$ret = vhsc005n( ”hv1”, $keyword, $value);

Read:

$ret = vhsc005n( ”hv1”, $keyword);

e.g.:

$ret = vhsc005n( ”hv1”, ”VoltageMeasure”);

$ret = vhq205l( ”hv12”, ”VoltageSet”, -120);

If a new set point is specified, Online also starts the ramp and waits for the voltage to reach the final value.

Here is the list of keywords. ’RW’ means that a keyword can be read or written. The first list displays the keywords

that control ’module registers’. These registers apply for all channels.

Keywords for the board

VoltageRampSpeed, RW

In per cent of the NominalVoltage per second. The upper limit is 20%/sec,

the lower limit 1mV/s.

CurrentRampSpeed, RW

not implemented

VoltageMax, R

The actual trim potentiometer reading, in per cent.

VoltageLimit = VoltageNominal*VoltageMax/100

CurrentMax, R

The actual trim potentiometer reading, in per cent.

CurrentLimit = CurrentNominal*CurrentMax/100

SupplyP5, R

The actual value of the 5 V power supply.

SupplyP12, R

The actual value of the +12 V power supply.

SupplyN12, R

The actual value of the -12 V power supply.

Temperature, R

The actual temperature of the board

The following keyword control individual channels:

Keywords for each channel:

VoltageSet, RW

Page 43: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

The voltage setpoint, valid in the range 0 to VoltageLimit (see above).

The procedure to set a voltage has several steps. First Online writes

the ramp speed, the VoltageBounds and the CurrentSet to the module. Then

is sets the setpoint and enables the ramp. It waits until the VoltageMeasure

reaches VoltageSet within VoltageBounds.

CurrentSet, RW

The current setpoint, valid in the range 0 to CurrentLimit (see above)

VoltageMeasure, R

The actual voltage, in V.

CurrentMeasure, R

The actual current, in A.

VoltageBounds, RW

The voltage deadband.

CurrentBounds, RW

The current deadband.

VoltageNominal, R

The maximal possible output voltage (500)

CurrentNominal, R

The maximal possible output current (0.015)

6.4 Miscellaneous Utility Functions

6.4.1 Util::display text()

Util::display text( ”title”, ”some text”);

Util::display text( ”title”, ”some other text”);

Opens a window and puts some lines of text in it. If the line is empty, the window is cleared.

Page 44: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.4.2 Util::info()

Util::info( ”some text\n a new line\n and another line”);

Displays some text.

6.5 ADC/DAC, MCA

control mca

$ret = control mca( ”mca11”, “OFF”);

a function to operate the SDD7. See the hardware section of the Online manual for details.

get adc threshold max, ˜ min, alias Gata, Gati

get dac voltage, alias Gdv

get dac voltage limits max, ˜ min, alias Gdvla, Gdvli

get dac voltage range max, ˜ min, alias Gdvra, Gdvri

Read adc, alias Ra

$val = Ra( ”adc1”);

Read mca

$ret = Read mca( ”mca1”, $bank, $name, 8192);

Read memory, alias Rm

Run adc

$ret = Run adc( ”mca1”, ”t1”, ”name”, 8192, $nsec);

Start mca

$ret = Start mca( ”mca1”, 0);

status mca

$ret = status mca( ”mca11”, “HV ON ON”);

a function to operate the SDD7. See the hardware section of the Online manual for details.

Stop mca

$ret = Stop mca( ”mca1”, 0);

Test mca

$ret = Test mca( ”mca1”, 0);

Reset adc

$ret = Reset adc( ”vfc1”);

set adc threshold max(), ˜ min, alias Sata, Sati

set dac voltage, alias Sdv

$ret = Sdv( ”dac1”, $voltage);

set dac voltage limit max(), ˜ min, alias Sdvla, Sdvli

set dac voltage range max, ˜ min, alias Sdvra, Sdvri

set tdc offset, alias Stdcof

set tdc overflow, alias Stdcov

set tdc range, alias Stdcr

Page 45: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.5.1 VFC ADC

The following functions can used for tthe VFC ADC:

get_adc_gain(), gag() gain from [0.25, 0.5, 1, 2, 5, 10]

set_adc_gain(), sag()

get_adc_offset(), gao() offset from [0 - 10V]

set_adc_offset(), sao()

set_adc_polarity(), sap() 0 (negative) or 1 (positive)

get_adc_polarity()

6.5.2 MCA()

The function Mca() takes a single MCA data set:

$ret = Spectra::mca(

adc => "MCA1", # Default: ADC_MCA

adc2 => ’...’, # Default: ADC2_MCA

cdt => ’...’, # Composite dead time counter, default: CDT_MCA

a_c2t_cdt => ’...’, # counts-to-time, a + b*counts, def.: A_C2T_CDT_MCA

b_c2t_cdt => ’...’, # counts-to-time, a + b*counts, def.: B_C2T_CDT_MCA

channels => ’...’, # Default: CHANNELS_MCA

comment => ’...’, # Optional

include_motors => ’yes’, # Optional

life_time => "5", # Optional

monitor => "...", # Monitor counter, default: MONITOR_MCA

monitor2 => "...", # 2. Monitor counter, default: MONITOR2_MCA

noalpha => ’yes’, # Optional, no output to alpha screen

noconfirm => ’yes’, # Optional, over-write disk file

nodisplay => ’yes’, # Optional, no graphical output

refresh_cycle => "5", # Default: 5

sample_time => "5", # Default: SAMPLE_TIME_MCA

scan_name => "...", # Default: GENERIC_MCA_NAME

store => ’yes’, # Optional, write disk file

log_scale_y => 1, # Optional

timer => ’t1’, # Default: TIMER_MCA

update_time => ’1’, # Default: 1

x_min => ’...’, # Window limit, optional

x_max => ’...’); # Window limit, optional

If LIFE TIME is supplied, ONLINE uses a dead time corrected sample time.

See 10.8 for an example.

6.5.3 Another MCA example

#!/bin/perl

use Spectra;

$bank = 0;

$ret = Clear_mca( "mca1", $bank);

$ret = Start_mca( "mca1", $bank);

#

# start-and-wait-for-timer, 1 second

#

$ret = Sawft( "t1", 1);

$ret = Stop_mca( "mca1", $bank);

$ret = Read_mca( "mca1", $bank, "testname", 8192);

Autoscale();

display();

Page 46: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

If it is not necessary to issue the start and stop commands explicitly, the above code can be written in a compact

way:

#!/bin/perl

use Spectra;

$ret = Run_adc( "mca1", "t1", "testname", 8192, 5);

Autoscale();

display();

6.5.4 SDD7 Example

After the SDD7 has been initialized it can be operated in the usual way. The initialization sequence is explained in the

hardware section of the Online manual.

#!/usr/bin/perl

use Spectra;

$ret = clear_mca( "mca11", 0);

$ret = start_mca( "mca11", 0);

Spectra::sawft( "t1", 1);

$ret = stop_mca( "mca11", 0);

$ret = read_mca( "mca11", 0, "dat1", 4096);

The bank no. 0 has no meaning. It is supplied because the functions expect it. For the SDD7 the channel number is

fixed: 4096.

6.5.5 XIA DXP-XMAP

The functions that are explained in this section operate the XIA DXP-XMAP in mapping mode. The word pixel is a

set of MCA spectra ( 1 - 4) which are taken during a single gating period.

start mca mapping( name =¿ $name, nMca =¿ $nmca, nPixel =¿ $npixel, mask =¿ $mask)

starts a thread that controls the measurement. The status of the thread can be tested with the function test mca mapping().

The thread terminates when the current pixel number reaches $nPixel. Normally the pixel number advances by

the leading edge of a gate signal.

$name: the device name of the MCA

$nPca: the number of bins in a MCA, e.g.: 1024. Applies for all 4 channels.

$mask: selects the channels of the module: ’1’ selects channel 0, ’3’ selects channel 0 and 1, ’15’ select all 4

channels.

read mca mapping( name =¿ $name, dirName =¿ $dirName, sweepNo =¿ $sweepNo)

reads the buffer of the Tango server that operates the XMAP. Every MCA spectrum is stored in a separate file.

The device name, $name, is the first part of the file name. It is followed by a number that contains the sweep

number and the MCA number within a sweep. If several channels are selected by $mask, their device names

are automatically created, e.g.: suppose $name is MCA10 (channel 0). Then MCA11 is assigned to the next

channel.

$dirName specifies the directory where the MCA files are stored. If it does not exist, it is created.

$name: the device name of the MCA

$dirName: the name of the directory where the MCAs are stored.

$sweepNo The sweep no. will be part of the file name

Page 47: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

stop mca mapping( name =¿ $name)

Normally there is no need to use this function because the sequence is terminated after the XMAP created as

many pixels as have been requested.

test mca mapping( name =¿ $name)

Returns 1, if the thread is busy.

read mca mapping current pixel( name =¿ $name)

Returns the current pixel. This number is less than $npixel.

advance mca mapping( name =¿ $name)

Debugging feature: advances the pixel using host control. This is normally done by a gate signal.

6.5.6 Example

The following script uses the mapping mode.

#!/bin/env perl

use Spectra;

my $nPixel = 4;

my $mask = 1;

my $mca = "MCA10";

my $sweepNo = 1;

my $dirName = "resultsMapping";

if( -d $dirName)

{

system( "/bin/rm -r $dirName");

}

if( !Spectra::start_mca_mapping( name => $mca,

nMca => 1024,

nPixel => $nPixel,

mask => $mask))

{

goto finish;

}

foreach my $ i ( 1 .. $nPixel)

{

Spectra::advance_mca_mapping( name => $mca);

print " current pixel " .

Spectra::read_mca_mapping_current_pixel( name => $mca) . "\n";

print " test mca " . Spectra::test_mca_mapping( name => $mca) . "\n";

wait( 0.5);

}

Spectra::read_mca_mapping( name => $mca,

dirName => $dirName,

sweepNo => $sweepNo);

finish:

Page 48: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.6 Counter/timer

check timer, alias ct

get offsets

This function determines the counter offsets and stores them in the symbols SCAN OFFSET C1, SCAN OFFSET C2,

.... The function relies on the symbols SCAN TIMER, SCAN C1, SCAN C2.... The sample time can be specified as

the argument, the default sample time is 10s.

$ret = get offsets( 3);

get timer external base, alias gteb

get counts, alias gc

reset all counters, alias resaco

$ret = resaco();

reset counter, alias resco

read and reset counter, alias rrc

read counter, alias rc

$val = Rc( ”c1”);

set timer external base, alias steb

start and wait for cont timer, alias sawfct

start and wait for timer, alias sawft

$ret = sawft( ”t1”, ”1.5”);

start and wait for preset timer, alias sawfpt

$ret = sawfpt( ”t1”, ”10000”);

start timer, alias st

$ret = st( ”t1”, ”1.234”);

start timer using motor, alias stum

$ret = stum( $timer, $st, $motor, $pos, $tolerance);

stop timer, alias stpt

vfc

$val = vfc( ”c1”, ”t1”, 1.2345);

vfcp

$val = vfcp( ”c1”, ”t1”, $counts, $time max);

vfc bw4

wait for timer, alias wft

$ret = wft( ”t1”);

was injection, alias wi

$ret = wi( ”c1”, ”t1”, ”st”, ”min-rate”, ”heatup”);

write counter, alias wc

$ret = wc( ”c1”, ”1000”);

Here is an example for accessing counter/timer functions:

Page 49: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

#!/bin/perl

use Spectra;

#

# reset-all-counter

#

$ret = Spectra::resaco();

#

# start-and-wait-for-timer

#

$ret = Spectra::sawft( "t1", "1.2345");

#

# read-counter

#

$val = Spectra::rc("c1");

print " Counter reading: $val\n";

6.7 Diffractometer

6.7.1 diff h, diff k, diff k, diff psi

Returns or changes a component of the hkl vector or the psi angle, e.g.: $ret = Spectra::diff h(1);

$ret = Spectra::diff h();

6.7.2 diff psirefx, diff psirefy, diff psirefz (Tango)

Returns or changes a component of the psi reference vector, e.g.:

$ret = Spectra::diff psirefx(1);

$ret = Spectra::diff psirefx();

6.7.3 diff mode, diff asn

The function diff mode selects one of the following modes:

0 bissector_vertical

1 constant_omega_vertical

2 constant_chi_vertical

3 constant_phi_vertical

4 lifting_detector_phi

5 lifting_detector_omega

6 lifting_detector_mu

7 double_diffraction_vertical

8 bissector_horizontal

9 double_diffraction_horizontal

10 psi_constant_vertical

It is called like:

$ret = Spectra::diff mode(10);

$ret = Spectra::diff mode();

The function diff asn selects/return the number of the selected set of angles (SOLEIL: Anglesidx):

$ret = Spectra::diff asn(1);

$ret = Spectra::diff asn();

Page 50: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.7.4 diff mu, diff omega, diff chi, diff phi, diff gamma, diff delta, diff two theta

Returns or changes a diffractometer angle, e.g.:

$ret = Spectra::diff mu(12.345);

$ret = Spectra::diff mu();

6.7.5 diff get r0, diff set r0, ˜r1

These functions handle the orienting reflections. A reflection that is used for the orientation consists of hkl values and

angles. The angles are read from the current motor positions, if they are not supplied.

my $ret = Spectra::diff_set_r0( $h, $k, $l);

my $ret = Spectra::diff_set_r0( $h, $k, $l, $tt, $om, $ch, $ph);

my $ret = Spectra::diff_set_r0( $h, $k, $l, $mu, $om, $ch, $ph, $ga, $de);

my $ret = Spectra::diff_set_r1( $h, $k, $l);

my $ret = Spectra::diff_set_r1( $h, $k, $l, $tt, $om, $ch, $ph);

my $ret = Spectra::diff_set_r1( $h, $k, $l, $mu, $om, $ch, $ph, $ga, $de);

This is how a reflection can be read:

my $ret = Spectra::diff_get_r0();

my ($h0, $k0, $l0, $tt0, $om0, $chi0, $phi0, $ga0, $de0) = split " ", $ret;

6.7.6 diff compute u (Tango)

After orienting reflections have been set, the U vector has to be re-calculated:

my $ret = Spectra::diff\_compute\_u();

6.7.7 diff angles()

angles()

$ret = diff angles( chi =¿ 90, phi =¿ 0, omega =¿ 0, two theta =¿ 0);

$ret = diff angles( mu =¿ 0, omega =¿ 12, chi =¿ 45, phi =¿ 90, gamma =¿ 0, delta =¿ 24);

$ret = diff angles();

If diff angles() is called without an argument, it returns ”2-theta omega chi phi” or ”mu omega chi phi gamma delta”

depending on the diffractometer type.

6.7.8 diff ang2h, diff ang2k, diff ang2l, diff ang2psi

diff ang2h( $tt, $om, $ch, $ph)

diff ang2h( $mu, $om, $ch, $ph, $ga, $de)

diff ang2k( $tt, $om, $ch, $ph)

diff ang2k( $mu, $om, $ch, $ph, $ga, $de)

diff ang2l( $tt, $om, $ch, $ph)

diff ang2l( $mu, $om, $ch, $ph, $ga, $de)

diff ang2psi( $tt, $om, $ch, $ph)

diff ang2psi( $mu, $om, $ch, $ph, $ga, $de)

Returns a calculated component of the q-vector, including psi, that correspond to the specified set of angles.

$h = diff ang2h( -1, 46, -97, 126);

6.7.9 diff hkl2two theta, diff hkl2omega, diff hkl2chi, diff hkl2phi, diff hkl2mu, diff hkl2gamma,diff hkl2delta

diff hkl2two theta( $h, $k, $l[, $par])

diff hkl2omega( $h, $k, $l[, $par])

diff hkl2chi( $h, $k, $l[, $par])

Page 51: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

diff hkl2phi( $h, $k, $l[, $par])

diff hkl2mu( $h, $k, $l[, $par])

diff hkl2gamma( $h, $k, $l[, $par])

diff hkl2delta( $h, $k, $l[, $par])

Returns the angle that corresponds to hkl. The meaning of the optional parameter $par depends on the mode: For the

fixed-psi mode it is the psi value, for the fixed-phi mode it is phi and for the fixed-om2 mode it is om2.

$tt = diff hkl2two theta( 1, 1, 1);

6.7.10 diff calc angles()

diff calc angles( $h, $k, $l)

diff calc angles( $h, $k, $l, $par)

diff calc angles( $h, $k, $l, $par, $index)

diff calc angles( $h, $k, $l, undef, $index)

Returns a string that contains the angles belonging to the specified hkl, e.g.:

my $ret = diff_calc_angles(1,1,0);

( mu = 0, omega = -11.60882, chi = 119.365, phi = -55.9933,

gamma = 1.272316e-13, delta = 52.26939).

$par is an optional parameter, e.g.: psi. $index selects a single angle, e.g.: mu is selected by supplying 1.

6.7.11 diff hkl()

$ret = diff hkl( h =¿ 1, k =¿ 0, l =¿ 0, psi =¿ 90);

$ret = diff hkl( h =¿ 1, k =¿ 0, l =¿ 0);

$ret = diff hkl( h =¿ 1, k =¿ 0, l =¿ 0, psi from ub =¿ 1);

This function can be used to set one or more components of the hkl-vector. If neither psi nor psi from ub is

supplied, the current psi value is kept.

If diff hkl() is called without arguments, it returns the current hkl-vector. It depends on the context whether it

returns a list or a string:

List context: my ( $h, $k, $l, $psi) = diff hkl();

Scalar context: $buffer = diff hkl();

$buffer contains: (h, k, l, psi).

6.7.12 diff gk1, diff gk2, diff gk3, diff gw1, diff gw2, diff gw3

Returns or changes a component of the lattice: :

$ret = Spectra::diff gk1(); # a

$ret = Spectra::diff gk1(5.5);

$ret = Spectra::diff gk2(); # b

$ret = Spectra::diff gk2(5.5);

$ret = Spectra::diff gk3(); # c

$ret = Spectra::diff gk3(5.5);

$ret = Spectra::diff gw1(); # alpha

$ret = Spectra::diff gw1(90 );

$ret = Spectra::diff gw2(); # beta

$ret = Spectra::diff gw2(90 );

$ret = Spectra::diff gw3(); # gamma

$ret = Spectra::diff gw3(90 );

Page 52: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.7.13 attribute( name =¿ ”ub matrix”, ...) (non-Tango)

attribute( name =¿ ”ub matrix”, get =¿ ...);

Returns an attribute of the UB matrix.

$ret = attribute( name =¿ ”ub matrix”, get =¿ ”r0”);

Returns hkl and the angles (tocp) of the first stored reflection.

$ret = attribute( name =¿ ”ub matrix”, get =¿ ”scan mode”);

$ret = attr( name =¿ ”ub matrix”, scan mode =¿ $val);

Returns/sets the scan mode. The meaning of $val is:

0 - Bisecting

1 - Fixed psi

2 - Constant plane

3 - Fixed phi

4 - Fixed om2 (omega-two theta*0.5)

$ret = attribute( name =¿ ”ub matrix”, get =¿ ”parameter”);

$ret = attr( name =¿ ”ub matrix”, parameter =¿ $val);

Returns/sets the scan mode parameter. The meaning depends on the scan mode, e.g.: for the fixed-psi mode it is the

psi value.

6.7.14 Absorber

Adjust filter

An absorber (DIFF ABSORBER) is adjusted. SIGNAL is kept between FILTER MIN and FILTER MAX. The ab-

sorber is moved in steps of FILTER DELTA.

Filter

$ret = filter();

$ret = filter(3);

Sets/gets the filter position (DIFF ABSORBER).

6.8 Encoder

The encoder() function operates the IK220 encoder (Heidenhain).

Encoder

$ret = encoder( ”hhe1”, ”position”);

$ret = encoder( ”hhe1”, ”cancelref”);

$ret = encoder( ”hhe1”, ”doref”);

$ret = encoder( ”hhe1”, ”init”);

$ret = encoder( ”hhe1”, ”staport”);

$ret = encoder( ”hhe1”, ”offset”);

$ret = encoder( ”hhe1”, ”conversion”);

$ret = encoder( ”hhe1”, ”offset”, ”value”);

$ret = encoder( ”hhe1”, ”conversion”, ”value”);

$ret = encoder( ”hhe1”, ”p1 ); # 1 incremental

$ret = encoder( ”hhe1”, ”p1”, ”value”);

$ret = encoder( ”hhe1”, ”p2”); # 0 muA, 1 V

$ret = encoder( ”hhe1”, ”p2”, ”value”);

$ret = encoder( ”hhe1”, ”p3”); # 0 linear, 1 rotational

$ret = encoder( ”hhe1”, ”p3”, ”value”);

$ret = encoder( ”hhe1”, ”p4”);

$ret = encoder( ”hhe1”, ”p4”, ”value”); # 0 positive, 1 negative

Port status values: 0x20 after ’init’, 0x4060 after ’doref’, 0xffffc024 after passing the reference point.

Page 53: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

key Explanation Example

x, y, z

u, v, w the coordinates $x= $HEXAPOD x;

$HEXAPOD x = $x;

r, s, t the pivot point $r = $HEXAPOD r;

$HEXAPOD s = $s;

sx, sy, sz,

su, sv, sw, the step sizes $sx = $HEXAPOD sx;

$HEXAPOD sx = $sx;

vel the velocity $vel = $HEXAPOD vel;

$HEXAPOD vel = 2;

rdy the status, moving (1) $rdy = $HEXAPOD rdy;

status 0 device is offline, 1 device is online $stat = $HEXAPOD status;

xyz see below

uvw see below

rst see below

pivot alias for rst

sxsysz see below

susvsw see below

Table 6.2: The %HEXAPOD Hash

6.9 Image Plate Scanner

close shutter()

open shutter()

status shutter()

Open shutter() moves motor shutter to pos open shutter, likewise close shutter() moves motor shutter to pos close shutter.

status shutter() returns 1, if the shutter is closed.

erase mar()

scan mar( $mode, $file name, $sample time)

These functions rely on NODE MAR:/home/mar345/mar erase and NODE MAR:/home/mar345/mar scan. NODE MAR

can be hasipbw5. The client has been started on NODE MAR before:

hasipbw5> scan345 [-host 192.0.2.1] [-port 4441]

The client displays log messages during the scans. The following messages can be ignored:

scan345: Diameter increased for next scan mode!

scan345: Plate will be erased first ...

file name: the directory is specified in NODE MAR:/home/mar345/bin/mar scan.

sample time: is stored in the images header, no other reason. node: The possible modes are:

0 - 2300 pixels, 345mm diameter, 0.15 mm pixelsize

1 - 2000 pixels, 300mm diameter, 0.15 mm pixelsize

2 - 1600 pixels, 240mm diameter, 0.15 mm pixelsize

3 - 1200 pixels, 180mm diameter, 0.15 mm pixelsize

4 - 3450 pixels, 345mm diameter, 0.10 mm pixelsize

5 - 3000 pixels, 300mm diameter, 0.10 mm pixelsize

6 - 2400 pixels, 240mm diameter, 0.10 mm pixelsize

7 - 1800 pixels, 180mm diameter, 0.10 mm pixelsize

6.10 Hexapod (Beamline L)

The hash %HEXAPOD provides an interface to the hexapod.

Note that there is an example of using the $HEXAPOD status in the Online manual.

The following example demonstrates how the hexapod is controlled from a Perl script.

Page 54: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

#!/usr/bin/perl

#

use Spectra;

#

# get the parameters

#

($x, $y, $z) = split ’ ’, $HEXAPOD{ xyz};

($u, $v, $w) = split ’ ’, $HEXAPOD{ uvw};

($r, $s, $t) = split ’ ’, $HEXAPOD{ rst};

($r, $s, $t) = split ’ ’, $HEXAPOD{ pivot};

$vel = $HEXAPOD{ vel};

$rdy = $HEXAPOD{ rdy}; # moving ?

#

# set the parameters

#

$HEXAPOD{ xyz} = "$x $y $z ";

$HEXAPOD{ uvw} = "$u $v $w ";

$HEXAPOD{ rst} = "$r $s $t "; # the pivot point

$HEXAPOD{ pivot} = "$r $s $t ";

$HEXAPOD{ sxsysz} = "$sx $sy $sz "; # the step sizes

$HEXAPOD{ susvsw} = "$sx $sy $sz ";

$HEXAPOD{ vel} = 2;

It is alos possible to access the Hexapod via a function:

#

# hexapod movements

#

$ret = hexapod( "x", $xpos);

$ret = hexapod( "y", $ypos);

...

#

# reading the hexapod position

#

$ret = hexapod( "x");

$ret = hexapod( "y");

...

6.11 LCX

These are the functions that operate the LCX camera:

lcxStart( $devName, $fname, $sampleTime, $num)

This function executes the following sequence:

• the attribute FileStartNum is set: $num

• the attribute DelayTime is set: 0

• the attribute NbFrames is set: 1

• the attribute ExposureTime is set: $sampleTime

• the attribute FilePrefix: $fname

• the command StartAcquisition is executed.

Virtual counters use the tng state($devName) function to sense when the state turns to IDLE.

Page 55: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.12 MARCCD

marccd open

Opens a TCP/IP socket connection to the MAR host. Needs the Spectra symbol MARCCD HOST. Assumes the

server runs on port 2002. If this call is omitted, the other functions do it automatically.

marccd close()

Closes the socket.

marccd abort()

Sends the abort command.

marccd get state()

Returns the status info. It consists of two numbers, the first describes the previous state, the second the current state.

See the following table for the meaning.

IDLE 0

ACQUIRE 1

READOUT 2

CORRECT 3

WRITING 4

ABORTING 5

UNAVAILABLE 6

ERROR 7

BUSY 8

marccd start()

Sends the start command and waits for the state “81”.

marccd readout()

Reads the CCD, which takes about 3 seconds, and waits for the state “20”.

marccd readout bg()

Reads the background image, which takes about 3 seconds, and waits for the state “20”.

marccd readout mr()

Reads the mr image and waits for the state “20”.

marccd correct()

Subtracts the backgound from the image and waits for the state “30”.

marccd send header( $string)

Sends a string to the header.

marccd writefile( $fileName)

Sends th writefile command and waits for the state “40”.

This is a typical sequence:

marccd_abort() or die "Failed to ’abort’";

marccd_start() or die "Failed to ’start’";

sleep 1;

marccd_readout_bg() or die "Failed to ’readout_bg’";

marccd_start() or die "Failed to ’start’";

sleep 1;

marccd_readout() or die "Failed to ’readout’";

marccd_correct() or die "Failed to ’correct’";

marccd_writefile( $fileName) or die "Failed to ’writefile’";

This is the implemantion as a virtual counter (VC):

if( $method =˜ /reset/i)

{

Spectra::marccd_abort();

return Spectra::marccd_start();

}

if( $method =˜ /read/i)

{

Spectra::marccd_readout();

Spectra::marccd_correct();

my $fname = $Spectra::SYM{ scan_name} . "_" . $Spectra::SYM{ sindex};

return Spectra::marccd_writefile( $fname);

}

Page 56: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

To be sure that the first image does not contain the previously collected noise, we provide the following extra-code for

the ’before’ script:

#

# clear the second shutter

#

Spectra::gra_command( "wor(oreg1) = 0");

#

# clear MARCCD

#

Spectra::marccd_readout();

6.13 Monochromator

energy()

$ret = energy();

$ret = energy( 8980);

$ret = move( energy =¿ 8980);

Sets/gets the energy of the monochromator [eV].

wavelength)

$ret = wavelength);

$ret = wavelength( 1.5);

Sets/gets the wavelength of the monochromator [Angstr.], alias: Lambda().

calibrate();

Calibrates the energy [eV].

calibrate( name => "Energy",

unit => SomeValue,

nolog => 1, # optional, def.: 0

noconfirm => 1); # optional, def.: 0

pos energy();

Returns the motor names and their positions at the specified energy.

$ret = pos_energy( "9000");

--> ( mot33 = 12.5483, mot39 = 12.5483, mot40 = 15, mot38 = 53.3777, mot34 = -10)

6.13.1 Hook: Before/after energy moves

The symbols bem command and aem command are executed before and after enery changes. They have been

implemented e.g. to disable/enable the MOSTAB during the movements. bem command may use the symbol

energy setpoint bem.

Here is an example for a command file that is executed before each enery move. The file /online dir/exp ini.exp should

contain the line:

bem_command = "run <˜.prog>bem_command.pl"

The file <˜.prog>bem_command.pl contains:

#/usr/bin/perl -w

use Spectra;

my $ret = Spectra::gra_decode_float( "energy_setpoint_bem");

Util::log( "bem_command: the energy is moved to $ret");

sleep(1);

return 1;

Here is an example for a command file that is executed after each enery move. The file /online dir/exp ini.exp should

contain the line:

aem_command = "run <˜.prog>aem_command.pl"

Page 57: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

The file <˜.prog>aem_command.pl contains:

#/usr/bin/perl -w

use Spectra;

my $ret = Spectra::energy();

Util::log( "aem_command: the energy is now $ret");

sleep(1);

return 1;

6.13.2 mostab()

The mostab() function communicates with the SIS2900 monochromator stabilizer. The most commonly used com-

mands set the device to idle, specify a setpoint and initiate a peak search:

$ret = Spectra::mostab( "I"); # switches to idle

$ret = Spectra::mostab( "S1=-0.7"); # setpoint to 70%, left edge

$ret = Spectra::mostab( "P" [, ns]); # peak search

# This call returns after the peak-search is done. It returns the

# number of seconds that were needed to find the peak, a typical

# value: 7. The user may specify the maximum search time, def.: 15 s.

When the MOSTAB is in the peak search mode, it sweeps the output voltage over the allowed range. The sweeping

time independent of the range. That means, if the range is reduced, the sensitivity of the peak search procedure is

increased. This is how the range is specified:

$ret = Spectra::mostab( "S6=-800"); # set minValue

$ret = Spectra::mostab( "S7=-200"); # set maxValue

For debugging purposes it may be interesting to read the status and possibly the parameters:

$ret = Spectra::mostab( "RS"); # read status

# Status messages:

# #2;IDLE# idle

# #4;NEWPEAK# peak search, 1. phase

# #10;GUESS# peak search, 2. phase

# #11;TRACKSP# track setpoint

$ret = Spectra::mostab( "RA"); # display all parameters

$ret = Spectra::mostab( "RF"); # read all parameters

$ret = Spectra::mostab( "RG"); # read all parameters

During the alignment of the monochromator it can be helpful to set the MOSTAB to a constant output voltage while

the crystal positions are optimized. This is the procedure:

$ret = Spectra::mostab( "M"); # to manual mode

$ret = Spectra::mostab( "SC=32000"); # sets the output voltage,

# valid range: 0 .. 65535, -1000 .. 0V

# at this stage the MC crystals can be aligned, then

$ret = Spectra::mostab( "A"); # to automatic mode

The MOSTAB can be tested with a telnet session:

> telnet hast11 3521

Trying 131.169.38.146...

Connected to hast11.

Escape character is ’ˆ]’.

RS

#10;GUESS#

Page 58: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Finally there are some utility commands:

$ret = Spectra::mostab( "C"); # switches local display mode off

$ret = Spectra::mostab( "N"); # switches echo mode off

6.14 Motor

Here are the functions that access the motor parameters or move motors.

calibrate()

Calibrates stepping motors. The function implicitly uses protect. Example:

$ret = calibrate( name => "mot1",

unit => 1.234,

nolog => 1, # optional, def.: 0

noconfirm => 1, # optional, def.: 0

keeping_limits => 0); # optional, def.: 1

cancel all moves(), alias cam()

$ret=cam();

check motor registers(), alias cmr()

See section 6.14.1.

check motors moving, alias cmm()

$ret=cmm();

check move(), alias cm()

$ret=cm( ”mot11”);

convert to relative steps, alias ctrs

$steps=ctrs( ”mot11”, 5.);

get motor ramp steps, alias gmrs

$steps=gmrs( ”mot11”);

get motor protection

Returns 1, if the motor is protected.

$steps=get motor protection( ”mot11”);

get motor ramp units, alias gmru

$steps=gmru( ”mot11”);

get motor step register controller, alias gmsrc

$steps=gmsrc( ”mot11”);

get motor step register internal, alias gmsri

$steps=gmsri( ”mot11”);

get move time, alias gmt

$steps = gmsrc( ”mot11”, $pos delta);

get motor unit position, alias gmup $pos = gmup( ”mot12”);

move()

move( mot1 =¿ 0, mot2 =¿ 100);

move( mot1 =¿ 100, relative =¿ 1);

move( mot1 =¿ 0.1, relative =¿ 1, backlash =¿ 0);

move( mot1 =¿ 1, steps =¿ 1);

move( energy =¿ 8980);

amove() see section 4.4

Page 59: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Oms58()

$ret = oms58( ”mot1”, ”ac1000”); acceleration [1,1000000000]

$ret = oms58( ”mot1”, ”id”); set done

$ret = oms58( ”mot1”, ”ic”); clear done and error

$ret = oms58( ”mot1”, ”fl”); flush queue

$ret = oms58( ”mot1”, ”gd”); clear done and go

$ret = oms58( ”mot1”, ”go”); initiate prev. prog. move

$ret = oms58( ”mot1”, ”kl”); kill, stop all, flush queues

$ret = oms58( ”mot1”, ”lp5000”); load position

$ret = oms58( ”mot1”, ”ma5000 go”); move absolute

$ret = oms58( ”mot1”, ”mr5000 go”); move relative

$ret = oms58( ”mot1”, ”rs”); power-on reset

$ret = oms58( ”mot1”, ”sa”); stop all, flush queue

$ret = oms58( ”mot1”, ”vb20”); base rate [1,vl[

$ret = oms58( ”mot1”, ”vl10000”); slew rate [1,1000000]

$ret = oms58( ”mot1”, ”mp wt1 ax ma1000 go”);

Sets the direction bit positive and waits 1 millisecond before the move is started (mp, mm)

$ret = oms58( ”mot1”, ”qa”); query axis

$ret = oms58( ”mot1”); read the result

$ret = oms58 qa( ”mot1”); query axis, debugging tool

$ret = oms58( ”mot1”, ”ra”); query axis and reset done

$ret = oms58( ”mot1”); read the result

$ret = oms58( ”mot1”, ”rp”); request position

$ret = oms58( ”mot1”); read the result

$ret = oms58( ”mot1”, ”rq”); request queue

$ret = oms58( ”mot1”); read the result

$ret = oms58( ”mot1”, ”wy”); who are you

$ret = oms58( ”mot1”); read the result

Query axis response: 1. char: P/M - moving in positive/negative direction, 2. char: D - done (ID, II or IN command

has been executed, set to N by this command or IC command), N - no ID executed yet, 3. char: L - axis in overtravel,

char 1 tells the direction, set to N when limit switch is not active. N - not in overtravel, 4. char: H - home switch active,

N - home switch not active.

reset motor step position, alias rmsp

$ret = rmsp( ”mot11”, 0);

reset motor step register, alias rmsr

set motor step register controller, alias smsrc

set motor step register internal, alias smsri

These functions are equivalent. $ret = rmsr( ”mot11”, 0);

search motor()

$ret = search motor( ”mot11”);

set min move time, get ˜, alias smmt(), gmmt()

set motor acceleration, get ˜, alias sma, gma

$ret = sma( ”mot11”, 300000);

$ret = gma( ”mot11”);

set motor base, get ˜, alias smb, gmb

$ret = smb( ”mot11”, 20);

$ret = gmb( ”mot11”);

set motor conversion, get ˜, alias smc, gmc

$ret = smc( ”mot1”, 20000);

$ret = gmc( ”mot1”);

set motor settle time, get ˜, alias smst, gmst

Page 60: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

set motor slew, get ˜, alias sms, gms

$ret = sms( ”mot1”, 200000);

set motor slew min, get ˜, alias smsi, gmsi

$ret = smsi( ”mot1”, 200000);

set motor slew max, get ˜, alias smsa, gmsa

$ret = smsa( ”mot1”, 200000);

get motor limits status

$ret = get motor limits status( ”mot1”);

0 - no limit switches hit, 1 - cw, 2 - ccw, 3 - both. CW is at the maximum step position (at the max. unit position, if

conv. greater than 0).

set motor step backlash, get ˜, alias smsb, gmsb

get motor accu limit min, ˜ max, alias gmali, gmala

set motor step limit max, get ˜, alias smsla, gmsla

set motor step limit min, get ˜, alias smsli, gmsli

set motor unit backlash, get ˜, alias smub, gmub

$ret = smub( ”mot11”, 0.1);

$ret = gmob( ”mot11”);

set motor unit limit max, get ˜, alias smula, gmula

$ret = smula( ”mot1”, 200);

set motor unit limit min, get ˜, alias smuli, gmuli

$ret = smuli( ”mot1”, 100);

setup absolute step move, alias sasm

setup absolute unit move, alias saum

setup relative step move, alias srsm

setup relative unit move, alias srum

slit()

$ret = slit( ”s1”, ”cx”);

$ret = slit( ”s1”, ”cx”, $new pos);

$ret = slit( ”s1”, ”cy”);

$ret = slit( ”s1”, ”dx”);

$ret = slit( ”s1”, ”dy”);

$ret = slit( ”s1”, ”left”);

$ret = slit( ”s1”, ”right”);

$ret = slit( ”s1”, ”top”);

$ret = slit( ”s1”, ”bottom”);

The slit system s1 can be treated by the slit function, if the following symbols are defined s1 left, s1 right, s1 top,

s1 bottom.

slit calibrate()

slit calibrate( ”s1”, ”cx”, $new value);

start all moves(), alias strtam

stop all moves(), alias stpam

start move(), stop move(), complete move()

VME only, these functions havn’t been tested yet. See section 10.7 for an example program.

Page 61: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.14.1 check motor registers()

This function searches for disagreements between the hardware (motor controllers) and the software (device list). If

cmr() detects differences, it prompts the user for how to proceed, unless it is called from exp ini.exp. In this case

it follows this recipe:

• cmr() returns 1, if the device list and the controllers contain the same values.

• cmr() trusts the device list, if all disagreements belong to controllers containing zeros.

• cmr() trusts the controllers, if the user issued ’cmr(1)’

• If the preceding Online session ended normally (no online.lock):

– If the device list is within the limits, it is used

– Else-if the controllers are within the limits, they are used

– Else image exit due to this fatal condition

• If the preceding Online session ended by a crash:

– If the controllers are within the limits, they are used.

– Else-if the device list is with the limits, it is loaded and vme recover.gra is executed.

– Else image exit due to this fatal condition

cmr() writes a record to online.log which describes what has been done.

Usage: $ret = cmr();.

6.14.2 Encoder (OMS-MAXV)

The following functions can be used with the OMS-MAXV stepper controller, if an encoder (e.g. RENISHAW RGH24)

is connected.

get motor unit position encoder, alias gmupe

this function uses the current encoder reading, the encoder conversion factor and the encoder home position to calculate

the motor position. $ret=gmupe( ”mot11”);

get motor ncoder raw, alias gmeraw

returns the raw encoder reading $ret=gmeraw( ”mot11”);

set motor conversion encoder, get ˜, alias smce, gmce

the conversion factor $ret=smce( ”mot11”, 20000);

$conv=gmce( ”mot11”);

set motor home position, get ˜, alias smhp, gmhp

$ret=smhp( ”mot11”, 50.186);

$conv=gmhp( ”mot11”);

Spectra::move home()

executes the motor homing procedure. Details about the homing procedure can be found in the Online manual:

functions-motors-encoder.

, $ret=Spectra::move home(”mot11”);

6.14.3 CutOrMap (OMS)

The Online manual contains the explanations concerning the CurOrMap feature. Here only the functions are listed:

$ret = Spectra::get_motor_flag_cutormap( "motorName");

$ret = Spectra::set_motor_flag_cutormap( "motorName", 0); # cutOrMap is ignored

$ret = Spectra::set_motor_flag_cutormap( "motorName", 1); # cutOrMap is a cutting point

$ret = Spectra::set_motor_flag_cutormap( "motorName", 2); # cutOrMap is a mapping point

$ret = Spectra::get_motor_cutormap( "motorName");

$ret = Spectra::set_motor_cutormap( "motorName", $value);

Page 62: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.15 NeXus

These are the functions that control the NeXus I/O:

nexus_add_devices( "exp_c01", "exp_c02")

Adds devices to a list which is used for the NeXus output. These

devices corresponf to data sources of the components

nexus_clear_devices()

nexus_show_devices()

nexus_add_components( "saxs_test")

Adds components to a list which is used for the NeXus output

nexus_clear_components()

nexus_show_components()

The internal list of selected components

nexus_show_available_components()

Read from the configuration server

set write_nexus on

Controls whether NeXus files are created during a scan.

Online needs the nexusWriter and the nexusConfigurationServer, e.g.:

<device>

<name>nexusWriter</name>

<tags>expert</tags>

<type>type_tango</type>

<module>module_tango</module>

<device>p19/nxsdatawriter/hastodt</device>

<control>tango</control>

<hostname>hastodt:10000</hostname>

</device>

<device>

<name>nexusConfigurationServer</name>

<tags>expert</tags>

<type>type_tango</type>

<module>module_tango</module>

<device>p19/nxsconfigserver/hastodt</device>

<control>tango</control>

<hostname>hastodt:10000</hostname>

</device>

6.16 Perkin Elmer

These are the functions that operate the Perkin Elmer detector:

perkinElmer startSubtracted( $devName, $fname, $sampleTime, $num)

perkinElmer startDark( $devName, $fname, $sampleTime, $num)

The functions execute the following sequence:

• the attribute exposureTime is read

• the attribute FilesAfterTrigger is read

• the attribute SummedSaveImages is set: ceil( sampleTime/exposureTime/filesAfterTrigger)

• the attribute FilePattern is set: $fname

• the attribute FileIndex s set: $num;

• the command AcquireSubtractedImagesAndSave or AcquireDarkImagesAndSave is executed.

Page 63: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Virtual counters use the tng state($devName) function to sense when the state turns to IDLE.

perkinElmer singleShotSubtracted( $devName, $fname, $sampleTime, $num)

perkinElmer singleShotDark( $devName, $fname, $sampleTime, $num)

The functions execute the following sequence:

• the corresponding start-function is executed

• the function waits for the state to become IDLE

6.17 Photonic Science

These are the functions that operate the Photonic Science camera:

photonicScienceStart( $devName, $fname, $sampleTime, $num)

This function executes the following sequence:

• the attribute FileRefNumber is set: $num

• the attribute NumberOfImages is set: 1

• the attribute ExposureTime is set: $sampleTime * 1000

• the attribute FilePrefix: $fname

• the command StartAcquisition is executed.

Virtual counters use the tng state($devName) function to sense when the state turns to IDLE.

6.18 Pilatus-300k

The Pilatus100k detector is operated via a Tango server. The Tango server has to be started before the following

functions can be invoked.

pilatus state( $devName);

Returns the state of the Pilatus detector, 0 - IDLE, 10 - RUNNING.

pilatus start( $devName, $fname, $exposureTime, [$num [,$postFix]])

The function starts the following sequence:

• The Tango state is read from the server. This call is necessary because of the server architecture.

• The Tango attribute ExposureTime is set.

• The Tango attribute FileStartNum is set to $num or extracted from $fname. This number is appended to the file

prefix. A ’ ’ is inserted between the two parts of the file name. For normal applications pilatus start() is called

for each image. In this case FileStartNum is used as it is supplied. There may be applications with lots of images

per start command. In this case the server increments the number automatically.

• The Tango attribute FilePostFix is set to $postFix or ’.tif’.

• The Tango command StartStandardAcq is invoked.

pilatus stop();

Stops the Pilatus detector.

pilatus wait for idle( $devName, [$tmo]);

Waits for the Pilatus to become IDLE. If $tmo is not supplied, $tmo is set to 3 seconds.

pilatus singleShot( $devName, $fname, $exposureTime, [$num [,$postFix]])

The function calls pilatus start and pilatus wait for idle.

These functions use the internal name Pilatus to access the server. The connection between the internal name and the

server is given by these definitions from /online dir/online.xml. The file is loaded from /online dir/TkIrc.pl:

Spectra::load configuration().

<?xml version="1.0"?>

<hw>

#

#

#

Page 64: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

<device>

<name>pilatus</name>

<type>detector</type>

<module>pilatus100k</module>

<device>b1/exp/pilatus1</device>

<control>tango</control>

<hostname>hasb1:10000</hostname>

</device>

</hw>

6.18.1 The startup procedure, P09

The following steps are described for P09. For other beamlines the names have to changed accordingly.

First the Pilatus control program has to be started. At P09 this program runs on haspp09pilatus, user det. It can

be started from haspp09, user p09user, by the command startpilatus which executes ’ssh -n det@haspp09pilatus

/home/det/startpilatus.sh’.

At P09 the output files should be written to a subdirectory of /data which points to a file server in the DESY computer

center. It is auto-mounted at haspp09 and haspp09pilatus. The target subdirectory should be created by det@haspp09pilatus

in order to avoid permission problems. Note that the images are stored by det@haspp09pilatus.

6.19 Prosilica

These are the functions that operate the Prosilica camera:

prosilicaStart( $devName, $fname, $sampleTime, $num)

This function executes the following sequence:

• the attribute FileStartNumber is set: $num

• the attribute Exposure is set: $sampleTime * 1000000

• the attribute FilePrefix: $fname

• the command StartAcquisition is executed.

Virtual counters use the tng state($devName) function to sense when the state turns to IDLE.

6.20 The pulse generator

get pg external base, alias gpgeb

set pg external base, alias spgeb

start pg, alias spg

6.21 Register

read input register, alias rir

$ret = rir( ”ireg1”);

read output register, alias ror

Reads the last value that has been written to an output register.

$ret = rir( ”ireg1”);

write output register, alias wor

$ret = wor(”oreg8”, 1);

clear output register bit, alias corb

input register data accepted, alias irda

wait for input register, alias wfir

Page 65: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

clear output register bit, alias corb

read and clear mca, alias racm

read input register bcd, alias rirbcd

read input register d, alias rird

reset input register, alias resir

reset output register, alias resor

test input register, alias tir

test output register, alias tor

6.22 Tango

Online can communicate with Tango servers. This may occur implicitly, e.g. the call Spectra::start mca( ”mca1”, 0)

may involve Tango I/O, if MCA1 is a Tango device. In addition there are functions that explicitly access Tango servers.

6.22.1 Attributes

Tango servers can have different types of attributes. So far double, float, long, unsigned short are supported. Functions

that read attributes end with Rd, functions that write attributes and with Wrt. The first argument of the functions is

always a device name that identifies the server. Device names are defined in /online dir/online.xml. The attribute names

are not case-sensitive.

Spectra::tng hasAttr()

$ret = Spectra::tng hasAttr( ”exp mot01”, ”cwlimit”)

Spectra::tng getDevName()

$ret = Spectra::tng getDevName( ”exp mot01”)

Spectra::tng attrBoolRd()

$ret = Spectra::tng attrBoolRd( ”dffrctmtr”, ”Simulated”)

Spectra::tng attrBoolWrt()

$ret = Spectra::tng attrBoolWrt( ”dffrctmtr”, ”Simulated”, 1)

Spectra::tng attrDoubleRd()

$ret = Spectra::tng attrDoubleRd( ”dev1”, ”whatEver”)

Spectra::tng attrDoubleWrt()

$ret = Spectra::tng attrDoubleWrt( ”dev1”, ”attr”, 0.5)

Spectra::tng attrDoubleImageRd()

$ret = Spectra::tng attrDoubleImageRd( ”dffrctmtr”, ”UB”)

returns an array, max. 20 elements.

Spectra::tng attrDoubleArrRd()

$len = Spectra::tng attrDoubleArrRd( ”TangoTest”, ”double spectrum”, ”size”)

returns the size of the array.

$ret = Spectra::tng attrDoubleArrRd( ”TangoTest”, ”double spectrum”, $idx)

returns the element number $idx. $idx can be in the range [0, $len - 1].

Spectra::tng attrDoubleArrWrt()

$len = Spectra::tng attrDoubleArrWrt( ”TangoTest”, ”double spectrum”, $idx, $value)

sets an element of an array.

$ret = Spectra::tng attrDoubleArrWrt( ”TangoTest”, ”double spectrum”, $idx, $value)

sets the element number $idx. $idx can be in the range [0, $len - 1].

Spectra::tng attrFloatRd()

$ret = Spectra::tng attrFloatRd( ”mca10”, ”totaltime”)

Spectra::tng attrFloatWrt()

$ret = Spectra::tng attrFloatWrt( ”t1”, ”sampletime”, 0.5)

Spectra::tng attrFloatArrRd()

$len = Spectra::tng attrFloatArrRd( ”TangoTest”, ”float spectrum”, ”size”)

Page 66: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

returns the size of the array.

$ret = Spectra::tng attrFloatArrRd( ”TangoTest”, ”float spectrum”, $idx)

returns the element number $idx. $idx can be in the range [0, $len - 1].

Spectra::tng attrFloatArrWrt()

$len = Spectra::tng attrFloatArrWrt( ”TangoTest”, ”float spectrum”, $idx, $value)

sets an element of an array.

$ret = Spectra::tng attrFloatArrWrt( ”TangoTest”, ”float spectrum”, $idx, $value)

sets the element number $idx. $idx can be in the range [0, $len - 1].

Spectra::tng attrLongRd()

$ret = Spectra::tng attrLongRd( ”dev2”, ”mask1”)

Spectra::tng attrULongWrt()

$ret = Spectra::tng attrULongWrt( ”dev2”, ”mask1”, 0x766)

Spectra::tng attrULongRd()

$ret = Spectra::tng attrULongRd( ”dev2”, ”mask1”)

Spectra::tng attrLongWrt()

$ret = Spectra::tng attrLongWrt( ”dev2”, ”mask1”, 0x766)

Spectra::tng attrLongArrRd()

$len = Spectra::tng attrLongArrRd( ”TangoTest”, ”long spectrum”, ”size”)

returns the size of the array.

$ret = Spectra::tng attrLongArrRd( ”TangoTest”, ”long spectrum”, $idx)

returns the element number $idx. $idx can be in the range [0, $len - 1].

Spectra::tng attrLongArrWrt()

$len = Spectra::tng attrLongArrWrt( ”TangoTest”, ”long spectrum”, $idx, $value)

sets an element of an array.

$ret = Spectra::tng attrLongArrWrt( ”TangoTest”, ”long spectrum”, $idx, $value)

sets the element number $idx. $idx can be in the range [0, $len - 1].

Spectra::tng attrStringRd()

$ret = Spectra::tng attrStringRd( ”tg test”, ”string scalar”)

Spectra::tng attrStringWrt()

$ret = Spectra::tng attrStringRd( ”tg test”, ”string scalar”, ”hello”)

Spectra::tng attrStringArrRd()

$ret = Spectra::tng attrStringRd( ”dffrctntr”, ”ModeNames”, ”size”)

returns the size of the string array.

$ret = Spectra::tng attrStringRd( ”dffrctntr”, ”ModeNames”, $idx)

returns the string numbered by $idx, [0, 99]

Spectra::tng attrUShortRd()

$ret = Spectra::tng attrUShortRd( ”mca10”, ”dac1”)

Spectra::tng attrUShortWrt()

$ret = Spectra::tng attrUShort( ”mca10”, ”dac1”, 50)

Spectra::tng attrShortRd()

$ret = Spectra::tng attrUShortRd( ”e6c”, ”AnglesIdx”)

Spectra::tng attrUShortWrt()

6.22.2 Properties

Spectra::tng propRd()

$ret = Spectra::tng propRd( ”exp mot65”, ”flagEncoder”)

Page 67: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

6.22.3 Commands

Tango command names are not case-sensitive.

Spectra::tng hasCmd()

Returns 1, if the command exists on that device.

$ret = Spectra::tng hasCmd( ”dev1”, ”StartMove”)

Spectra::tng inout()

Executes a command that returns no data.

$ret = Spectra::tng inout( ”dev1”, ”com”)

Spectra::tng inoutVoidDouble()

Executes a command that returns a double value.

$ret = Spectra::tng inoutVoidDouble( ”dev1”, ”com”)

Spectra::tng inoutVoidLong()

Executes a command that returns a long value.

$ret = Spectra::tng inoutVoidLong( ”dev1”, ”com”)

Spectra::tng inoutVoidULong()

Executes a command that returns a unsigned long value.

$ret = Spectra::tng inoutVoidULong( ”dev1”, ”com”)

Spectra::tng inoutVoidShort()

Executes a command that returns a short.

$ret = Spectra::tng inoutVoidShort( ”dffrctmtr”, ”SomeName”)

Spectra::tng inoutVoidUShort()

Executes a command that returns an unsigned short.

$ret = Spectra::tng inoutVoidUShort( ”dffrctmtr”, ”GetReflectionSize”)

Spectra::tng inoutDoubleVoid()

Executes a command that requires a double and returns a void.

$ret = Spectra::tng inoutDoubleVoid( ”dev1”, ”com”, 1.)

Spectra::tng inoutDoubleArrVoid()

Executes a command that requires an array of doubles (can be empty) and returns a void.

$ret = Spectra::tng inoutDoubleArrVoid( ”dev1”, ”com”, 1., 2., 3.)

$ret = Spectra::tng inoutDoubleArrVoid( ”dffrctmtr”, ”AddReflection”)

Spectra::tng inoutLongArrVoid()

Executes a command that requires an array of longs and returns a void.

$ret = Spectra::tng inoutLongArrVoid( ”dffrctmtr”, ”ComputeU”, 0, 1)

Spectra::tng inoutLongVoid()

Executes a command that requires a long and returns a void.

$ret = Spectra::tng inoutLongVoid( ”marccd”, ”StopExposure”, 0)

Spectra::tng inoutDoubleULong()

Executes a command that expects a double argument and returns a unsigned long value.

$ret = Spectra::tng inoutDoubleULong( ”dev1”, ”com”, 0.123)

Spectra::tng inoutLongLong()

Executes a command that expects a long argument and returns a long value.

$ret = Spectra::tng inoutLongLong( ”mca10”, ”start”, 0)

Spectra::tng inoutULongULong()

Executes a command that expects a unsigned long argument and returns a unsigned long value.

$ret = Spectra::tng inoutULongULong( ”dev1”, ”com”, 2)

Page 68: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Spectra::tng inoutStringDouble()

Executes a command that expects a string argument and returns a double.

$ret = Spectra::tng inoutStringDouble( ”dffrctmtr”, ”AffineCrystal”, ”Cr1”)

Spectra::tng inoutStringString()

Executes a command that expects a string argument and returns a string.

$ret = Spectra::tng inoutStringString( ”exp mot65”, ”WriteRead”, ”RP?”)

Spectra::tng inoutStringVoid()

Executes a command that expects a string argument and returns a void.

$ret = Spectra::tng inoutStringVoid( ”dffrctmtr”, ”AddNewCrystal”, ”Cr1”)

Spectra::tng inoutShortVoid()

Executes a command that requires a short and returns void.

$ret = Spectra::tng inoutShortVoid( ”dffrctmtr”, ”RemoveReflection”, 0)

Spectra::tng inoutUShortVoid()

Executes a command that requires an unsigned short and returns void.

$ret = Spectra::tng inoutUShortVoid( ”dffrctmtr”, ”SomeName”, $someValue)

Spectra::tng getReflection()

Returns the selected reflection as an array.

@ret = Spectra::tng getReflection( ”dffrctmtr”)

6.22.4 State

$ret = Spectra::tng state( ”dev1”)

Returns the state: 0 ON, 6 MOVING, 10 RUNNING.

6.22.5 isAlive

$ret = Spectra::tng isAlive( ”dev1”)

Returns 1, if the device exists and if a state query does not produce an exception.

6.22.6 Status

$ret = Spectra::tng status( ”dev1”)

Returns the status string

6.22.7 is tango()

$ret = Spectra::is tango( ”dev1”)

Returns 1, if dev1 is a Tango device.

6.22.8 is device()

$ret = Spectra::is device( ”dev1”)

Returns 1, if dev1 is a device.

6.23 Undulator/wiggler

calc gap

$ret = calc gap( 100);

Returns the gap the corresponds to a given energy.

gap

$ret = gap();

$ret = gap( 120);

Page 69: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

gap max

gap min

gap max cntrl

gap min cntrl

6.24 Functions for G1

sample rot x

g1 adjust phi0

g1 detector

g1 grating coarse

g1 mirror coarse

g1 sample

detector rot x

detector x

grating

mirror

sample x

6.25 Functions for W3

The following functions operate the spectrometer at W3:

$ret = Analysator();

$ret = Analysator( 200);

Page 70: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Chapter 7

Working with GQEs

The following sections describte how Perl allows us to treat graphical queue elements (GQEs) as objects.

7.1 Base class methods

The following table lists those methods which are available for several GQEs.

activate(), deactivate()

Activates/deactivates GQEs:

$ret = $some gqe-¿activate();

delete()

Delete a GQE:

$ret = $some gqe-¿delete();

display()

Display a single GQE:

$ret = $some gqe-¿display();

get(), set()

Get/set a GQE attribute:

$ret = $some gqe-¿get( ”colour”);

$ret = $some gqe-¿set( ”colour” =¿ ”red”);

preserve(), unpreserve()

Preserve a GQE, make it survive the Spectra session:

$ret = $some gqe-¿preserve();

Here is a complete example:

#!/usr/bin/perl -w

use strict;

use Spectra;

use GQE;

Spectra::delete();

my $s = SCAN->create( name => "test");

my $ret = $s->get( "colour");

Page 71: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Item Description

column no. of columns

data type

delta column

delta row

ncolour no. of colours

row no. of rows

scale data-to-colour mapping

size [LW] read-only

start column

start row

x min view viewport

y min view viewport

Table 7.1: The ARRAY Items

7.2 ARRAY Methods

Constructors:

use GQE;

$array1 = ARRAY->create( name => "ArrId", # mandatory

cols => $nc, # mandatory

rows => $nr); # mandatory

$array1 = ARRAY->locate( name => "ArrId"); # mandatory

$array1 = ARRAY->read( name => "arrname", # mandatory

format => "fio", # default: fio

file_name => "..."); # default: name

In addition to these methods the following instance methods are available:

$a2 = $a1->copy( c_new => "ival1", # A2 is a magnified copy of A1.

r_new => "ival2"); # IVAL1 and IVAL2 are the new column/

# row number, multiple of the

# original values.

$ret = $a1->write( format => "fio", # default: fio

file_name => "...", # default: name

noconfirm => "yes"); # default: "no"

7.2.1 ARRAY Items

GQE items are accessed via the methods set() and get(). They are available after an object has been constructed.

Table ?? displays the available ARRAY items.

7.2.2 An ARRAY Example

The following example demonstrates how an array is created. It can be displayed as an 8-bit grey-scale. The command

change/ct id can be used to change the colour representation.

#!/usr/bin/perl

use Spectra;

use GQE;

cls();

delete();

Page 72: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

$nx = 220;

$ny = 200;

$a1 = ARRAY->create( name => "a1",

columns => $nx,

title => "hallo",

rows => $ny) or die " failed to create a1 ";

#

# Fill the ARRAY GQE.

#

for( $x = 0; $x < $nx; $x++)

{

for( $y = 0; $y < $ny; $y++)

{

$a1->{data}[$x + $nx*$y] = $x*10;

}

if( ! ($x % 10))

{

print "\033[2;5f $x/$nx \n";

}

}

#

# the min and max have to be calculated

#

Gra_command <<EOF;

calc a1 = a1 + 0

EOF

;

$a1->set( "ncolour" => "$nx",

"offset_colour" => "10",

"scale" => "2");

#

# array reference in scalar context, return length (total())

#

#$length = @{$a1->{data}};

display();

Page 73: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

7.3 CONST Methods

Constructors:

use Spectra;

use GQE;

$const1 = CONST->create( name => "SlotId");

$const1 = CONST->locate( name => "ConstId");

Instance methods:

$ret = $const1->delete();

$ret = $const1->get( "itemName");

$ret = $const1->set( "itemName" => "itemValue"[,...]);

# Examples:

$ret = $const1->get( "colour");

$ret = $const1->set( "colour" => "black");

7.3.1 CONST Items

GQE items are accessed via the methods set() and get(). They are available after an object has been constructed.

The following table displays the available CONST items.

border

Whether a border is drawn around the whole plot.

colour

The frame colour, see 7.4.3.

font

See table 7.3, default: TimesBold.

grid colour

See 7.4.3.

grid type

The grid line type, see table 7.4.3.

grid width

The grid line width, default: 1.

height

The font height, default: 17.

map mode

Default: 2.

plot box

The axis plotting mode, possible values are: No (0), Yes (1), UpRight (2), OpenRight (3), OpenLeft (4), BothOpen (5).

type

The frame line type, see 7.4.3.

width

The frame line width.

x maj size

The length of major tic marks [0, 1].

x off

The x-distance of the tic mark numbers [-1.1, 0.1].

Page 74: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

y tic size

The length of tic marks [0, 1].

y maj size

The length of major tic marks [0, 1].

y off

The y-distance of the tic mark numbers [-1.1, 0.1].

y tic size

The length of tic marks [0, 1].

7.3.2 A CONST Example

#!/usr/bin/perl

use Spectra;

use GQE;

Gra_command( "create test 0 10 100");

$t1 = CONST->locate( name => "layout");

#

# set the frame colour to blue and the

# thickness of the frame to 3

#

$t1->set( "colour" => "blue",

"width" => "3");

display();

prtc();

Page 75: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

7.4 SCAN Methods

7.4.1 Constructors

Most of the arguments of the methods are optional. Those that have to be supplied are marked ’mandatory’. The pair

colour => "red" indicates that the contructors may also be used to set SCAN attributes. The complete list of

attributes can be found in section 7.4.3.

use Spectra;

use GQE;

$s1 = SCAN->create( name => "ScanName", # mandatory

start => $start_value, # default: 0

stop => $stop_value, # default: 1

np => $np, # default: 1001

delta => $delta # instead of np

y_default => $y_d, # the default y-value

title => "title", # titel of the plot

xlabel => "x-desc.", # description of the x-axis

ylabel => "y-desc.", # description of the y-axis

comment => "...", # creates a comment text string

date => "no", # suppresses the date text

colour => "red", #

...)

$s1 = SCAN->create( name => "ScanName", # mandatory

x_ptr => \@arr_x, # arr_x and arr_y are copied to

y_ptr => \@arr_y, # the internal data structures

title => "title", # titel of the plot

xlabel => "x-desc.", # description of the x-axis

ylabel => "y-desc.", # description of the y-axis

comment => "...", # creates a comment text string

...);

$s1 = SCAN->copy( from => $ScanPtr, # a pointer to a SCAN object or

from => "ScanName", # a name of a SCAN

src => ..., # synonym for ’from’

to => "DestName" # mandatory

title => "title", # titel of the plot

xlabel => "x-desc.", # description of the x-axis

ylabel => "y-desc.", # description of the y-axis

comment => "...", # creates a comment text string

...);

$s1 = SCAN->read( name => "whatever", # mandatory

format => "fio", # fio, asc, gqe, def.: fio

x => "...", # x-column, default 1

y => "...", # y-column, default 2

file_name => "...", # default: name

title => "title", # titel of the plot

xlabel => "x-desc.", # description of the x-axis

ylabel => "y-desc.", # description of the y-axis

comment => "...", # creates a comment text string

...);

$s1 = SCAN->locate( name => "whatever", # mandatory

colour => "red",

...)

The method create() has the parameter NP, which stands for the number of points, not the number of intervalls, as

for the create command in .gra-speak.

Page 76: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

So far read() supports the formats ascii, gqe and fio.

The method locate() works for existing SCAN GQEs only. They could have been created by a restore operation

or by some other command that was executed outside the script.

7.4.2 Methods

The following methods return 1 on successful completion:

$s1-¿activate();

$s1-¿activate( clear =¿ ”1”);

$s1-¿deactivate();

Activate/deactives a SCAN. Active SCANs are displayed

$s1-¿autoscale();

$s1-¿autoscale( x =¿ ”yes”);

$s1-¿autoscale( y =¿ ”yes”);

$s1-¿autoscale( max =¿ 5);

$s1-¿autoscale(window =¿ ”yes”);

Choose approriate axes.

$s1-¿calc( expr =¿ ”calc-expr”);

my $temp = $s1->get( "name");

$s1->calc( expr => "$temp > 0’’);

For explanations see 7.4.5.

$s1-¿cursor();

Invoke the cursor module.

$s1-¿exchange();

Exchange x and y.

$s1-¿derivative();

Replaces the SCAN by its derivative.

$s1-¿display();

Displays the SCAN.

$s1-¿display( update =¿ ”yes”);

An implicit cls() is executed only, if the axes changed

$s1-¿get( ”itemName”);

Get an item value. See 7.4.3.

$s1-¿hide();

$s1-¿hide( clear =¿ ”1”);

Sets/cleas the hidden bit.

$s1-¿linearRegression();

Replaces the SCAN by a line representing its linear regression. An example can be found in ??.

$s1-¿overlay();

Suppresses the drawing of the axis.

$s1-¿overlay( src =¿ OtherName);

Suppresses the drawing of the axis and copies the window limits from OtherName.

$s1-¿postscript( file =¿ ”fname”, # def.: laser.ps

print =¿ 1, # default: 0

printer =¿ ”hasps1”); # default: see Spectra POST command

noconfirm =¿ 1); # default: 0

$s1-¿preserve();

# sets the preserve bit $s1-¿preserve( clear =¿ ”1”);

# clears the preserve bit

Page 77: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

$s1-¿roi( min =¿ $xmin, max =¿ $xmax);

$s1-¿roi net( min =¿ $xmin, max =¿ $xmax);

$s1-¿roi bg( min =¿ $xmin, max =¿ $xmax);

Return ROI counts, netcounts or the background.

$s1-¿spacing( [dist]);

The x-values of the SCAN are equally spaced by dist (or 1), the y-values are interpolated.

$s1-¿set( itemName =¿ ”itemValue”);

Set an item.

$s1-¿sort();

$s1-¿sum( min =¿ $index1, max =¿$index);

Min and max specify the range of the sum, min ¿= 0.

$s1-¿type();

$s1-¿write( format =¿ ”fio”, # fio, asc, gqe, def.: fio

file name =¿ ”...”, # default: name

fio comments =¿ ”yes”,

fio params =¿ ”p1 val1 p2 val2 ...”,

hexapod =¿ ”yes”, # default: ”no”

mca =¿ ”yes”, # default: ”no”

motors =¿ ”yes”, # include motor positions, default: ”no”

ro =¿ ”yes”, # default: ”no”, fio feature, ro == 444, read-only

scan =¿ ”yes”, # default: ”no”

ssa =¿ ”yes”, # default: ”no”

nolog =¿ ”yes”, # default: ”no”

noconfirm =¿ ”yes”); # default: ”no”

my ($ssa status, $cms, $midpoint, $int,

$bg int, $fwhm, $peak x, $peak y, $bg l, $bg r) = $s1-¿ssa();

The contents of the symbols fio comment i (1=1, 10) are written to the .fio file, e.g.:

$Spectra::SYM{ fio_comment_1} = "some message";

$Spectra::SYM{ fio_comment_2} = "[text(\"mot3 = \"gmup( mot3))]";

fio comment 2 is defined rather complicated. The reason is that it has to be evaluated at the time the file is created

(gmup() translates to get-motor-unit-position).

If the flag fio comments is supplied, the function Spectra::fio comments() is called when the output file is created.

The function returns a string which is written into the comment section of the file. The string may consist of several

lines, e.g.:

#

# \online_dir\TkIrc.pl is a good place to define this function

#

sub Spectra::fio_comments

{

my $string = "";

$string .= "line 1\n";

$string .= "line 2\n";

$string .= "! line 3\n";

$string .= "! line 4\n";

return $string;

}

Lines that do not begin with an exclamation mark are considered as “official” Spectra comments. Mind that at most 10

of these can be stored (including the comments that are generated somewhere else). If a line begins with an exclamation

mark “!”, it is written into the output file. But it is ignored by Spectra when the file is read. Still it is in the .fio file and

it can be extracted by some script.

The symbol flag additional fio comments can also be used to invoke the Spectra::fio comments() feature.

The simple scan analysis (Ssa) can also be called as a function:

Page 78: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

my ($ssa_status, $cms, $midpoint, $int,

$bg_int, $fwhm, $peak_x, $peak_y,

$bg_l, $bg_r) = Ssa( "$name_scan");

There are 3 methods of passing data from Perl to Spectra, i.e. filling SCANs. These methods are demonstrated in the

following exmple sections.

7.4.3 SCAN items

GQE items are accessed via the methods set() and get(). They are available after an object has been constructed.

Here is an example:

use Spectra;

use GQE;

$s1 = SCAN->create( name => "test");

#

# get/set an item

#

$colour = $s1->get( "colour");

$s1->set( colour => "blue");

The following table displays a list of SCAN items.

at

The viewport selection, e.g. at =¿ ”(2,3,3)” means that the screen is logically divided into 2 columns and 3 rows. The

position of the scan is in cell no. 3.

colour

The colour: black, read, green, blue, etc., see 7.4.3.

curr

The number of valid points.

doty

If 1, the x-values are understood as date-of-the-year values. Spectra displays date strings at the big tic marks.

integral

max x, max y, min x, min y

The highest/lowest data values.

mean x, mean y

name

np, total

The total number of points.

primitive

The primitive type: line, marker, histogramm, etc, see 7.4.3.

sigma x, sigma y

size

The size, default: 1.

sum

The sum of the y-values.

Page 79: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

type

The line or marker types, see 7.4.3, 7.4.3.

x maj, y maj

The big tic mark factor.

x maj off, y maj off

The big tic mark factor offset.

x max, y max, x min, y min

The window limits.

x shift, y shift

The offset of the axis.

x tic, y tic

The tic distance.

x tic off, y tic off

x log, y log

1: logarithmic scaling, 0: linear

com 1, com 2, ...

A comment line, max: 10.

The following parameters are identified by names and number. The numbers are returned by get(). The set()

function uses both.

The available colours are:

White (0),

Black (1),

Red (2),

Green (3),

Blue (4),

Cyan (5),

Yellow (6),

Magenta (7),

Grey85 (8),

Grey50 (9).

These are the primitive types:

Line (0),

Marker (1),

Histogram (2),

FilledHistogram (3),

FilledLine (4),

LineAndMarker (5).

The line types:

Solid (0)

Dotted ....... (1)

Dotted1 . . . . (2)

Dashed - - - - (3)

Dashed1 -- -- -- (4)

DashedDotted -- . -- . (5)

DashedDotted1 -- ... -- ... (6)

DashedDotted2 -- ..... -- ..... (7)

DashedDotted3 -- -- . -- -- . (8).

These are the marker types:

Dot (0)

Plus (1)

Star (2)

Page 80: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Circle (3)

DiagonalCross (4)

SolidCircle (5)

TriangleUp (6)

SolidTriangleUp (7)

TriangleDown (8)

SolidTriangleDown (9)

Square (10)

SolidSquare (11)

BowTie (12)

SolidBowTie (13)

Hourglass (14)

SolidHourglass (15)

Diamond (16)

SolidDiamond (17),

7.4.4 SCAN data

The x- and y-values of a SCAN can be accessed this way:

#!/usr/bin/env perl

use strict;

use Spectra;

use POSIX;

package Spectra;

my $s1 = SCAN->create( name => "hallo",

start => 0,

stop => 6.28);

my $len = @{$s1->{y}};

my $first = $s1->{x}[0];

my $last = $s1->{x}[-1];

print " scan $s1->{name} has $len points, from $first to $last \n";

for( my $i = 0; $i < $len; $i++)

{

$s1->{y}[$i] = POSIX::sin( $s1->{x}[$i]);

}

autoscale();

display();

keyw();

7.4.5 The calc() method

The calc() method is the interface to the Spectra calc command. The Spectra manual gives the details.

In the following examples the constructor (SCAN-¿create()) is used. It is described in 7.4.1.

The $var-¿calc( expr =¿ ”someExpr”) is implemented in the following way: Spectra executes the command calc $var-

¿name = someExpr. The expression $var-¿name is the name of the GQE.

Here is the first example:

#!/usr/bin/env perl

use strict;

use Spectra;

my $t1 = SCAN->create( name => "t1",

start => 0,

stop => 10,

Page 81: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

delta => 0.1);

$t1->calc( expr => "sin( x(t1))");

$t1->display();

Spectra::wait();

# Spectra::gra_input(); # invokes the CLI

The symbol $t1 points to a SCAN GQE. The name happens to be T1. In the calc expression the GQE can be referred

to by T1 or by $t1-¿ name.

In the following example two SCANs, sin and cos, are created and the y-values are set by the calc() method. A third

SCAN, tan, is created by duplicating the first SCAN. tan could have been ’created’ as well since the number of points

and the limits are known. In genral this is not he case, that’s why the copy() method is useful.

Finally the y-values of tan are set to the ratio of sin divided by cos. Figure 7.1 shows the graphical screen.

#!/usr/bin/env perl

use strict;

use Spectra;

my $sin = SCAN->create( name => "sin",

start => 0,

stop => 10,

delta => 0.1,

title => "Sinus",

at => "(2,2,1)",

colour => ’red’);

$sin->calc( expr => "sin( x(sin))");

my $cos = SCAN->create( name => "cos",

start => 0,

stop => 10,

delta => 0.1,

title => "Cosinus",

at => "(2,2,2)",

colour => ’green’);

$cos->calc( expr => "cos( x(cos))");

my $tan = SCAN->copy( from => "sin",

to => "tan",

title => "Tangens",

at => "(1,2,2)",

colour => ’blue’);

$tan->calc( expr => "sin/cos");

Spectra::display();

Spectra::wait();

In the next example was used as extra code for the after scan macro. The input from c5at means, the symbol

$Spectra::SYM scan name exists and the counters c1 and c5 have been selected for the measurement.

my $sname = $Spectra::SYM{ scan_name};

my $src = SCAN->locate( name => $sname);

my $res = SCAN->copy( from => $src,

to => $sname . "_res");

$res->calc( expr => "${sname}_c5/${sname}_c1");

$res->write( format => "asc",

file_name => $sname);

$res->delete();

Page 82: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Figure 7.1: calc(): sin/cos/tan

7.4.6 Smart update of the graphics window

Normally a display() starts with an implicit cls(). This is perfect as long as it doesn’t happen too often. During

measurements, an update of the screen is more appropriate than a complete re-display. That is the purpose of the

”update” =¿ ”yes” switch, see the following example:

use Spectra;

delete();

cls();

my $np = 401;

my $sin = SCAN->create( name => "sinus",

start => 0,

stop => 10,

title => "Sinus",

np => "$np",

at => "(1,2,1)");

my $tan = SCAN->create( name => "tangens",

start => 0,

stop => 10,

title => "Tangens",

np => $np,

at => "(1,2,2)");

$sin->calc( "expr" => "sin(x(sinus))");

$tan->calc( "expr" => "tan(x(tangens))");

foreach my $i( 1 .. $np)

{

$sin->set( curr => $i);

Page 83: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

$tan->set( curr => $i);

Autoscale( y => "yes");

display( update => "yes");

}

Page 84: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

7.5 TAG Methods

Class methods:

use GQE;

$tag1 = TAG->create( name => "SlotId", # mandatory

colour => "red",

...);

$tag2 = TAG->locate( "name" => "TagId"); # mandatory

Methods:

$ret = $tag1->delete();

$ret = $tag1->get( "itemName");

$ret = $tag1->set( itemName => "itemValue"[,...]);

# Examples:

$ret = $const1->get( "colour");

$ret = $const1->set( x => 0.5, y => 0.6);

7.5.1 TAG Items

GQE items are accessed via the methods set() and get(). They are available after an object has been constructed.

Table 7.5.1 displays the available TAG items.

bg colour

The background colour, see 7.4.3.

colour

The colour: black, red, green, blue, ..., see 7.4.3.

distance

The distance between text and symbol.

font

See table 7.3, default: 3.

frame

The coordinate frame 0: NDC (0 - 1), 1: WORLD

height

The font height, default: 17.

h align

The horizontal alignment: normal, left, center, right

par1

Used for rectangle, ellipse.

par2

Angle

size

The line width/marker size, default: 1.

string

The tag text.

Page 85: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

type

The line or marker type, see 7.4.3, 7.4.3.

tag size

The symbol size, default: 1.

tag type

line, marker, leftarrow, etc., see 7.2.

x, y

The tag position.

Line

Marker

LeftArrow

RightArrow

LeftRightArrow

Square

SolidSquare

Rectangle (PAR1 stretches it)

SolidRectangle

Ellipse (PAR1 stretches it)

SolidCircle (PAR1 stretches it)

Triangle

SolidTriangle

Table 7.2: The Tag Types

7.5.2 A TAG Example

#!/usr/local/perl

use Spectra;

use GQE;

cls();

#

# create a SCAN GQE ...

#

Gra_command( "create/notext test 0 10 100");

#

# ... and create a TAG GQE in the same slot

#

$t1 = TAG->create( "name" => "test");

#

# set the text string and the colour of the TAG

#

$t1->set( string => "Test",

colour => "blue");

display();

prtc();

Page 86: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

7.6 TEXT Methods

Class methods:

use GQE;

$text1 = TEXT->create( name => "whatever", # mandatory

string => "msg",

...);

$text2 = TEXT->locate( name => "whatever"); # mandatory

Methods:

$ret = $text1->delete();

$ret = $text1->get( "itemName");

$ret = $text1->set( itemName => "itemValue"[,...]);

# Examples:

$ret = $text1->get( "colour");

$ret = $text1->set( font => 12, colour => "blue");

7.6.1 TEXT Items

GQE items are accessed via the methods set() and get(). They are available after an object has been constructed.

The following table displays the available TEXT items.

bg colour

The background colour, see 7.4.3.

colour

The colour: black, red, green, blue, ..., see 7.4.3.

font

See table 7.3, default: 3.

frame

NDC (0): normalized device coordinates, WORLD(1)

height

The font height, default: 17

h align

The horizontal alignment: normal, left, center, right.

string

The text string.

ux, uy

The up-vector.

v align

The vertical alignment: normal, top, cap, half, base, bottom.

x, y

The position.

7.6.2 A TEXT Example

#!/usr/local/perl

use Spectra;

Page 87: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

TimesRoman (1)

TimesItalic (2)

TimesBold (3)

TimesBoldItalic (4)

Helvetica (5)

HelveticaOblique (6)

HelveticaBold (7)

HelveticaBoldOblique (8)

Courier (9)

CourierOblique (10)

CourierBold (11)

CourierBoldOblique (12)

NewCenturySchoolbook (13)

NewCenturySchoolbookItalic (14)

NewCenturySchoolbookBold (15)

NewCenturySchoolbookBoldItalic (16)

Symbol

Table 7.3: The Fonts

use GQE;

cls();

#

# create a TEXT GQE

#

$t1 = TEXT->create( name => "test");

#

# set the text string and give it the colour blue

#

$t1->set( string => "ein Test",

colour => "blue");

display();

prtc();

Page 88: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

7.7 UB Matrix Methods

Class methods:

use GQE;

$ub = UB->create();

$ub = UB->locate();

Methods:

$ret = $ub->get( "itemName");

$ret = $ub->set( itemName => "itemValue"[,...]);

# Examples:

my ($ub11, $ub12, $ub13,

$ub21, $ub22, $ub23,

$ub31, $ub32, $ub33) = $ub->get( "ub");

my $cv_ratio = $ub->get( "cv_ratio");

$ret = $ub->set( r0 => "(1, 0, 0)"); # using current angles

$ret = $ub->set( r0 => "($h, $k, $l, $tt, $om, $ch, $ph)"); # with angles

The available UB matrix items are listed below.

cv ratio

A parameter which is used for the convergence test during the centering of the reflections. The test is passed, if

abs( max - new max)/width < CV RATIO. The default is 0.01.

h1, h2

The orienation of the reciprocal lattice is determined by the vectors h1 and h2:

$ub-¿set( h1 =¿ ”(1, 0, 0)”);

gk

The lattice constants.

gw

The lattice angles.

rk

The reciprocal lattice constants.

rw

The reciprocal lattice angles.

n iter

The maximum number of iterations that are used to find the center of a reflection. One iteration includes the

optimization of OMEGA, TWO THETA and CHI. The centering procedure terminates earlier, if there are no

significant shifts between two consecutive iterations.

np scan

The number of scan points that are used to center a reflection.

parameter

psi

The angle that used for the FIXED PSI, FIXED PHI or FIXED OM2 scan mode (om2 = omega - two theta∗0.5).

reflex count

The number of reflections.

r0, r1, .+, r19+

r0 to r19 are the reflections that used for the calculation of the UB matrix. If no angles are specified, the current

angles are stored:

$ub-¿set( r0 =¿ ”(1, 0, 0)”); # using current angles

$ub-¿set( r0 =¿ ”(1, 0, 0, tt,om, ch,ph)”);

Page 89: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

range chi

range omega

range phi

range two theta

The scan range for the centering of the reflections.

scan mode

Specifies a constraint for the transformation of angles to momentum space.

0 Bisecting

1 Fixed psi

2 Constant plane

3 Fixed phi

4 Fixed om2 = (omega-two theta*0.5)

ub

The elements of the UB matrix:

$ub-¿set( ub =¿ [$ub11, $ub12, $ub13, $ub21, ..., $ub33]);

ub from two

The UB matrix is calculated from the first 2 reflections and the lattice parameters:

$ub-¿set( ub from two =¿ ”yes”);

ub from rafin

The UB matrix is calculated by Rafin, coded by A. Filhol, Institut Laue-Langevin, Grenoble:

$ub-¿set( ub from rafin =¿ ”yes”);

ub from dif4

The UB matrix is calculated by DIF4, coded by K. Eichhorn, Universitat Karlsruhe):

$ub-¿set( ub from dif4 =¿ ”yes”);

Page 90: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

7.8 GKS - Default Graphical Attributes

The GKS object allows the specification of the default graphical attributes. They are used when new GQEs are created.

Class method:

use GQE;

$gks = GKS->locate();

Methods:

$ret = $gks->get( "itemName");

$ret = $gks->set( itemName => "itemValue"[,...]);

# Examples:

$ret = $gks->get( "at_border_min_x");

$ret = $gks->set( at_border_min_x => 0.1);

7.8.1 GKS Items

GKS items are accessed via the methods set() and get(). They are available after an object has been constructed

(located). The following table displays the available items.

at border min x, def.: 0.2, leaves space for y-axis tic numbers

at border max x, def.: 0.1

at border min y, def.: 0.15

at border max y, def.: 0.15

The border limits determine how much space is around the SCANs.

at screen min x, def.: 0.

at screen max x, def.: 1.

at screen min y, def.: 0.05

at screen max y, def.: 0.9, leaves some space for the title

The screen limits specify the available space for the viewports.

colour

The colour: black, red, green, blue, ..., see 7.4.3.

font

See table 7.3, default: 3

primitive

The primitive type: line, marker, histogramm, etc, see 7.4.3.

size

The marker size, default: 1.

type

The line or marker type, see 7.4.3, 7.4.3.

width

The line width, default: 1.

grid colour

See 7.4.3.

grid type

See 7.4.3, 7.4.3

gra width

The line width, default: 1.

Page 91: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

text colour

See 7.4.3.

text height

The font height, default: 17

heading y

The y-position of ’Scan · · · started at · · ·’, def.: 1.08.

title y

The y-position of the title, date, ylabel: 1.02

comment y

THe y-position of the comment: 1.

h align

The horizontal alignment: normal, left, center, right, default: left

v align

The vertical alignment: normal, top, cap, half, base, bottom, default: half

xlabel y

The y-position of the x-label, default: -0.1

ylabel x

The x-position of the y-label, default: -0.1

7.9 A Simple Plotting Routine

The function plot() is an easy way to display data which consist of x- and y-pairs.

GQE::plot( x => $x,

y => $y,

start => $x_start, # optional, def. 0

stop => $x_stop, # optional, def. 1

np => $np_max, # optional, def. 1000

xlabel => "x-descr.", # optional, def. Position

ylabel => "y-descr.", # optional, def. Signal

title => "Title", # optional, def. name

comment => "some text", # optional

name => "generic_name", # optional, def. PlotScan

);

$name = GQE::plot( method => "getname"); # returns the GQE name

($max_x, $max_y) =

GQE::plot( method => "maximum"); # returns the coord. of the maximum

GQE::plot( method => "postscript",

printer => "printerName"); # optional, default: $SYM{printer},

# $ENV{PRINTER}, $ENV{LPDEST}

GQE::plot( method => "reset");

GQE::plot( method => "write", # create a fio-file

file_name => "filename", # optional

fio_params => "p1 val1 p2 val2 ...’’,

# name/value pairs of fio parameters

Page 92: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

hexapod => "yes", # optional, default ’no’

motors => "yes"); # include motor positions, opt., def. ’no’

GQE::plot( x_ptr => \@array_x, # passes arrays instead of scalars

y_ptr => \@array_y, #

...

);

If plot() is used to pass scalars, the user supplies x- and y-values. They are appended to the existing data and

displayed. x may start at high or at low values. The plot is resetted, if the x-values change their direction (plot() has

been coded to display a signal during the adjustment moves of single motors). The plot can also be resetted, if the

corresponding method (reset) is invoked.

Here is an example:

#!/usr/local/perl

use Spectra;

use GQE;

my $y = 0;

my $x = 0;

my $delta = 0.1;

while(1)

{

$y = sin( $x);

GQE::plot( x => $x,

y => $y,

xlabel => "Position");

$let = keyw(); # read keystrokes

last if( $let == 32); # the space bar terminates the loop

$x += $delta if $let == 274 ; # up-arrow

$x -= $delta if $let == 275 ; # down-arrow

}

return;

The following example shows how plot() is used to pass arrays.

#!/usr/local/perl

use Spectra;

use GQE;

@x_arr = ( 1 .. 1000);

@y_arr = ( 1 .. 1000);

foreach my $y (@y_arr)

{

$y = sin($y/10);

}

GQE::plot( x_ptr => \@x_arr,

y_ptr => \@y_arr,

name => "sinus");

Page 93: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Chapter 8

Data Busses

8.1 The Low Level VME Interface

The functions

$ret = vmeRead( "mode", $base, $offset);

$ret = vmeRrite( "mode", $base, $offset, $data);

perform raw VME I/O. The mode parameter can be: A16D8, A16D16, A24D8, A24D16, A24D32, A32D16 and

A32D32. In addition there are the control functions VmeReopen and VmeSysreset. The following example code

demonstrates how the V462 gate generator of CAEN is operated by primitive VME calls.

#!/bin/perl

#

# the timer V462 is operated by primitive VME calls

#

use Spectra;

cls();

$base = 0;

$v462_status = 0;

$v462_ch0_msb = 2;

$v462_ch0_lsb = 4;

$v462_start_ch0 = 0x200;

$v462_gate0_open = 0x800;

$v462_local_ch0 = 0x2000;

#

# read the status

#

$status = vmeRead( A24D16, $base, $v462_status);

if( $status & $v462_local_ch0)

{

print "\033[2;2f Channel 0 in local mode \n";

return;

}

if( $status & $v462_gate0_open)

{

print "\033[2;2f Gate is already open \n";

return;

}

#

# open the gate for 1.2345678 seconds

#

$ret = vmeWrite( A24D16, $base, $v462_ch0_msb , 0x1234);

$ret = vmeWrite( A24D16, $base, $v462_ch0_lsb , 0x5678);

$ret = vmeWrite( A24D16, $base, $v462_status, $v462_start_ch0);

Page 94: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

$status = vmeWrite( A24D16, $base, $v462_status);

$i = 0;

while( $status & $v462_gate0_open)

{

printf "\033[2;2f $i Waiting for the timer \n";

Wait( 0.1);

$i++;

$status = vmeRead( A24D16, $base, $v462_status);

}

The performance of the vme read() function was measured with this script:

#!/bin/perl

#

# this code runs with 1560 Hz on a 333 MHz processor,

# Linux 2.4.4, Perl 5.6.0, SIS1100

#

use Spectra;

cls();

#

# read the v462 status

#

$base = 0;

$v462_status = 0;

$time_start = Secnds();

$max = 10000;

for (1 .. $max)

{

vmeRead( A24D16, $base, $v462_status);

}

$time_total = Secnds() - $time_start;

$res = $max / $time_total;

print "\033[2;2f $time_total for $max iterations ($res Hz)\n";

8.2 The ADS Interface

The functions adsRead(), adsReadFloat(), adsReadDouble(), adsWrite(), adsWriteFloat() and

adsWriteDouble() implement the ADS/AMS interface of Beckhoff (www.beckhoff.de).

$ret = adsRead( $host, $AMSPort, $indexGroup, $indexOffset, $length);

$ret = adsWrite( $host, $AMSPort, $indexGroup, $indexOffset, $length, $data);

$ret = adsReadFloat( $host, $AMSPort, $indexGroup, $indexOffset, 4);

$ret = adsWriteFloat( $host, $AMSPort, $indexGroup, $indexOffset, 4, $xdata);

$ret = adsReadDouble( $host, $AMSPort, $indexGroup, $indexOffset, 8);

$ret = adsWriteDouble( $host, $AMSPort, $indexGroup, $indexOffset, 8, $xdata);

$ret = adsRead( "hasc1", 801, 0xf020, 0x59, 4)

$ret = adsWrite( "131.169.123.123", 801, 0xf020, 0x59, 4, 0x3f800000)

The $AMSPort is 801 for the ’SPS Laufzeitsystem 1’, for example.

$indexGroup and $indexOffset identify the register.

$length can be 1, 2, or 4 for int I/O or 4 for float I/O.

Note: Before a client can connect to a TwinCAD system via ADS, the corresponding host has to be authorized on the

server by name, AMS Net Id ( e.g.: 131.169.123.123.1.1) and address. The TwinCAD system has to be re-started after

a new host has been authorized. TwinCAD runs on Windows PCs. The wirewall of this PC has to be disabled. ADS

uses the TCP/IP port 48808.

Note: Before a client can connect to a CX system a static route has to be added on the CX. You have a TwinCat running

on a Windows PC and use ’Zielsystem waehlen’ to select the CX. Then restart the CX, enter Config mode, double-click

Routing Einstellungen, add a static route and make sure the remote route is static (login information will be prompted).

Page 95: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

8.2.1 Example: ReadLong

Here is an example for ADS I/O. The following piece of code can be used as a virtual counter.

if( $method =˜ /reset/i)

{

return 1;

}

if( $method =˜ /read/i)

{

return adsRead( "131.169.221.171", 801, 0xf020, 0x19, 4);

}

8.2.2 Example: WriteDouble, ReadDouble

This is another example. An 8 byte register that represents the setpoint position of the large-offset-monochromator is

read and written:

#!/bin/env perl

use Spectra;

my $host = "131.169.221.186";

my $AMSPort = 801;

$ret = adsReadDouble( $host, $AMSPort, 0xf020, 256, 8);

print " Sollposition $ret \n";

$ret = adsWriteDouble( $host, $AMSPort, 0xf020, 256, 8, 9.444);

$ret = adsReadDouble( $host, $AMSPort, 0xf020, 256, 8);

print " Sollposition $ret \n";

$ret = adsWriteDouble( $host, $AMSPort, 0xf020, 256, 8, 9.222);

8.3 The GPIB Interface

The functions gpibRead() and gpibWrite() access the GPIB bus. The example code switches a Keithley 617

between the different measurement modes and does a reading for each mode.

#!/usr/bin/perl

#

# Example Keithley 617

#

use Spectra;

@msg = ( "F0X", "F1X", "F2X", "F3X");

$len_max = 20;

foreach $msg (@msg)

{

$ret = gpibWrite( 7, $msg);

print " Received " . gpibRead( 7, $len_max) . "\n";

}

prtc();

8.4 The Canbus Interface

The functions canRead() and canWrite do CanBus I/O.

Page 96: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

#!/usr/bin/perl

use Spectra

#

# send 2 bytes (0, 0) to the identifier 0x201

#

$ret = canWrite( 0x201, 0, 0);

#

# generate a frame with the identifier 0x181 ...

#

$ret = canWrite( 0x181);

#

# ... and fetch the transmitted frame and split it into

# - the identifier ($adr)

# - the length of the frame ($len)

# - and the message part (@msg)

#

($adr, $len, @msg) = split ’ ’, canRead();

#

# loop until we find the desired pattern

#

while( $msg[0] != 85 ||

$msg[1] != 85)

{

$ret = canWrite( 0x181);

($adr, $len, @msg) = split ’ ’, canRead();

Wait( 0.2);

}

8.5 The Modbus Interface

The functions that access the Modbus are:

@data = modbusRead( "hostname", $adr, $nw); # in units of 2B

my $ret = modbusWrite( "hostname", $adr, @data);

my $ret = modbusOpen( "hostname");

my $ret = modbusClose( "hostname");

If the Modbus is not explicitly opened, Online does it on the first read or write access.

modbusRead() uses function 3, read holding registers, whereas modbusWrite() uses function 16, write multiple

registers.

8.5.1 Modbus example: a virtual motor

The following code gives an example of Modbus I/O. It shows how a Beckhoff motor is implemented as a virtual motor.

#!/usr/bin/perl -w

#

# file name:

# /online_dir/vm4.pl

#

# the X motor

#

use Spectra;

my ($method, $value_new) = @ARGV;

my $status = 1;

#

# the controller has a time-out after 10s, be sure to re-open the Modbus

#

Page 97: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Spectra::modbuClose( "hasa106bc01");

if( "$method" eq "set_position")

{

my $ziel = $value_new;

Spectra::modbusWrite( "hasa106bc01", 0x4002, ($ziel & 0xffff, $ziel >> 16));

Spectra::modbusWrite( "hasa106bc01", 0x4000, 1);

my $count = 0;

delete $Spectra::SYM{ INTERRUPT_SCAN};

while( 1)

{

my @data = Spectra::modbusRead( "hasa106bc01", 0x4004, 2);

my $pos = $data[0] + ($data[1] << 16);

last if( Spectra::key() == 32);

last if( $Spectra::SYM{ INTERRUPT_SCAN});

last if( $pos == $ziel);

Util::refresh() if( !($count++ % 10));

}

Spectra::modbusWrite( "hasa106bc01", 0x4000, 2);

goto finish;

}

if( "$method" eq "get_position")

{

my @data = Spectra::modbusRead( "hasa106bc01", 0x4004, 2);

my $pos = $data[0] + ($data[1] << 16);

$SYM{RETURN_VALUE} = $pos;

goto finish;

}

if( "$method" eq "get_limit_min")

{

$SYM{RETURN_VALUE} = 0;

goto finish;

}

if( "$method" eq "get_limit_max")

{

$SYM{RETURN_VALUE} = 1000000;

goto finish;

}

finish:

$status;

8.5.2 Modbus example: configuration of a motor

The following code shows how a Beckhoff motor is configured using the Modbus interface:

#!/usr/bin/env perl

#

# Usage: run bc9000_config.pl [destination]

#

use strict;

use Spectra;

my $status = 1;

my $base = 0x4000;

Spectra::modbusClose( "hasa106bc01");

Spectra::modbusWrite( "hasa106bc01", $base, 2); # halt

Page 98: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

name Explanation Example

cmcrd Read $ret = cmcrd( $n, $f, $a);

cmcrdbcd Read binary coded decimals $ret = cmcrdbcd( $n, $f, $a);

cmcrdbcdc Read complementary binary coded decimals $ret = cmcrdbcdc( $n, $f, $a);

cmcwd Write $ret = cmcwd( $n, $f, $a, $data);

cmcci Clear inhibit $ret = cmcci();

cmcsi Set inhibit $ret = cmcsi();

cmcdc Data way clear $ret = cmcdc();

cmcdz Data way zero $ret = cmcdz();

cmcsc Select crate $ret = cmcsc( $crate);

Table 8.1: Raw CAMAC Functions

Spectra::modbusWrite( "hasa106bc01", $base + 0x10, 100); # base, 0 - 2047, microsteps/sec

Spectra::modbusWrite( "hasa106bc01", $base + 0x11, 1000); # slew, 0 - 2047, microsteps/sec

Spectra::modbusWrite( "hasa106bc01", $base + 0x12, 1000); # accel, 0 - 2047

Spectra::modbusWrite( "hasa106bc01", $base + 0x18, 4); # microstepping

# 1 - 6, microsteps/vollschritt,

Spectra::modbusWrite( "hasa106bc01", $base + 0x1, 3); # reset, uebernahme

Spectra::wait( 0.1);

goto finish if( !defined( $ARGV[0]));

my $ziel = $ARGV[0];

Spectra::modbusWrite( "hasa106bc01", $base + 0x2, ($ziel & 0xffff, $ziel >> 16)); # zielposition

Spectra::modbusWrite( "hasa106bc01", $base, ( 1));

print "\033[2J";

while( 1)

{

my @data = Spectra::modbusRead( "hasa106bc01", $base + 0x4, 2);

my ($status) = Spectra::modbusRead( "hasa106bc01", $base + 0x8, 1);

my $pos = $data[0] + ($data[1] << 16);

print sprintf "\033[2;5f pos %7d, status 0x%02x \n", $pos, $status;

last if( Spectra::key() == 32);

last if( $pos == $ziel);

}

Spectra::modbusWrite( "hasa106bc01", $base, ( 2)); # halt

finish:

return $status;

8.6 The Low Level CAMAC Interface

The functions which are described in this section perform raw CAMAC I/O. They are intended to be used for debugging

purposes or for testing new hardware.

The following example code demonstrates how data is read/written from/to an input/output register.

#!/bin/perl

use Spectra;

$n = 9;

$f = 0;

$a = 0;

$status = cmcrd( $n, $f, $a);

print " cmcrd: Got $status \n";

Page 99: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

$n = 8;

$f = 16;

$a = 0;

$date = 15;

$status = cmcwd( $n, $f, $a, $data);

print " cmcwd status: $status \n";

Page 100: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Chapter 9

The Low Level Spectra Interface

The Spectra-Perl interface is developed following the aim to make the Spectra features available to Perl programmers

in an elegant way. Since only a part of the work has been done so far, Spectra programmers may be interested to learn

about the low level interface to be able to do the things themselves.

The module Spectra.pm exports several functions. Their usage is demonstrated in the following example.

#!/usr/bin/perl

use Spectra;

#

# Spectra::gra_command returns 1 to indicate a successful completion, 0 otherwise

#

$ret = Spectra::gra_command( "delete *.*");

$ret = Spectra::gra_command( "create test 0 10 100");

$ret = Spectra::gra_command( "display");

if( !$ret)

{

print " An error occurred ... \n";

prtc();

return;

}

#

# Gra_decode_... return a number, a string or "undef" to indicate an error

#

$x_min = Spectra::gra_decode_double( "attr(test, x_min)");

$colour = Spectra::gra_decode_int( "attr(test, colour)");

$date = Spectra::gra_decode_text( "date()");

if( ! defined $date )

{

print " An error occured ... \n";

prtc();

return;

}

print " x_min: $x_min \n";

print " colour: $colour \n";

print " date: $date \n";

prtc();

#

# enter Spectra

#

Spectra::gra_input();

Notice that Spectra::gra_command() always returns a numerical value: 0 or 1. In contrast, the Spectra::gra_decode_...

functions return undef to indicate an error. In Perl a variable can have the value undef. This feature allows us to

Page 101: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

handle the data transfer from Spectra to Perl in a compact form. Otherwise one had to pass a data structure consisting

of a return status and a value.

Notice also that double-quoted strings are subject of variable interpolation of scalar and list values:

#!/usr/bin/perl

use Spectra;

$var = "test";

$start = 0;

$stop = 10;

$np = 100;

$ret = Spectra::gra_command( "create $var $start $stop $np");

1

Page 102: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Chapter 10

Examples

10.1 Centering Slits using a Profile and SSA, P02

The following piece of code optimizes the centers of two slits. Notice that the devices which are used during the

measurement are supplied as a (local) profile. This does not alter the device selection.

#!/bin/env perl

use Spectra;

my $vc = "VC17";

my %profile = ( timer => [ qw( exp_t01)],

counter => [ $vc, "ipetra"],

flags => [ qw( write_to_disk 1

display_deadtime 1

bell_on_scan_end 1)]);

#

# slitName "s1"

# center "cx"

# opening "dx"

# range 2.5, np 51, openingFinal

# np 51

# openingFinal 1.25, where opening is eventually moved

#

sub doScan

{

my ( $slitName, $center, $opening, $range, $np, $openingFinal) = @_;

my $status = 1;

Spectra::log( "doScan: scanning ${slitName}, ${center}");

$Spectra::SYM{ "generic_scan_name"} = $slitName . $opening;

if( !Spectra::slit( $slitName, $opening, 0.1))

{

$status = Spectra::error( "slitscans: failed to move ${slitName} ${opening}");

goto finish;

}

if( !Spectra::scan( type => "slit",

device => "(${slitName}, ${center})",

range => $range,

np => $np,

st => 0.2,

title => "A Slit Scan",

generic_macro_name => "auto_scan",

profile => \%profile))

{

$status = Spectra::error( "slitscans: failed to execute $slitName ${center} scan");

goto finish;

Page 103: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

}

my $sname = $Spectra::SYM{ scan_name} . "_$vc";

($ssa_status, $cms, $midpoint, $int, $bg_int,

$fwhm, $peak_x, $peak_y, $bg_l, $bg_r) = Spectra::ssa( name => $sname);

if( !$ssa_status)

{

$status = Spectra::error( "slitscans: ssa_status == 0, ${slitName} ${center}");

goto finish;

}

Spectra::log( "doScan: ${slitName} ${center}, result cms $cms");

if( !Spectra::slit( $slitName, $center, $cms))

{

$status = Spectra::error( "slitscans: failed to move ${slitName} ${center}");

goto finish;

}

if( !Spectra::slit( $slitName, $opening, $openingFinal))

{

$status = Spectra::error( "slitscans: failed to move ${slitName} ${opening}");

goto finish;

}

finish:

return $status;

}

#

# main

#

my $status = 0;

if( !Spectra::slit( "s2", "dx", 3))

{

Spectra::error( "slitscans: failed to move s2_dx");

goto finish;

}

if( !Spectra::slit( "s2", "dy", 3))

{

Spectra::error( "slitscans: failed to move s2_dy");

goto finish;

}

if( !doScan( "s1", "cx", "dx", 2.5, 51, 1))

{

goto finish;

}

if( !doScan( "s1", "cy", "dy", 2.5, 51, 1))

{

goto finish;

}

if( !doScan( "s2", "cx", "dx", 2.5, 51, 1.25))

{

goto finish;

}

if( !doScan( "s2", "cy", "dy", 2.5, 51, 1.25))

{

goto finish;

}

Spectra::log( "slitscans: DONE");

$status = 1;

finish:

Page 104: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

$status;

10.2 PE image series, incl. loop over SDD positions, P02

This example can be found in the Online -tki manual.

10.3 Converting .fio to .dat files

The following script converts all .fio files of a directory to .dat files.

#!/usr/bin/perl -w

#

# convert .fio to ASCII files

#

# the column descriptions are copied to comments

#

use strict;

my @files = <*.fio>;

my @lines;

foreach my $file (@files)

{

next if( $file !˜ /\.fio/);

print "Converting $file \n";

@lines = ‘cat $file‘;

$file =˜ /(.+)\.fio/;

my $temp = "$1" . ".dat";

if( -e "$temp")

{

print "\007\n\n $temp exits \n\n";

goto finish;

}

my $flag_found_data = 0;

#

# open the output file

#

open FILE, "> $temp";

foreach my $line (@lines)

{

chomp $line;

#

# skip all files unti ’%d’

#

if( $line =˜ /\%d/i)

{

$flag_found_data = 1;

next;

}

if( $flag_found_data)

{

#

# the ’!’ may indicate a comment

#

if( $line =˜ /col/i)

{

print FILE "! $line \n";

}

Page 105: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

else

{

print FILE "$line \n";

}

}

}

close FILE;

}

finish:

10.4 ROIs from many files

The following script calculated differences of ROIs for a number of files.

#!/bin/env perl

use Spectra;

#use GQE;

if( scalar( @ARGV) < 2)

{

print "\n Usage: \n\n";

print " ./roi.pl startNo stopNo \n\n";

goto finish;

}

Spectra::delete();

my $start = $ARGV[0];

my $stop = $ARGV[1];

my $res = SCAN->create( name => "result",

start => $start,

stop => $stop,

delta => 1,

xlabel => "Filenumber",

ylabel => "delta-roi");

my $count = 0;

foreach my $i ( $start .. $stop)

{

my $s1 = SCAN->read( file_name => "ll_00035_mythen_${i}.dat",

format => "asc");

my $roi1 = $s1->roi( min => 350, max => 700);

my $roi2 = $s1->roi( min => 750, max => 1050);

my $temp = $roi1 - $roi2;

$res->{x}[$count] = $i;

$res->{y}[$count] = $temp;

# print " i $i res $temp\n";

$count++;

}

$res->autoscale();

$res->display();

$res->write( file_name => "roi_${start}_${stop}.dat",

format => "asc");

if( Spectra::yesno( "Enter Spectra"))

{

Spectra::gra_input();

Page 106: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

}

finish:

;

10.5 SSA for many .fio Files

The following script demonstrates how the SSA procedure is applied to certain .fio files of the current directory.

#!/usr/bin/perl -w

#

# this script does a ssa (single scan analysis, implemented in spectra) for files

# in the working directory that begin with string to be given at program call, e.g.

# ’ssa.pl test’ will perfrom a ssa for each ’.fio’-file that begin with ’test’

#

# output of script is a file named by the search string with extension

# ’ssa’, e.g. ’test.ssa’ for given program call ’perl ssa.pl test’

#

# limitations: no error handling, i.e. program terminates if fio-file contains no data

# (no notification, empty output file if first input file conains no data etc.)

#

#

# T. Kracht, A. Rothkirch

#

# September 2005

use strict;

use Spectra;

use GQE;

my ($s, $ssa_status, $cms, $midpoint, $int,

$bg_int, $fwhm, $peak_x, $peak_y,

$bg_l, $bg_r);

if( !@ARGV)

{

print_usage();

goto finish;

}

#

# the default prefix

#

my $pattern = $ARGV[0];

opendir( D, "./");

my @files = sort readdir(D);

closedir( D);

# define and open output file

open( FH, ">$pattern.ssa");

# write file header: descriptor for columns

print FH "filename, cms, midpoint , integral, bg_int, fwhm, x_pos_at_max, counts_at_max, bg_l,

# loop over files

foreach my $file (@files)

{

#

# select files that begin with pattern given in programm call

#

next if( $file !˜ /ˆ$pattern.+\.fio/i);

Page 107: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

#

# the file may have several columns, we use the

# assignment 1 -> x, 2 -> y

#

$s = SCAN->read( file_name => $file, qw( x 1 y 2));

($ssa_status, $cms, $midpoint, $int,

$bg_int, $fwhm, $peak_x, $peak_y, $bg_l, $bg_r) = $s->ssa();

if( $ssa_status)

{

print "$file, $cms, $midpoint, $int, $bg_int, $fwhm, $peak_x, $peak_y, $bg_l, $bg_r\n";

#

# write ssa result to file

#

print FH "$file, $cms, $midpoint , $int, $bg_int, $fwhm, $peak_x, $peak_y, $bg_l, $bg_r\n";

#

# un-comment the following lines to inspect the data and see the ssa result

#

# $s->display();

# Spectra::prtc();

#

}

$s->delete();

}

close( FH);

finish:

;

#

#

#

sub print_usage

{

print << "EOF"

Usage:

./ssa.pl prefix

EOF

;

}

10.6 Asynchronous Move, P09

#!/usr/env perl

use strict;

use Spectra;

use GQE;

use Motor;

my $ret;

# global variables

my $pos;

my $dstart;

my $dend;

my $status = 1;

if ( $ARGV[0] eq "help" )

Page 108: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

{

print "\n\n";

print " This script is used to scan position of a motor, \n";

print " one pilatus image will be obtained: start and end \n";

print " positions are given relative to the starting point; \n";

print " motor returns to the starting point of the scan after scan!\n\n";

print " Usage:\n\n";

print " plup motor_name relativemove_start relativemove_stop exp_time";

print "\n\n\n";

$status = 0 ;

goto finish ;

}

if( !defined( $Spectra::SYM{ generic_scan_name}))

{

$Spectra::SYM{ generic_scan_name} = "hasylab";

}

my $sname = Spectra::create_scan_name();

print "scan name $sname \n";

#

# write some info to online.log

#

Spectra::log( "scan name $sname");

my $scan_number = -1;

if( $sname =˜ /(.+?)_0*(\d+)/)

{

$scan_number = $2;

}

if( $scan_number == -1)

{

Spectra::error( "shotrot_new:: trouble finding scan_number");

exit 0;

}

my $motor_name = "exp_mot01";

Spectra::amove( $motor_name => 20);

#

# at this place you might want to start a detector

#

while( Spectra::cm( $motor_name))

{

print "$motor_name " . Spectra::gmup( $motor_name) . "\n";

#

# here you might want to check the detector state

#

}

Spectra::complete_move( $motor_name);

while( Spectra::cm( $motor_name))

{

Spectra::wait( 0.1);

}

#

# the preceeding complete-move is not necessay, if you

# go back to some position with a synchronous move anyway

#

Spectra::move( $motor_name => 0);

print "the scan number is $scan_number \n";

Spectra::gra_command( "create/scan $sname 0 1 1");

$Spectra::SYM{ scan_name} = $sname;

Spectra::Write_fio( scan => 1,

motors => 1,

Page 109: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

file => $sname);

Spectra::deactivate();

Spectra::cleanup();

finish:

$status;

10.7 Asynchronous Moves

#!/usr/bin/perl -w

#

# MOT1 is moved from 0 to 20000 or from 20000 to 0 while

# MOT2 oscillates between 0 and 20

#

use strict;

use Spectra;

my ($pos1, $pos2);

gmup( "mot1") < 10000 ? ($pos1 = 20000) : ($pos1 = 0);

amove( mot1 => $pos1) or die "Failed to setup MOT1";

while( cm( "mot1"))

{

gmup( "mot2") < 10 ? ($pos2 = 20) : ($pos2 = 0);

saum( "mot2", $pos2) or die " Failed to Saum";

start_move( "mot2") or die " Failed to start_move";

while( Cm( "mot2"))

{

print "\033[2;1f MOT2 " . gmup( "mot2") . "\033[K\n";

print "\033[3;1f MOT1 " . gmup( "mot1") . "\033[K\n";

Wait( 0.2);

if( key() == 32)

{

stop_move( "mot1");

stop_move( "mot2");

complete_move( "mot2");

print "\033[2;1f MOT2, stopped at " . gmup( "mot2") . "\033[K\n";

goto finish;

}

}

print "\033[2;1f MOT2 before complete " . gmup( "mot2") . "\033[K\n";

complete_move( "mot2");

print "\033[2;1f MOT2, end position: " . gmup( "mot2") . "\033[K\n";

}

finish:

print "\033[2;1f MOT2 " . gmup( "mot2") . "\033[K\n";

print "\033[3;1f MOT1 " . gmup( "mot1") . "\033[K\n";

10.8 MCA()

The following script does:

• a MCA spectrum is measured using EXP MCA01, 8192 channels

• the timer EXP T01 is gating the MCA, sample time is 1s

• after the measurement a .fio file is created, tst 00001.fio

• if the script is repeatedly called, the next file would be tst 00002.fio

• the motor positios are included in the output file

Page 110: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

The full syntax of MCA() is given in 6.5.2.

#!/bin/perl

use Spectra;

$Spectra::SYM{ generic_mca_name} = "tst";

$ret = Spectra::mca(

adc => "exp_mca01",

channels => 8192,

comment => ’this is a comment’,

include_motors => 1,

noconfirm => 1,

nodisplay => 0,

refresh_cycle => 1,

log_scale_y => 1,

sample_time => 1,

store => 1,

timer => "exp_t01",

update_time => 1);

10.9 Scans (measurements)

10.9.1 DUMMY Scan

#!/usr/bin/env perl

use Spectra;

#

# a dummy scan

#

Spectra::scan( device => "dummy",

start => 0,

stop => 100,

delta => 20,

comment => "A comment",

scan_name => "test_name",

st => 1) or die " Failed to execute a DUMMY scan";

10.9.2 Single Motor Scan

#!/usr/bin/env perl

use Spectra;

#

# a single motor scan

#

Spectra::scan( device => "mot12",

range => 0.1,

st => 0.2, # sample time

np => 11) or die " Failed to execute a motor scan ";

10.9.3 2D Scan, Single Motor Scan with Outer Loop

The following script shows how mot11 is scanned at different positions of mot12. These positions are -80, -79 and

-78. Motor mot11 is scanned from 100 to 101 with a stepwidth of 0.1. The sample time is 0.1s.

#!/usr/bin/perl -w

use strict;

my $status = 1;

#

Page 111: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

# the outer loop motor and its positions

#

my $mot = "mot12";

my @pos = qw( -80 -79 -78);

my $st = 0.1; # sample time

foreach my $pos ( @pos)

{

if( !Spectra::move( $mot => $pos))

{

$status = Spectra::error( "failed to move $mot");

goto finish;

}

#

# inner loop: mot11

#

Util::log( "execute a mot11 scan ");

if( !Spectra::scan( type => "motor",

device => "mot11",

start => 135,

stop => 136,

delta => 0.1,

st => $st, # sample time

comment => "$mot at $pos"))

{

$status = Spectra::error( " Failed to scan ");

goto finish;

}

}

finish:

$status;

10.9.4 2D Scan, Flipping the Scan Direction

MOT1 is scanned at different positions of MOT2. MOT1 is scanned from 5 to 10 and then from 10 to 5 reverting the

direction.

#!/usr/bin/perl -w

#

use strict;

my $status = 1;

#

# the outer loop motor and its positions

#

my $mot_2d = "mot27";

# my @pos_2d = qw( 10 20 30);

my @pos_2d = map {$_ = $_*0.1 + 0.3} ( 0 .. 2);

#

#

#

my $start = -2;

my $stop = -1.9;

my $st = 0.1; # sample time

my $bl = Spectra::get_motor_unit_backlash( "mot30");

Util::log( "mot30, set backlash to 0, was $bl");

Spectra::set_motor_unit_backlash( "mot30", 0.);

foreach my $pos_2d ( @pos_2d)

{

if( !Spectra::move( $mot_2d => $pos_2d))

Page 112: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

{

$status = Spectra::error( "failed to move $mot_2d");

goto finish;

}

#

# inner loop: mot30

#

Util::log( "execute a mot30 scan, from $start to $stop ");

if( !Spectra::scan( type => "motor",

device => "mot30",

start => $start,

stop => $stop,

delta => 0.01, # step width

st => $st, # sample time

comment => "$mot_2d at $pos_2d"))

{

$status = Spectra::error( " Failed to scan ");

goto finish;

}

#

# this statement reverses the scan direction

#

( $start, $stop) = ( $stop, $start);

}

finish:

Util::log( "mot30, set backlash to $bl");

Spectra::set_motor_unit_backlash( "mot30", $bl);

$status;

10.9.5 3D Scan, Flipping the Scan Direction

#!/usr/bin/perl -w

#

use strict;

my $status = 1;

#

# the outer loop motor and its positions

#

my $mot_2d = "mot27";

# my @pos_2d = qw( 10 20 30);

my @pos_2d = map {$_ = $_*0.1 + 0.3} ( 0 .. 2);

#

my $mot_3d = "mot29";

my @pos_3d = map {$_ = $_*0.2 - 2.} ( 0 .. 2);

#

#

#

my $start = -2;

my $stop = -1.9;

my $st = 0.1; # sample time

my $bl = Spectra::get_motor_unit_backlash( "mot30");

Util::log( "mot30, set backlash to 0, was $bl");

Spectra::set_motor_unit_backlash( "mot30", 0.);

foreach my $pos_3d ( @pos_3d)

{

if( !Spectra::move( $mot_3d => $pos_3d))

{

$status = Spectra::error( "failed to move $mot_3d");

Page 113: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

goto finish;

}

foreach my $pos_2d ( @pos_2d)

{

if( !Spectra::move( $mot_2d => $pos_2d))

{

$status = Spectra::error( "failed to move $mot_2d");

goto finish;

}

#

# inner loop: mot30

#

Util::log( "execute a mot30 scan, from $start to $stop ");

if( !Spectra::scan( type => "motor",

device => "mot30",

start => $start,

stop => $stop,

delta => 0.01, # step width

st => $st, # sample time

comment => "$mot_2d at $pos_2d, $mot_3d at $pos_3d")

)

{

$status = Spectra::error( " Failed to scan ");

goto finish;

}

#

# this statement reverses the scan direction

( $start, $stop) = ( $stop, $start);

}

}

finish:

Util::log( "mot30, set backlash to $bl");

Spectra::set_motor_unit_backlash( "mot30", $bl);

$status;

10.9.6 Alignment of 8 Motors, SLAC

The following script uses SSA to align 8 motors.

#!/usr/bin/env perl

use strict;

my $status = 1;

#

# 8 motors are aligned, one after the other,

# the @motors array defines the sequence

#

my @motors = qw( exp_mot01 exp_mot02 exp_mot03 exp_mot04

exp_mot05 exp_mot06 exp_mot07 exp_mot08);

my %ranges = ( exp_mot01 => 1.1,

exp_mot02 => 1.2,

exp_mot03 => 1.3,

exp_mot04 => 1.4,

exp_mot05 => 1.5,

exp_mot06 => 1.6,

exp_mot07 => 1.7,

exp_mot08 => 1.8,

);

my $np = 51;

my $st = 0.1; # sample time

Page 114: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

foreach my $mot ( @motors)

{

my $pos = Spectra::gmup( $mot);

Util::log( "aligning $mot, range $ranges{$mot}, now at $pos ");

if( !Spectra::scan( type => "motor",

device => $mot,

range => $ranges{$mot},

np => $np,

st => $st,

comment => "Aligning $mot, range $ranges{$mot}",

ssa => 1,

#

# auto_return: 2 - midpoint, 3 - cms, 4 - peak

#

auto_return => 2,

#

# the device selection by ’profile’ is valid only

# this scan function

#

profile =>

{

timer => [ qw( exp_t01)],

counter => [ qw( vc17)]

}))

{

$status = Spectra::error( " Failed to align $mot");

goto finish;

}

my $pos = Spectra::gmup( $mot);

Util::log( "aligning $mot, DONE, now at $pos ");

}

finish:

$status;

10.9.7 spirale.pl, using profile, P10

The following piece of code executes a scan with two motors following an arbitrary path, independent of each other.

The virtual counters VC13 and VC14 are prepared to read the positions. This way the positions are stored the output

file.

#

# @pos_x and @pos_y are filled with some positions, e.g. a spiral

#

my @pos_x = ();

my @pos_y = ();

foreach my $x (0 ... 10)

{

@pos_x = (@pos_x, $x/10.);

@pos_y = (@pos_y, $x/10. + 1);

}

Spectra::scan( device => "dummy",

start => 0,

stop => (scalar(@pos_y) - 1), # use the array length to calc. the stop value

delta => 1,

st => 0.1,

title => "A Test Scan",

profile =>

{ timer => [ qw( exp_t01)],

counter => [ qw( exp_c01 exp_c02 vc13 vc14)], # VC13 and VC14 read the positions

Page 115: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

exp_mca01 => { channels => 8192},

sca1 => { mca => "exp_mca01",

min => 1000,

max => 2000},

flags => [ qw( write_to_disk 1

display_deadtime 1

bell_on_scan_end 1)],

before_during_function => sub {

Spectra::move( exp_dmy01 => $pos_x[ $Spectra::SYM{ sindex}

exp_dmy02 => $pos_y[ $Spectra::SYM{ sindex}

}});

10.9.8 Lenses, using profile, P03

#!/bin/env perl

use Spectra;

my ( $lense_start, $lense_stop, $lense_delta) = ( 800, 850, 10);

my ( $open_y, $open_z) = ( -5, 0.5);

my $lense_pos = $lense_start;

#

# move to ’open’ positions

#

if( !Spectra::move( hexa5_moty => $open_y))

{

goto finish;

}

if( !Spectra::move( hexa5_motz => $open_z))

{

goto finish;

}

while( $lense_pos < $lense_stop)

{

if( !Spectra::move( crl1_z => $lense_pos))

{

goto finish;

}

#

# open: -5

#

$Spectra::SYM{ generic_scan_name} = "lns_y";

if( !Spectra::scan( device => "hexa5_moty",

start => -2.9,

stop => -2.1,

auto_return => 1,

st => 0.1,

np => 11,

comment => "lense at $lense_pos, motz " .

Spectra::gmup( "hexa5_motz"),

profile =>

{ timer => [ qw( exp_t01)],

counter => [ qw( exp_vfc01 ipetra)],

flags => [ qw( write_to_disk 1

display_deadtime 1

Page 116: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

bell_on_scan_end 1)],}))

{

goto finish;

}

#

# open: 0.5

#

$Spectra::SYM{ generic_scan_name} = "lns_z";

if( !Spectra::scan( device => "hexa5_motz",

start => -0.5,

stop => 0.5,

auto_return => 1,

st => 0.1,

np => 11,

comment => "lense at $lense_pos, moty " .

Spectra::gmup( "hexa5_moty"),

profile =>

{ timer => "exp_t01",

counter => [ qw( exp_vfc01 ipetra)],

flags => [ qw( write_to_disk 1

display_deadtime 1

bell_on_scan_end 1)],}))

{

goto finish;

}

$lense_pos += $lense_delta;

}

finish:

;

10.9.9 Photonic Science Camera, using profile, P03

The following script, psacq.pl, takes some frames with the Photonic Science Camera and uses a counter to measure

the flux. The script can be called from the Online command line by issuing, e.g.:

psacq 0.1 20

The symbol psacq has to be defined in /online dir/exp ini.exp:

psacq = "run [˜.prog]psacq.pl"

Here is the script:

#!/bin/env perl

#

# Photonic Science Camera -> VC1

#

use Spectra;

my $status = 1;

my ( $sample_time, $np) = @ARGV;

if( !defined( $sample_time) ||

!defined( $np))

{

print "\n\n Usage: \n\n";

print " psacq sampleTime Np \n";

print "\n\n";

goto finish;

}

Page 117: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

if( !defined( $Spectra::SYM{ generic_scan_name}))

{

$Spectra::SYM{ generic_scan_name} = "hasylab";

}

$status = Spectra::scan( device => "dummy",

start => 0,

stop => ($np - 1),

delta => 1,

st => $sample_time,

title => "A Photonic Science Test Scan",

profile =>

{ timer => [ qw(p03nano_t01)],

counter => [ qw( p03nano_c01 vc1 ipetra)],

flags => [ qw( write_to_disk 1

display_deadtime 1

bell_on_scan_end 1)],

});

finish:

$status;

10.9.10 Motor Regions Scan

#!/usr/bin/env perl

use Spectra;

#

# motor regions scan

#

Spectra::scan( device => "mot12",

regions => "yes",

regions_file => "regions1.exa") or die " Failed to execute a motor scan ";

The regions file may have the following contents:

!

! Data

%d

Col 1 Energy FLOAT

Col 2 Delta FLOAT

Col 3 Sample_Time FLOAT

Col 4 Edge FLOAT

Col 5 Power FLOAT

50 1 0.2 0 0

60 2 0.1 0 0

70 0 0 60000 1

10.9.11 Energy Scan

#!/usr/bin/env perl

use Spectra;

#

# an energy scan

#

Spectra::scan( type => "energy",

range => 10,

sample_time => 0.2,

np => 11) or die "Failed to execute an energy scan ";

10.9.12 EXAFS Scan

#!/usr/bin/env perl

Page 118: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

use Spectra;

my $status = 1;

#

# an EXAFS scan

#

if( !Spectra::scan( type => "exafs"))

{

print " Failed to execute an exafs scan \n";

$status = 0;

goto finish;

}

if( !Spectra::scan( type => "exafs",

exafs_file => "exafs1.exa"))

{

print " Failed to execute an exafs scan \n";

$status = 0;

goto finish;

}

finish:

$status;

The file exafs1.exa may contain the following lines:

!

! Data

%d

Col 1 Energy FLOAT

Col 2 10 FLOAT

Col 3 0.5 FLOAT

Col 4 Edge FLOAT

Col 5 Power FLOAT

74750 10 0.5 0 0

74970 0.5 0.5 0 0

75040 0.5 0.5 75000 1

76000 0 0.5 0 0

10.9.13 Combined Move (CM) Scan

In the following example MOT11 is moved within the given scan limits. MOT12 is moved in parallel but twice as

much because factor => 2.

#!/usr/bin/env perl

use Spectra;

my $status = 1;

#

# Combined move:

#

if( !Spectra::scan( type => "cm",

device => "mot11",

factor => 2,

device_cm => "mot12",

st => 0.1,

range => 1,

np => 11,

generic_macro_name => "auto_scan"))

{

print " Failed to execute a CM scan \n";

$status = 0;

goto finish;

}

Page 119: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

finish:

$status;

10.9.14 Omega-2Theta Scan, 2Theta-Omage Scan

This kind of scan is available only at experiments that have the diffractometer software installed.

#!/usr/bin/env perl

use Spectra;

my $status = 1;

#

# omega-2theta scan

#

if( !Spectra::scan( type => "om_tt",

range => 1,

st => 0.2,

np => 11))

{

print " Failed to execute a om_tt scan \n";

$status = 0;

goto finish;

}

if( !Spectra::scan( type => "tt_om",

range => 1,

st => 0.2,

np => 11))

{

print " Failed to execute a tt_om scan \n";

$status = 0;

goto finish;

}

finish:

$status;

If Omega and 2Theta are represented by single motors, this kind of scans can also by executed as a combined-move

(CM) scans (non-diffractometer scan), see section 10.9.13.

10.9.15 2Theta Scan

This kind of scan is available only at experiments that have the diffractometer software installed.

#!/usr/bin/env perl

use Spectra;

#

# 2-theta scan

#

Spectra::scan( type => "two_theta",

range => 1,

st => 0.2,

np => 11) or die " Failed to scan 2Theta";

If 2Theta is represented by a single motor, this kind of scan can also by executed as a normal scan (non-diffractometer

scan), see section 10.9.2.

10.9.16 hkl Scans

This kind of scan is available only at experiments that have the diffractometer software installed.

#!/usr/bin/env perl

use Spectra;

#

# hkl scans

Page 120: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

#

Spectra::scan( type => "hkl",

start_hkl => [1, 0, 0],

stop_hkl => [2, 0, 0],

sample_time => 0.1,

np => 11) or die " Failed to scan hkl";

Spectra::scan( type => "hkl",

start_h => 1,

stop_h => 2,

sample_time => 0.1,

np => 11) or die " Failed to scan hkl";

10.9.17 Scan/Reflection

This kind of scan is available only at experiments that have the diffractometer software installed. The first argument is

mandatory, the others not.

#!/usr/bin/env perl

use Spectra;

Spectra::scan( type => "reflection", # mandatory

auto_filter => 0,

centering_order => "OCTP",

coarse => 0,

np_scan => 11,

nobackground_subtraction => 0,

range_chi => 0.5,

range_omega => 0.5,

range_phi => 0.5,

range_two_theta => 0.5,

store => 1);

10.9.18 Slit Scan

#!/usr/bin/env perl

use Spectra;

#

# slit scans

#

Spectra::scan( type => "slit",

device => "(slt1, cx)",

start => 1,

stop => 2,

delta => 0.1,

comment => "Slit Scan",

st => "0.1") or die " Failed to execute a slit scan";

10.9.19 Continuous Move Scan

The following command shows how to start a continuous scan. While the motor constantly moves between the scan

limits, the measurements are executed. The sample time is calculated using the sweep time and delta or np.

#!/usr/bin/env perl

use Spectra;

#

# a continuous scan

#

Spectra::scan( device => "mot11",

start => 135,

stop => 140,

delta => 0.5,

Page 121: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

scan_par => 20, # total scan time

continuous => 1) or die " Failed to execute a motor scan ";

10.9.20 Om-tt scan with outer loop

The following script demonstrates how an omega-2theta scan is executed at different positions of an outer loop motor.

It also demonstrates how a scan parameter, the sample time, is specified for each position of the outer loop motor. It

invoked from the command line of the Online widget. If the Scan widget is open, it will be updated. The script can be

interrupted by pressing any Stop button.

#!/usr/bin/perl -w

use strict;

my $status = 1;

#

# the outer loop motor and its positions

#

my $mot = "mot2";

my @pos = qw( 7 7.5 8);

#

# different sample times for different positions

# of the outer loop motor

#

my @st = qw( 0.1 0.2 0.3);

foreach my $i ( 0 .. (scalar( @pos) - 1))

{

if( !Spectra::move( $mot => $pos[$i]))

{

$status = Spectra::error( "failed to move $mot");

goto finish;

}

#

# inner loop: omega-2theta scan

#

Util::log( "execute a om_tt scan");

if( !Spectra::scan( type => "om_tt",

start => 3,

stop => 4,

delta => 0.5,

st => $st[$i], # sample time

comment => "$mot at $pos[$i]"))

{

$status = Spectra::error( " Failed to scan om_tt");

goto finish;

}

}

finish:

$status;

10.9.21 Sweep with outer loop motor, P10

This example can be found in the Online -tki manual.

10.10 SCAN (GQE)

10.10.1 Passing data by array references

This example demonstrates how arrays of floating point numbers are transferred to SPECTRA. The purpose is to

display the data and create a Postscript output file.

Page 122: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

#!/usr/bin/perl -w

use Spectra;

use GQE;

#

# delete everything

#

Spectra::delete();

#

# create the arrays

#

my @x_arr = ( 0 .. 100);

my @sin_arr = ( 0 .. 100);

#

# fill the arrays

#

foreach my $x (@x_arr)

{

$x = $x/10;

}

foreach my $y (@sin_arr)

{

$y = sin($y/10);

}

#

# create the SCAN

#

$sin = SCAN->create( name => "Sinus",

title => "Sinus",

x_ptr => \@x_arr,

y_ptr => \@sin_arr,

colour => "red") or

die " Failed to create Sinus ";

#

# set the viewport: the screen is divided into a 1x2 matrix,

# the plot is placed into the position no. 1

#

$sin->set( "at" => "(1,2,1)");

#

# find window limits and display

#

Spectra::autoscale();

Spectra::display();

if( Spectra::yesno( "Postscript"))

{

Post( "/dina4/nocon/print");

}

10.10.2 Passing data by direct assignments

This example shows how a SCAN GQE is created by the create() method and how the data are manipulated.

#!/usr/bin/perl

use Spectra;

use GQE;

cls();

Page 123: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

$size = 100;

#

# create a SCAN t1 and ...

#

$t1 = SCAN->create( name => "t1",

start => 0,

stop => 10,

np => $size) or

die " Failed to create t1 ";

#

# ... set the y-values to sinus() ...

#

for $i (0 .. ($size - 1))

{

$t1->{y}[$i] = sin( $t1->{x}[$i]);

}

#

# ... and write it to a file (t1.fio).

#

$ret = $t1->write( noconfirm => "yes");

$t1->set( at => "(2,2,3)", colour => "red");

Spectra::autoscale();

Spectra::display();

#

# cleanup

#

$t1->delete();

10.10.3 Passing data as a buffer reference (fast)

This example demonstrates how SCANs can be created by supplying a list of value pairs. This is by far the fastest

method because the data is not transfered one by one. Instead the buffer is passed to Spectra by a single call. Spectra is

then cutting it into records, which are delimited by \n. Each record contains 2 numbers that are separated by blanks.

The first of the numbers is decoded as an x-value the second as the corresponding y-value. The number of points of the

newly created SCAN is just the number of records.

#!/usr/bin/perl -w

use Spectra;

use GQE;

use POSIX;

#

# delete everything

#

Spectra::delete();

#

# create the buffer

#

my $buffer = ’ ’ x 100000;

$buffer = "";

#

# fill the buffer with a list of value pairs, each record is

# terminated by ’\n’

#

foreach my $i ( 1 .. 8192)

{

my $sin = POSIX::sin( $i/800);

Page 124: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

$buffer .= "$i $sin\n";

}

$sin = SCAN->create( name => "Sinus",

title => "Sinus",

data_ptr => \$buffer) or die " Failed to create Sinus ";

#

$sin->set( "at" => "(1,2,2)");

#

# find window limits and display

#

Spectra::autoscale();

Spectra::display();

Spectra::keyw();

10.10.4 Linear regression

In the following script a SCAN, named RND, is created and filled with random numbers. The SCAN is copied to LR

which is replaced by a linear regression of the data. The result is displayed, see below.

#!/usr/bin/perl -w

use Spectra;

use GQE;

use strict;

#

# delete everything

#

Spectra::delete();

#

# create the arrays

#

my @x_arr = ( 0 .. 100);

my @y_arr = ( 0 .. 100);

#

# fill the arrays

#

foreach my $x (@x_arr)

{

$x = $x/10;

}

foreach my $y (@y_arr)

{

$y = 10 + $y + Spectra::random()*10;

}

#

# create the SCAN

#

my $rnd = SCAN->create( name => "Rnd",

title => "Rnd",

x_ptr => \@x_arr,

y_ptr => \@y_arr,

colour => "red") or

die " Failed to create Rnd ";

my $lr = SCAN->copy( from => $rnd,

to => "LR");

$lr->linearRegression();

Spectra::autoscale();

Spectra::display();

Page 125: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Spectra::gra_input();

Figure 10.1: A linear regresseion

10.10.5 Data conversion

The following piece of code shows how internal Spectra data (fix positions, ioni1, data 1, data 2, ...) are written to an

external file.

#!/usr/bin/env perl

use strict;

use Spectra;

my $fix_positions = SCAN->locate( name => "fix_positions") or

die " failed to locate fix_positions ";

my $ioni1 = SCAN->locate( name => "ioni1") or

die " failed to locate ioni1 ";

open( FH, ">out.lis");

foreach my $i ( 0 .. (scalar( @{$fix_positions->{y}}) - 1))

{

my $name = "DATA_" . ($i + 1);

my $data = SCAN->locate( name => $name) or

die "failed locate $name";

foreach my $chan ( 0 .. (scalar( @{ $data->{y}}) - 1))

{

print FH $fix_positions->{ y}[ $i] . " " .

$ioni1->{y}[$i] . " " .

$chan . " " . $data->{ y}[ $chan] . "\n";

}

print FH "\n";

Page 126: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

}

close( FH);

1;

10.10.6 read()/write()

This example shows how a SCAN GQE is read from a disk file.

#!/usr/bin/perl

use Spectra;

use GQE;

cls();

#

# read t1.fio and name it t2

#

$t1 = SCAN->read( format => "fio",

name => "t2",

file_name => "t1.fio") or

die " Failed to read t1.fio";

#

# set the viewports and colours

#

$t1->set( at => "(2,2,1)", colour => "red");

Spectra::autoscale();

Spectra::display();

#

#

#

$t1 = SCAN->write( "file_name" => "t2.fio") or

die " Failed to create t2.fio";

#

# cleanup

#

$t1->delete();

10.11 Virtual motors

.

10.11.1 A very trivial example

Here is a script that implements a virtual motor. Does does nothing else but else but changing a global symbol.

Before the virtual motor can be used, the following command has to be entered: ONLINE> def vm1.

#!/usr/bin/perl -w

#

# file name: /online_dir/vm1.pl

#

# This script is a template for a virtual motor.

#

my ($method, $value_new) = @ARGV;

$Spectra::dummy_vm1 = 0 if( !defined( $Spectra::dummy_vm1));

my $status = 1;

Page 127: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

if( $method eq "set_position")

{

$Spectra::dummy_vm1 = $value_new;

}

elsif( $method eq "get_position")

{

$SYM{RETURN_VALUE} = $Spectra::dummy_vm1;

}

elsif( $method eq "get_limit_min")

{

$SYM{RETURN_VALUE} = -100;

}

elsif( $method eq "get_limit_max")

{

$SYM{RETURN_VALUE} = 100;

}

elsif( $method eq "exec_stop")

{

Util::log( "method exec-stop");

}

else

{

Spectra::error( "vm1: failed to identify $method");

$status = 0;

goto finish;

}

finish:

$status;

10.11.2 A trivial example

Here is a script that implements a virtual motor. It maps vm1 to mot2.

Before the virtual motor can be used, the following command has to be entered: ONLINE> def vm1.

#!/usr/bin/perl -w

#

# file name: /online_dir/vm1.pl

#

# This script is a template for a virtual motor.

#

my ($method, $value_new) = @ARGV;

my $status = 1;

if( $method eq "set_position")

{

$status = Spectra::move( mot2 => $value_new);

}

elsif( $method eq "get_position")

{

$SYM{RETURN_VALUE} = Spectra::gmup( "mot2");

}

elsif( $method eq "get_limit_min")

{

$SYM{RETURN_VALUE} = Spectra::gmuli( "mot2");

}

elsif( $method eq "get_limit_max")

{

$SYM{RETURN_VALUE} = Spectra::gmula( "mot2");

Page 128: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

}

elsif( $method eq "exec_stop")

{

Spectra::stop_move( "mot2");

}

elsif( $method eq "calibration")

{

$status = Spectra::calibrate( name => "mot2",

unit => $value_new,

noconfirm => 1);

}

else

{

Spectra::error( "vm1: failed to identify $method");

$status = 0;

goto finish;

}

finish:

$status;

Note that the calibrate command is executed with the noconfirm attribute. This is because Online prompts the user

for confirmation before it calls the script.

10.11.3 Two Motors uniformly

Here is a script that moves 2 motors uniformly. The distance between the motors is kept fixed. When using this script,

think about the unit limits.

#!/usr/bin/perl -w

#

# file name: /online_dir/vm1.pl

#

# This script is a template for a virtual motor.

#

use Spectra;

my ($method, $value_new) = @ARGV;

my $status = 1;

if( "$method" eq "set_position")

{

my $m1 = Spectra::gmup( "mot1");

my $m2 = Spectra::gmup( "mot2");

my $current = ($m1 + $m2)/2.;

my $diff = $value_new - $current;

$status = move( mot1 => ($m1 + $diff),

mot2 => ($m2 + $diff));

}

elsif( "$method" eq "get_position")

{

$SYM{RETURN_VALUE} = (Spectra::gmup( "mot1") + Spectra::gmup("mot2"))/2.;

}

elsif( "$method" eq "get_limit_min")

{

$SYM{RETURN_VALUE} = Spectra::gmuli( "mot1");

}

elsif( "$method" eq "get_limit_max")

{

$SYM{RETURN_VALUE} = Spectra::gmula( "mot1");

}

Page 129: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

elsif( "$method" eq "calibration")

{

;

}

elsif( $method eq "exec_stop")

{

Spectra::stop_move("mot1");

Spectra::stop_move("mot2");

}

else

{

Spectra::error( "vm1: failed to identify $method");

$status = 0;

goto finish;

}

finish:

$status;

10.11.4 Centralized VMs

Suppose that there are several PCs at a beamline and a particular virtual motor macro is used at each of these PCs.

Instead of copying the virtual motor macro to the each /online dir, it is preferable to maintain the macro at a central

place on a network file system and let the local virtual motor macros invoke the central script.

This is a solution. Each /online dir contains the script vm1.pl:

#!/usr/bin/perl -w

#

# file name: /online_dir/vm1.pl

#

$status = eval ‘cat /centralPlace/vm1_central.pl‘;

And on /centralPlace we have the script vm1 central.pl which happens to be exactly the former vm1.pl:

#!/usr/bin/perl -w

#

# file name: /online_dir/vm1.pl

#

# This script is a template for a virtual motor.

#

my ($method, $value_new) = @ARGV;

Util::log( "this is vm1_central, $method $value_new");

my $status = 1;

if( $method eq "set_position")

{

$status = Spectra::move( exp_mot15 => $value_new);

}

elsif( $method eq "get_position")

{

$SYM{RETURN_VALUE} = Spectra::gmup( "exp_mot15");

}

elsif( $method eq "get_limit_min")

{

$SYM{RETURN_VALUE} = Spectra::gmuli( "exp_mot15");

}

elsif( $method eq "get_limit_max")

{

$SYM{RETURN_VALUE} = Spectra::gmula( "exp_mot15");

Page 130: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

}

elsif( $method eq "exec_stop")

{

Spectra::stop_move( "exp_mot15");

}

elsif( $method eq "calibration")

{

$status = Spectra::calibrate( name => "exp_mot15",

unit => $value_new,

noconfirm => 1);

}

else

{

Spectra::error( "vm1: failed to identify $method");

$status = 0;

goto finish;

}

finish:

$status;

10.11.5 FMB-DCM: ExitOffset, Tango

The following virtual motor changes the ExitOffset parameter of FMB Oxford monochromators using the following

procedure: the current energy is read and stored in symbol $posOld, the ExitOffset is changed to the requested value

and finally the energy is moved to $posOld. The Bragg axis stays at their position, the translations are moved.

#!/usr/bin/perl -w

#

# file name: /online_dir/vm35.pl

#

my ($method, $value_new) = @ARGV;

my ( $min, $max) = ( 15, 23);

my $status = 1;

if( $method eq "set_position")

{

if( $value_new < $min ||

$value_new > $max)

{

$status = Spectra::error( "vm35: requested position $value_new outside limits $min, $max");

goto finish;

}

$posOld = Spectra::tng_attrDoubleRd( "fmbenergy", "Position");

$ret = Spectra::tng_attrDoubleWrt( "fmbenergy", "ExitOffset", $value_new);

$ret = Spectra::tng_attrDoubleWrt( "fmbenergy", "Position", $posOld);

my $startTime = Spectra::Secnds();

while( Spectra::tng_state( "fmbenergy") == 6)

{

Spectra::wait( 0.1);

#

# refresh the motor positions and sense ’Stop’ clicks

#

Util::refresh();

if( (Spectra::secnds() - $startTime) > 5)

{

$status = Spectra::error( "vm35: move didn’t finish within 5s");

goto finish;

}

}

Page 131: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

}

elsif( $method eq "get_position")

{

$SYM{RETURN_VALUE} = Spectra::tng_attrDoubleRd( "fmbenergy", "ExitOffset");

}

elsif( $method eq "get_limit_min")

{

$SYM{RETURN_VALUE} = $min;

}

elsif( $method eq "get_limit_max")

{

$SYM{RETURN_VALUE} = $max;

}

elsif( $method eq "exec_stop")

{

Spectra::tng_inout( "fmbenergy", "StopMove");

}

else

{

Spectra::error( "vm1: failed to identify $method");

$status = 0;

goto finish;

}

finish:

$status;

10.11.6 FMB-DCM: DCM Z (Jack)

The following virutal motor moves 3 motors in parallel. The position and the limits of the virtual motor is taken from

one of the motors.

#!/usr/bin/perl -w

#

# file name: /online_dir/vm1.pl

#

# DCM_Z

#

my ($method, $value_new) = @ARGV;

my $status = 1;

if( $method eq "set_position")

{

$status = Spectra::move( oh1_mot03 => $value_new,

oh1_mot04 => $value_new,

oh1_mot07 => $value_new);

}

elsif( $method eq "get_position")

{

$SYM{RETURN_VALUE} = Spectra::gmup( "oh1_mot03");

}

elsif( $method eq "get_limit_min")

{

$SYM{RETURN_VALUE} = Spectra::gmuli( "oh1_mot03");

}

elsif( $method eq "get_limit_max")

{

$SYM{RETURN_VALUE} = Spectra::gmula( "oh1_mot03");

}

elsif( $method eq "exec_stop")

{

Page 132: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Spectra::stop_move( "oh1_mot03");

Spectra::stop_move( "oh1_mot04");

Spectra::stop_move( "oh1_mot07");

}

else

{

Spectra::error( "vm1: failed to identify $method");

$status = 0;

goto finish;

}

finish:

$status;

10.11.7 Undulator Gap, Tango

#!/usr/bin/perl -w

#

my ($method, $value_new) = @ARGV;

my $status = 1;

if( $method eq "set_position")

{

$status = Spectra::tng_attrFloatWrt( "Undulator", "Gap", $value_new);

#

# the undulator needs some time to start

#

sleep(2);

my $startTime = Spectra::Secnds();

while( Spectra::tng_state( "Undulator") == 6)

{

Spectra::wait( 0.1);

#

# refresh the motor positions and sense ’Stop’ clicks

#

Util::refresh();

if( (Spectra::secnds() - $startTime) > 20)

{

$status = Spectra::error( "vm1: move didn’t finish within 20s");

goto finish;

}

}

}

elsif( $method eq "get_position")

{

$SYM{RETURN_VALUE} = Spectra::tng_attrFloatRd( "Undulator", "Gap");

}

elsif( $method eq "get_limit_min")

{

$SYM{RETURN_VALUE} = 11.1;

}

elsif( $method eq "get_limit_max")

{

$SYM{RETURN_VALUE} = 220.

}

elsif( $method eq "exec_stop")

{

$status = Spectra::tng_inout( "Undulator", "StopMove");

}

Page 133: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

finish:

$status;

10.11.8 Mirror height

This section shows a virtual motor that controls the height of a mirror. Two motors are involved, mirr y 1 and

mirr y 2. A second virtual motor, see the next section, uses these motors to rotate the mirror.

Before the virtual motor can be used, the following command has to be entered: ONLINE> def vm1.

#!/usr/bin/perl -w

#

# this script moves the height of a mirror

#

my ($method, $value_new) = @ARGV;

#

# the motor names

#

my ( $m1, $m2) = ( "mirr_y_1", "mirr_y_2");

my $status = 0;

if( !Spectra::search_motor( $m1))

{

Spectra::error( "vm1: missing $m1");

goto finish;

}

if( !Spectra::search_motor( $m2))

{

Spectra::error( "vm1: missing $m2");

goto finish;

}

#

# read the positions

#

my $p1 = Spectra::gmup( $m1);

my $p2 = Spectra::gmup( $m2);

goto finish if( !defined( $p1) || !defined( $p2));

if( $method eq "set_position")

{

#

# the mirror motors should be moved from the VM scripts only,

# that’s why they are protected

#

goto finish if( !Spectra::privilege( flag => 1));

goto finish if( !Spectra::protect( $m1 => 0, $m2 => 0));

my $delta = $value_new - ($p1 + $p2)*0.5;

$status = Spectra::move( $m1 => ($p1 + $delta),

$m2 => ($p2 + $delta));

goto finish if( !Spectra::protect( $m1 => 1, $m2 => 1));

}

elsif( $method eq "get_position")

{

$SYM{RETURN_VALUE} = ($p1 + $p2)*0.5;

}

elsif( $method eq "get_limit_min")

{

$SYM{RETURN_VALUE} = (Spectra::gmuli( $m1) + Spectra::gmuli( $m2))*0.5;

}

elsif( $method eq "get_limit_max")

{

$SYM{RETURN_VALUE} = (Spectra::gmula( $m1) + Spectra::gmula( $m2))*0.5;

Page 134: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

}

elsif( $method eq "exec_stop")

{

Util::log( "method exec-stop");

}

else

{

Spectra::error( "vm1: failed to identify $method");

$status = 0;

goto finish;

}

$status = 1;

finish:

$status;

10.11.9 Mirror angle

This section shows a virtual motor that controls the angle of a mirror. Two motors are involved, mirr y 1 and mirr y 2.

A second virtual motor, see the preceeding section, uses these motors to change the height of the mirror.

Before the virtual motor can be used, the following command has to be entered: ONLINE> def vm1.

#!/usr/bin/perl -w

#

# this script moves the angle of a mirror. [mrad]

#

use POSIX;

my ($method, $value_new) = @ARGV;

my ( $min, $max) = ( -5, 5);

#

# here are the motor names

#

my ( $m1, $m2) = ( "mirr_y_1", "mirr_y_2");

my $status = 0;

if( !Spectra::search_motor( $m1))

{

Spectra::error( "vm1: missing $m1");

goto finish;

}

if( !Spectra::search_motor( $m2))

{

Spectra::error( "vm1: missing $m2");

goto finish;

}

my $len = $Spectra::SYM{ mirr_length};

if( !$len)

{

Spectra::error( "vm2: missing MIRR_LENGTH");

goto finish;

}

#

# read the positions

#

my $p1 = Spectra::gmup( $m1);

my $p2 = Spectra::gmup( $m2);

my $p = ($p1 + $p2)*0.5;

goto finish if( !defined( $p1) || !defined( $p2));

Page 135: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

if( $method eq "set_position")

{

if( $value_new < $min || $value_new > $max)

{

$status = Spectra::error( "vm2: end position $value_new outside limits [$min, $max]");

goto finish;

}

# # the mirror motors should be moved from the VM scripts only,

# that’s why they are protected

#

goto finish if( !Spectra::privilege( flag => 1));

goto finish if( !Spectra::protect( $m1 => 0, $m2 => 0));

my $delta = POSIX::tan( $value_new/1000.)*$len;

$status = Spectra::move( $m1 => ($p - $delta*0.5),

$m2 => ($p + $delta*0.5));

goto finish if( !Spectra::protect( $m1 => 1, $m2 => 1));

}

elsif( $method eq "get_position")

{

$SYM{RETURN_VALUE} = POSIX::atan( ($p2 - $p1)/$len) * 1000;

}

elsif( $method eq "get_limit_min")

{

$SYM{RETURN_VALUE} = $min;

}

elsif( $method eq "get_limit_max")

{

$SYM{RETURN_VALUE} = $max;

}

elsif( $method eq "exec_stop")

{

Util::log( "method exec-stop");

}

else

{

Spectra::error( "vm2: failed to identify $method");

$status = 0;

goto finish;

}

$status = 1;

finish:

$status;

10.11.10 HKL rotation (BW5)

The following VM has been coded for BW5. It can be used at other diffractometer beamlines as well.

Before the virtual motor can be used, the following command has to be entered: ONLINE> def vm1.

#!/bin/env perl -w

# file name: /online_dir/vm1.pl

#

# this script drives a diffractometer in a circle around a

# reflection in the h-k plane, 0 - 360, clockwise. The

# zero-degree position is in the direction of the h axis.

# 0 ( h + r, k, 0)

# 90 ( k, k - r, 0).

# 90 ( k - r, k, 0).

# 270 ( h, k + r, 0)

Page 136: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

#

use Spectra;

use POSIX;

my ($method, $value_new) = @ARGV;

my $deg2rad = 0.0174533;

my $rad2deg = 57.2958;

my $status = 1;

#

#

#

my $r = 0.2;

my ( $h0, $k0, $l0) = ( 2, 0, 0);

my $flag_0_to_360 = 1;

#

#

if( $method eq "set_position")

{

if( $flag_0_to_360)

{

if( $value_new < 0 || $value_new > 360)

{

$status = Spectra::error( "vm1: requested position not in [0., 360.]");

goto finish;

}

}

else

{

if( $value_new < -180 || $value_new > 180.)

{

$status = Spectra::error( "vm1: requested position not in [-180, 180]");

goto finish;

}

}

my $h_new = $h0 + $r*POSIX::cos( $value_new*$deg2rad);

my $k_new = $k0 - $r*POSIX::sin( $value_new*$deg2rad);

$status = Spectra::hkl( h => $h_new,

k => $k_new,

l => $l0);

goto finish;

}

if( $method eq "get_position")

{

my $x = Spectra::h() - $h0;

my $y = Spectra::k() - $k0;

$y = -$y; # clockwise

my $res = POSIX::atan2( $y, $x)*$rad2deg;

if( $flag_0_to_360)

{

$res = 360. + $res if( $res < 0);

}

$SYM{RETURN_VALUE} = $res;

goto finish;

}

if( $method eq "get_limit_min")

{

if( $flag_0_to_360)

{

$SYM{RETURN_VALUE} = 0;

Page 137: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

}

else

{

$SYM{RETURN_VALUE} = -180.;

}

goto finish;

}

if( $method eq "get_limit_max")

{

if( $flag_0_to_360)

{

$SYM{RETURN_VALUE} = 360.;

}

else

{

$SYM{RETURN_VALUE} = 180.;

}

goto finish;

}

if( $method eq "exec_stop")

{

Util::log( "method exec-stop");

}

finish:

$status;

10.11.11 Slit (haspp02ch1a)

The following VM has been coded for haspp02ch1a. This way, cx of a slit can be used as the outer loop motor of 2D

scans.

Before the virtual motor can be used, the following command has to be entered: ONLINE> def vm1.

#!/usr/bin/perl -w

#

# file name: /online_dir/vm1.pl

#

# This script is a template for a virtual motor.

#

my ($method, $value_new) = @ARGV;

my $cx = Motor->locate( name => "slit( slt3, cx)");

my $status = 1;

if( $method eq "set_position")

{

$status = $cx->set( position => $value_new);

}

elsif( $method eq "get_position")

{

$SYM{RETURN_VALUE} = $cx->get( "position")

}

elsif( $method eq "get_limit_min")

{

$SYM{RETURN_VALUE} = $cx->get( "unit_limit_min")

}

elsif( $method eq "get_limit_max")

{

$SYM{RETURN_VALUE} = $cx->get( "unit_limit_max")

}

Page 138: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

elsif( $method eq "exec_stop")

{

Util::log( "vm1: method exec-stop");

}

else

{

Spectra::error( "vm1: failed to identify $method");

$status = 0;

goto finish;

}

finish:

$status;

10.11.12 Temperature controller hasg3, TCU200

The following virtual motor operates a temperature controller via USB. This is the VM code:

#!/usr/bin/perl -w

#

# file name: /online_dir/vm1.pl

#

# This script is a template for a virtual motor.

#

my ($method, $value_new) = @ARGV;

my $status = 1;

if( $method eq "set_position")

{

Spectra::set_temp_tcu200( $value_new);

}

elsif( $method eq "get_position")

{

$SYM{RETURN_VALUE} = Spectra::get_temp_tcu200(1);

}

elsif( $method eq "get_limit_min")

{

$SYM{RETURN_VALUE} = 0.;

}

elsif( $method eq "get_limit_max")

{

$SYM{RETURN_VALUE} = 1000;

}

elsif( $method eq "exec_stop")

{

;

}

else

{

Spectra::error( "vm1: failed to identify $method");

$status = 0;

goto finish;

}

finish:

$status;

The functions that speak to the device are defined in /online dir/TkIrc.pl:

#

#

#

Page 139: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

package Spectra;

use strict;

use Fcntl;

use POSIX qw( :termios_h);

my $flag_tcu200_open = 0;

my $flag_tcu200_debug = 0;

sub open_tcu200

{

my $status = 1;

my $dev = "/dev/ttyUSB0";

#

# the configuration

#

#$ stty -F /dev/ttyUSB0 -a

# speed 9600 baud; rows 0; columns 0; line = 0;

# intr = ˆC; quit = ˆ\; erase = ˆ?; kill = ˆU; eof = ˆD; eol = <undef>; eol2 = <undef>; swtch

# susp = ˆZ; rprnt = ˆR; werase = ˆW; lnext = ˆV; flush = ˆO; min = 0; time = 0;

# parenb -parodd cs7 hupcl -cstopb cread clocal -crtscts

# -ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany

# -opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0

# -isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl

if( -e $dev)

{

system( "stty -F $dev 7fffe006:4:dad:0:3:1c:7f:15:4:0:0:0:11:13:1a:0:12:f:17:16:0:0:0:0:0

}

else

{

$dev = "/dev/ttyUSB1";

if( -e $dev)

{

system( "stty -F $dev 7fffe006:4:dad:0:3:1c:7f:15:4:0:0:0:11:13:1a:0:12:f:17:16:0:0:0:0:0

}

else

{

print " no USB device \n";

goto finish;

}

}

if( !sysopen(USB, $dev, O_RDWR))

{

if( !sysopen(USB, $dev, O_RDWR))

{

Spectra::error(" open_tcu200: failed to open USB0 and USB1 ");

$status = 0;

goto finish;

}

}

finish:

return $status;

}

sub recv_tcu200

{

my ( $tmo) = @_;

my $status = undef;

Page 140: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

my $flag_retry = 0;

if( !$flag_tcu200_open)

{

open_tcu200();

if( !$flag_tcu200_open)

{

Spectra::error( "Failed to open USB for Tcu200 controller");

goto finish;

}

}

retry:

my $rin = my $win = my $ein = "";

vec( $rin, fileno( USB), 1) = 1;

$ein = $rin | $win;

#

# do we have input?

#

my $nfd = select( $rin, $win, $ein, $tmo);

if( !$nfd)

{

Spectra::error( "TkIrc::recv_tcu200: time-out during select(), tmp $tmo");

$status = undef;

goto finish;

}

my $buffer = " " x 101;

sysread( USB, $buffer, 100, 0);

$buffer = substr( $buffer, 3);

$buffer = substr( $buffer, 0, length( $buffer) - 2);

if( length( $buffer) < 1)

{

if( !$flag_retry)

{

$flag_retry = 1;

if( $flag_tcu200_debug)

{

print "recv_tcu200: received empty answer, repeating recv()\n";

}

goto retry;

}

else

{

Spectra::error(" TkIRc.pl::recv_tcu200: received 2nd empty answer");

$status = undef;

goto finish;

}

}

$status = $buffer;

if( $flag_tcu200_debug)

{

print "recv_tcu200: <<< $status";

}

finish:

return $status;

Page 141: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

}

sub send_tcu200

{

my ($buffer_in) = @_;

my $status = 1;

if( !$flag_tcu200_open)

{

open_tcu200();

if( !$flag_tcu200_open)

{

Spectra::error( "Failed to open usb for Tcu200 controller");

$status = 0;

goto finish;

}

}

syswrite( USB, $buffer_in, length($buffer_in), 0);

if( $flag_tcu200_debug)

{

print "send_tcu200: >>> $buffer_in\n";

}

finish:

return $status;

}

sub set_temp_tcu200

{

my ( $setpoint) = @_;

my $status = 1;

my $part1 = "\0040011\002";

my $part2 = sprintf( "SL%.1f\003", $setpoint);

my @l = unpack("C*", $part2);

my $bcc = $l[0];

for( my $i = 1; $i < length( $part2); $i++)

{

$bcc = $bcc ˆ $l[$i];

}

my $buffer_out = $part1 . $part2 . chr($bcc) . "\r\n";

if( !send_tcu200( $buffer_out))

{

Spectra::error( "TkIrc::set_temp_tcu200: failed to seg ’temp’");

$status = 0;

goto finish;

}

select undef, undef, undef, 0.05;

if( $flag_tcu200_debug)

{

print "send_tcu200: <<< $setpoint\n";

}

finish:

Page 142: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

return $status;

}

sub get_temp_tcu200

{

my $status = 1;

my $buffer = "\0040011PV\005\r\n";

if( !send_tcu200( $buffer))

{

Spectra::error( "TkIrc::get_temp_tcu200: failed to get ’temp’");

$status = 0;

goto finish;

}

#

# 2 seconds time-out

#

select undef, undef, undef, 0.05;

my $buffer = recv_tcu200( 2);

if( !defined( $buffer))

{

$status = Spectra::error( "TkIRc::get_temp_tcu200: failed to receive temp");

goto finish;

}

#

# remove a leading ’V’ which comes when a new temperatur is sent

#

$buffer =˜ s/ˆV(.+)$/$1/;

finish:

return $buffer;

}

10.11.13 A solution for the 24 bits problem of the OMS-VME58, large moves, limits

The VME58 controllers of OMS store the motor positions in registers which are 24 bits wide. This may lead to

problems, if a motor has a large conversion factor. In this case 24 bits not sufficient to perform large movements. In

addition, the hard unit limits cannot be expressed in terms of 24 numbers as unit limits (soft limits). The following

virtual motor script provides a workaround to this problem. A motor is moved between 0.1 and 90 units (hard limits).

Before the virtual motor can be used, the following command has to be entered: ONLINE> def vm1.

#!/usr/bin/perl -w

#

# file name: /online_dir/vm1.pl

#

# mot16 is moved from 0.1 to 90, the hard limits

#

use Spectra;

my ($method, $value_new) = @ARGV;

my $buffer = " " x 100;

my ( $lim_min, $lim_max) = ( 0, 90);

my $status = 1;

if( $method eq "set_position")

{

#

# read the current soft limits

#

my $min = Spectra::gmuli( "mot16");

Page 143: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

my $max = Spectra::gmula( "mot16");

my $bl = Spectra::gmub( "mot16");

#

# if the requested position is outside the hard limits,

# return an error

#

if( $value_new < $lim_min ||

$value_new > $lim_max)

{

$status = Spectra::error( "vm1: mot16, move outside limits $value_new not in [$lim_min, $lim_max]");

goto finish;

}

#

# if the requested position is within the soft

# limits, execute the move

#

if( $value_new <= $max &&

$value_new >= $min)

{

$status = Spectra::move( mot16 => $value_new);

goto finish;

}

#

# move is outside the soft limits but within the

# hard limits, move in two steps

#

if( $value_new > $max)

{

Util::log( "vm1: mot16 to " . $max . ", first step");

$status = Spectra::move( mot16 => $max);

goto finish if( !$status);

Spectra::rmsr( mot16 => 0);

Util::log( "vm1: mot16 unit-limit-max to " . $lim_max);

Spectra::smula( mot16 => $lim_max);

Util::log( "vm1: mot16 to " . $value_new);

$status = Spectra::move( mot16 => $value_new);

goto finish;

}

if( $value_new < $min)

{

Util::log( "vm1: mot16 to " . ($min + $bl*2) . ", first step");

$status = Spectra::move( mot16 => ($min + $bl*2));

goto finish if( !$status);

Spectra::rmsr( mot16 => 0);

Util::log( "vm1: mot16 unit-limit-min to " . ($lim_min));

Spectra::smuli( mot16 => $lim_min);

Util::log( "vm1: mot16 to " . $value_new);

$status = Spectra::move( mot16 => $value_new);

goto finish;

}

goto finish;

}

if( $method eq "get_position")

{

$SYM{RETURN_VALUE} = Spectra::gmup( "mot16");

goto finish;

}

if( $method eq "get_limit_min")

Page 144: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

{

$SYM{RETURN_VALUE} = $lim_min;

goto finish;

}

if( $method eq "get_limit_max")

{

$SYM{RETURN_VALUE} = $lim_max;

goto finish;

}

if( $method eq "calibration")

{

goto finish;

}

finish:

$status;

10.12 Virtual counters

10.12.1 Pilatus, Single Shot, P03

The following virtual counter operates a Pilatus in single shot mode, i.e. if the VC is used during a scan, a single frame

is taken at each stop.

if( $method =˜ /reset/i)

{

Spectra::tng_attrLongWrt( "pilatus", "NbFrames", 1);

Spectra::pilatus_start( "pilatus",

$Spectra::SYM{ scan_name},

$Spectra::SYM{ sample_time},

$Spectra::SYM{ sindex},

".cbf");

return 1;

}

if( $method =˜ /read/i)

{

while( Spectra::tng_state( "pilatus"))

{

Util::log( "waiting for Pilatus ");

Spectra::wait( 0.5);

}

Util::log( "pilatus state " . Spectra::tng_state( "pilatus"));

return 1;

}

10.12.2 Pilatus, Multiple Frames, P03

The following virtual counter operates a Pilatus in multiple frame mode, i.e. if the VC is used during a scan, 100 frames

(can be edited) are taken at each stop.

# Label: 300k_carsten

#

# Pilatus as virual counter taking several images instead of a single one per

# point during a scan.

#

# here:

# exposure time given in online defines total exposure time for a single

Page 145: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

# pilatus sequence (including dead time(s)).

# variable ’numimages’ defines the numer of pilatus images to take per scan point

#

# history:

# version 0: A.R., oct 24, 2012

#

if( $method =˜ /reset/i)

{

##########################

# to be adjusted by user #

##########################

my $numimages=100;

my $mydeadtime=0.003;

my $pil_epo = $Spectra::SYM{ sample_time} / ($numimages) - $mydeadtime;

Spectra::tng_attrStringWrt( "pilatus", "FilePrefix", $Spectra::SYM{ scan_name});

Spectra::tng_attrLongWrt( "pilatus", "NbFrames", $numimages);

Spectra::tng_attrDoubleWrt( "pilatus", "ExposureTime", $pil_epo);

Spectra::tng_attrDoubleWrt( "pilatus", "ExposurePeriod", $pil_epo+$mydeadtime);

Spectra::tng_attrLongWrt( "pilatus", "FileStartNum", ($Spectra::SYM{ sindex}-1)*$numimages+1);

Spectra::tng_inout("pilatus", "StartStandardAcq");

return 1;

}

if( $method =˜ /read/i)

{

while( Spectra::pilatus_state( "pilatus"))

{

Util::log( "waiting for Pilatus ");

Spectra::wait( 0.1);

}

return 1;

}

10.12.3 Lima

# Label: Lima

# saving_mode has to be set to AUTO_FRAME

# saving_directory and saving_suffix have to be set to the desired values

# Possible saving_sufix values: .edf, .raw, .cbf

if( $method =˜ /reset/i)

{

Util::log( "VC: scan_name $Spectra::SYM{ scan_name}");

Spectra::tng_attrDoubleWrt( "lima", "acq_expo_time",

$Spectra::SYM{ sample_time});

Spectra::tng_attrStringWrt( "lima", "saving_prefix",

$Spectra::SYM{ scan_name});

Spectra::tng_inout("lima", "prepareAcq");

Spectra::tng_inout("lima", "startAcq");

return 1;

}

if( $method =˜ /read/i)

{

Page 146: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

while( !Spectra::tng_attrBoolRd("lima","ready_for_next_acq"))

{

Util::log( "VC: waiting for Lima");

Spectra::wait( 0.5);

if( $Spectra::SYM{ interrupt_scan})

{

Util::log( "VC: wait-for-lima aborted");

last;

}

}

Util::log( "Lima ready for next acq ");

return 1;

}

10.12.4 ADQ1600, P01, XFEL-WP76

This virtual counter uses a socket connection to communicate with an external server.

Here is the VC code:

if( $method =˜ /reset/i)

{

ADQ1600::reset_ADQ1600( $Spectra::SYM{ scan_name}, $Spectra::SYM{ sindex});

return 1;

}

if( $method =˜ /read/i)

{

return ADQ1600::read_ADQ1600();

}

The module ADQ1600 is defined in /online dir/TkIrc.pl:

#

# ADQ1600: WP76 (XFEL)

#

package ADQ1600;

use strict;

use IO::Socket::INET;

use IO::Select;

use Spectra;

our $node = "exflXXX.desy.de";

our $port = 23;

sub open_ADQ1600

{

my $status = 1;

$Util::res_h{ sock_ADQ1600} = IO::Socket::INET->new(PeerAddr => $node,

PeerPort => $port,

Proto => ’tcp’,

Type => SOCK_STREAM);

if( !$Util::res_h{ sock_ADQ1600})

{

$status = Spectra::error( "open_ADQ1600: failed to connect to $node port $port");

goto finish;

}

my $res = recv_ADQ1600();

print "open_ADQ1600: welcome msg, $res \n";

finish:

Page 147: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

return $status;

}

sub close_ADQ1600

{

my $status = 1;

send_ADQ1600( "exit");

close( $Util::res_h{ sock_ADQ1600});

delete $Util::res_h{ sock_ADQ1600};

finish:

return $status;

}

sub send_ADQ1600

{

my ( $argin) = @_;

my $status = 1;

if( !defined( $Util::res_h{ sock_ADQ1600}))

{

if( !open_ADQ1600())

{

$status = Spectra::error( "send_ADQ1600: open_ADQ1600 returned error");

goto finish;

}

}

$argin =˜ s/ˆ\s*(.*?)\s*$/$1/;

$argin .= "\015\012";

$status = $Util::res_h{ sock_ADQ1600}->send( $argin);

finish:

return $status;

}

sub recv_ADQ1600

{

my $argout;

my $status = 1;

if( !defined( $Util::res_h{ sock_ADQ1600}))

{

if( !open_ADQ1600())

{

$status = Spectra::error( "recv_ADQ1600: open_ADQ1600 returned error");

goto finish;

}

}

my $s = new IO::Select();

$s->add( $Util::resh_h{ sock_ADQ1600});

$argout = "";

my $buffer;

while( !length( $argout) || $s->can_read(0.1))

{

$Util::res_h{ sock_ADQ1600}->recv( $buffer, 100);

$argout .= $buffer;

$buffer = "";

}

$argout =˜ s/ˆ\s*(.*?)\s*$/$1/;

Page 148: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

return $argout;

}

sub read_ADQ1600

{

send_ADQ1600( "read");

my $res = recv_ADQ1600();

return $res;

}

sub read_ADQ1600_laser

{

send_ADQ1600( "read laser");

my $res = recv_ADQ1600();

return $res;

}

sub reset_ADQ1600

{

my ( $sname, $index, $st) = @_;

my $cmd = sprintf( "reset %s_%05d", $sname, $index);

send_ADQ1600( $cmd);

my $res = recv_ADQ1600();

my $ret = 0;

if( $res =˜ /done/i)

{

$ret = 1;

}

return $ret;

}

10.12.5 Keithley 6517a, Current Attribute, Tango

if( $method =˜ /reset/i)

{

return 1;

}

if( $method =˜ /read/i)

{

return Spectra::tng_attrDoubleRd( "k6517a", "Current");

}

10.12.6 Keithley 617, NON-Tango

if( $method =˜ /reset/i)

{

return 1;

}

if( $method =˜ /read/i)

{

my $ret = gpibWrite( 11, "F1X");

$ret = gpibRead( 11);

# some string manipulation

# $ret =˜ s/ˆ\s*(.*?)\s*$/$1/;

return $ret;

}

Page 149: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

10.12.7 Encoder raw position

The following virtual counter monitors the encoder raw position.

if( $method =˜ /reset/i)

{

return 1;

}

if( $method =˜ /read/i)

{

return Spectra::get_motor_encoder_raw( "exp_motXX");

}

10.12.8 Send an email, if a counter shows a signal

The following virtual counter reads physical counter and sends an email to a user, if the count rate is above some value.

Motor positions are included and the scan is interrupted:

if( $method =˜ /reset/i)

{

return 1;

}

if( $method =˜ /read/i)

{

my $counts = Rc("eh1a_c01");

if( $counts > 100)

{

my $p29 = Spectra::gmup( "oh1_mot29");

my $p25 = Spectra::gmup( "oh1_mot25");

system( " echo \"$counts counts at p29 $p29, p25 $p25 \" | mail -s c01 [email protected]");

$Spectra::SYM{ interrupt_scan} = 1;

return 1;

}

}

10.12.9 Lecroy DSO

The following piece of code shows how a DSO (digital sampling oscilloscope, LC584, LC424, etc.) is operated using

the virtual counter interface.

#

# A virtual counter is defined by a piece of Perl code that responds to

# the methods ’reset’ and ’read’. ’reset’ is called after the other

# counters have been resetted, ’read’ after the other counters have been read.

# In the following example a random number is returned, ’reset’ is not needed:

#

if( $method =˜ /reset/i)

{

return 1;

}

if( $method =˜ /read/i)

{

Spectra::cls();

#

# "12" - read channel 1 and 2, can be "1", "2", "12", "123", "all"

# 1024 - the number of data points

# 1 - sparsing factor

Page 150: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

# 0 - offset

#

Spectra::wf( "dso1", "12", 1024, 1, 0);

mkdir $SYM{ scan_name} if( ! -d $SYM{ scan_name});

my $dir = $ENV{ PWD};

chdir $SYM{ scan_name};

my $fname = "$SYM{ scan_name}_dso_s$SYM{ sindex}";

Spectra::gra_command( "set lc_dso_c1/com_5=\"Motor $SYM{scan_device} at $SYM{ position}\"");

Spectra::gra_command( "write/fio/y(lc_dso_c1)/y(lc_dso_c2) $fname");

chdir $dir;

}

10.13 Lissajou Figures

The following example produces Lissajou figures:

#!/usr/bin/perl

use Spectra;

use GQE;

$r_max = 10000;

($fx, $fy, $np, $par) = @ARGV;

$fx = $fx || 2;

$fy = $fy || 3;

$par = $par || (0.01*sqrt(sqrt($fx+$fy)));

$np = $np || 101;

Spectra::delete("*.*");

Spectra::set( "raise off");

Spectra::set( "cif off"); # change-input-focus to off

Spectra::cls();

print "\033[5;1f Usage:\n\n";

print " TScan.pl fx fy np par \n\n";

print " Examples: \n";

print " TScan.pl 4 5 \n";

print " TScan.pl 9 10 201\n";

print " TScan.pl 7 8 201 0.01 \n\n";

print " Press the space bar to terminate the loop \n";

$t1 = SCAN->create( name => t1,

start => -1,

stop => 1,

np => $np) or

die "Failed to create t1 ";

$t2 = SCAN->create( name => t2,

start => -1,

stop => 1,

np => $np) or

die "Failed to create t2 ";

Spectra::autoscale();

#($user, $system, $cuser, $csystem) = times;

$start = (times)[0];

$pi = Gra_decode_double( "4.*atan(1.)");

Page 151: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

$f1 = 2*$pi/($np-3);

for $r (0 .. $r_max )

{

for $i (0 .. ($np - 1))

{

$t1->{x}[$i] = cos($fx*($f1*$i+$r*$par));

$t1->{y}[$i] = sin($fy*($i*$f1 + 0*($r+0.5)*$par));

}

$t2->set( colour => ’white’);

$t1->set( colour => ’black’);

Spectra::display( over => 1);

for $i (0 .. ($np - 1))

{

$t2->{x}[$i] = cos($fx*($f1*$i+($r+0.5)*$par));

$t2->{y}[$i] = sin($fy*($i*$f1 + 0*($r+0.5)*$par));

}

$t2->set( colour => ’black’);

$t1->set( colour => ’white’);

Spectra::display( over => 1);

$let = Spectra::key();

last if( $let == 32);

}

$end = (times)[0];

printf "\n Time %.2f seconds \n", $end - $start;

Page 152: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Bibliography

[1] Larry Wall et al., Programming Perl, O’Reilly

Page 153: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Index

ARGV array, 9

DEV, 14

MAR, 14

%Hexapod, 52

%SYM, 14

%user h, 11

aem command, 55

amc, 18

ARRAY

Items, 70

bem command, 55

bmc, 18

BW5, 134

Calc, 79

Calibration, 16

CAMAC, 97

Canbus, 94

CCD, 54

CONST

Items, 72

Coordinate frame, 20

Devices, 14

diff asn(), 48

diff calc angles(), 50

diff chi(), 49

diff compute u(), 49

diff delta(), 49

diff gamma(), 49

diff get r0(), 49

diff get r1(), 49

diff gk1(), 50

diff gk2(), 50

diff gk3(), 50

diff gw1(), 50

diff gw2(), 50

diff gw3(), 50

diff h(), 48

diff hkl(), 50

diff k(), 48

diff l(), 48

diff mode(), 48

diff mu(), 49

diff omega(), 49

diff phi(), 49

diff psi(), 48

diff psirefx(), 48

diff psirefy(), 48

diff psirefz(), 48

diff set r0(), 49

diff set r1(), 49

diff two theta(), 49

Display

smart update, 81

Encoder, 60

Example

ARRAY, 70

cmcrd(), 97

cmcwd(), 97

CONST, 73

Counter, 47

Gpib, 94

Keithley 617, 94

Lissajou, 149

Low level Spectra interface, 99

MCA, 44

Motor movements, 16

Motor parameters, 16

Run adc(), 45

SCAN, create, 121

SCAN, create(), 120

SCAN, read, 125

Scans, hkl(), 118

Scans, reflection, 119

SDD7, 45

TAG, 84

TEXT, 85

Timer, 47

fio comment, 76

fio comments, 76

Function

activate, 28

adsRead, 93

adsReadDouble, 93

adsReadFloat, 93

adsWrite, 93

adsWriteDouble, 93

adsWriteFloat, 93

amove(), 19

append scan info file(), 35

autoscale, 28

awe(), 35

calibrate(), 57

cancel all moves(), 57

canRead, 94

canWrite, 94

ceil(), 29

check motor moving(), 57

check motor registers(), 57, 60

Page 154: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

check move(), 57

cleanup, 29

clear output register bit(), 63

close shutter(), 52

cls, 29

cmcci(), 97

cmcdc(), 97

cmcdz(), 97

cmcrd(), 97

cmcrdbcd(), 97

cmcrdbcdc(), 97

cmcsc(), 97

cmcsi(), 97

cmcwd(), 97

cmr(), 60

convert to relative steps(), 57

corb(), 63

create scan name(), 35

date(), 30

date and time(), 30

deactivate, 28

define(), 35

delete(), 30

device(), 36

device record(), 36

device type(), 36

display, 30

doris(), 36

doris is sync run(), 36

doris state(), 36

doris wait for sync run(), 36

doty(), 30

dump, 30

elcomat(), 36

elcomat ascii(), 36

encoder, 60

encoder(), 51

energy(), 55

erase mar(), 52

eval, 10

exp init, 33

exp init(), 99

flag(), 30

floor(), 29

get counters(), 36

get devices(), 37

get encoders(), 36

get first active scan(), 33

get free line(), 33

get free slot(), 33

get last error, 31

get mcas(), 36

get modules(), 37

get motor acceleration, 57

get motor base, 57

get motor conversion, 57

get motor conversion encoder, 60

get motor encoder raw, 60

get motor home position, 60

get motor limits status(), 57

get motor protection(), 57

get motor ramp steps(), 57

get motor ramp units(), 57

get motor settle time, 57

get motor slew, 57

get motor slew max, 57

get motor slew min, 57

get motor step backlash, 57

get motor step limit max, 57

get motor step limit min, 57

get motor step register controller(), 57

get motor step register internal(), 57

get motor unit backlash, 57

get motor unit limit max, 57

get motor unit limit min, 57

get motor unit position(), 57

get motor unit position encoder, 60

get motors(), 36

get move time(), 57

get timers(), 36

get vfcadcs(), 36

gpibRead, 94

gpibWrite, 94

gra command(), 8, 31, 99

gra decode float(), 99

gra decode int(), 99

gra decode text(), 99

gra init, 33

gra input, 33

gra input(), 99

key(), 31

keyw(), 31

lambda(), 55

linear regression(), 31

log(), 37

marccd abort(), 54

marccd close(), 54

marccd correct(), 54

marccd open(), 54

marccd readout(), 54

marccd readout bg(), 54

marccd readout mr(), 54

marccd send header(), 54

marccd start(), 54

marccd writefile(), 54

max(), 31

memory free(), 33

memory info(), 33

memstat(), 33

min(), 31

modbusClose(), 95

modbusOpen(), 95

modbusRead(), 95

modbusWrite(), 95

module name(), 38

mostab, 56

move(), 16, 57

mpa3(), 37

n device(), 36

noyes(), 33

Page 155: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

oms58(), 57

oms58 qa(), 57

open shutter(), 52

ortec972(), 38

parabolic regression(), 31

petra(), 37

petra is sync run(), 37

petra state(), 37

petra wait for sync run(), 37

pilatus singleShot(), 62

pilatus start(), 62

pilatus state(), 62

pilatus stop(), 62

plot(), 90

postscript, 31

print(), 31

privilege(), 38

protect(), 38

prtc(), 9, 99

read, 31

read line(), 32

reset motor step position(), 57

reset motor step register(), 57

restore, 30

roi(), 32

run, 32

scan mar(), 52

scan number(), 33

search device(), 38

search gqe(), 33

search motor(), 57

search scan(), 33

search symbol(), 33

secnds(), 32

set min move time(), 57

set motor acceleration, 57

set motor base, 57

set motor conversion, 57

set motor conversion encoder, 60

set motor home position, 60

set motor settle time, 57

set motor slew, 57

set motor slew max, 57

set motor slew min, 57

set motor step backlash, 57

set motor step limit max, 57

set motor step limit min, 57

set motor step register controller(), 57

set motor step register internal(), 57

set motor unit backlash, 57

set motor unit limit max, 57

set motor unit limit min, 57

setup absolute step move, 57

setup absolute unit move, 57

setup relative step move, 57

setup relative unit move, 57

sigbus(), 33

slit, 57

slit calibrate, 57

Spectra::was beamloss doris(), 39

Spectra::was beamloss petra(), 39

Spectra::was injection(), 39

ssa(), 32

start all moves, 57

status shutter(), 52

stop all moves, 57

symbol alias(), 32

time stamp nexus(), 30

TkITableBlank(), 38

TkITablePop(), 38

trainno(), 39

Util::display text(), 42

Util::info(), 43

version(), 32, 33

vhq205l(), 40

vhsc005n(), 41

vme reopen(), 92

vme sysreset(), 92

vmeRead(), 92

vmeWwrite(), 92

waveform(), 39

wavelength(), 55

yesno(), 33

function

attribute(), 28

book name(), 29

book slot(), 29

book subindex(), 29

GKS, 89

Items, 89

GQE, 8

Hexapod, 52

hooks, 18

Keithley 617, 94

LCX, 53

mapping mode, 45

MARCCD, 54

Marker, 14

MAXV, 60

MCA, 44

Methods, 69

Methods, ARRAY, 70

Methods, base class, 69

Methods, CONST, 72

Methods, SCAN, 74

Methods, TAG, 83

Methods, TEXT, 85

Methods, UB Matrix, 87

Modbus, 95

mostab, 56

Motors, 16

Calibration, 16

Moving, 16

Parameters, 16

Slits, 19

Virtual, 21

move commands, 18

Page 156: Perl-Spectrahasyweb.desy.de/services/computing/perl_spectra/perl_spectra.pdf · Contents 1 Spectra meets Perl 7 1.1 General remarks . . . . . . . . . . . . . . . . . . . . . .

Moves, 16

Single steps, 16

nexus add components, 61

nexus add devices, 61

nexus clear components, 61

nexus clear devices, 61

nexus show available components, 61

nexus show components, 61

nexus show devices, 61

OMS-MAXV, 60

PerkinElmer, 61

Photonic science camera, 115

PhotonicScience, 62, 63

Pilatus100k, 62

Postscript, 120

SCAN

data, 79

Items, 77

Scans, 23

Slits, 19

Ssa, 76

Stepping motors, 16

Symbols, 14

TAG

Items, 83

Tango, 64

is device(), 67

is tango(), 67

tng attrBoolRd(), 64

tng attrBoolWrt(), 64

tng attrDoubleArrRd(), 64

tng attrDoubleArrWrt(), 64

tng attrDoubleImageRd(), 64

tng attrDoubleRd(), 64

tng attrDoubleWrt(), 64

tng attrFloatArrRd(), 64

tng attrFloatArrWrt(), 64

tng attrFloatRd(), 64

tng attrFloatWrt(), 64

tng attrLongArrRd(), 64

tng attrLongArrWrt(), 64

tng attrLongRd(), 64

tng attrLongWrt(), 64

tng attrShortRd(), 64

tng attrShortWrt(), 64

tng attrStringArrRd(), 64

tng attrStringRd(), 64

tng attrStringWrt(), 64

tng attrULongRd(), 64

tng attrULongWrt(), 64

tng attrUShortRd(), 64

tng attrUShortWrt(), 64

tng getDevName(), 64

tng getReflection(), 66

tng hasAttr(), 64

tng hasCmd(), 66

tng inout(), 66

tng inoutDoubleArrVoid(), 66

tng inoutDoubleULong(), 66

tng inoutDoubleVoid(), 66

tng inoutLongArrVoid(), 66

tng inoutLongLong(), 66

tng inoutLongVoid(), 66

tng inoutShortVoid(), 66

tng inoutStringDouble(), 66

tng inoutStringString(), 66

tng inoutStringVoid(), 66

tng inoutULongULong(), 66

tng inoutUShortVoid(), 66

tng inoutVoidDouble(), 66

tng inoutVoidLong(), 66

tng inoutVoidShort(), 66

tng inoutVoidULong(), 66

tng inoutVoidUShort(), 66

tng isAlive(), 67

tng propRd(), 65

tng state(), 67

tng status(), 67

TEXT

Items, 85

Virtual motors, 21

VME, 92

XIA, 45

XMAP, 45