Coverage for /Users/Newville/Codes/xraylarch/larch/epics/__init__.py: 62%

40 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-11-09 10:08 -0600

1#!/usr/bin/env python 

2""" 

3Use Epics Channel Access 

4""" 

5 

6HAS_PYEPICS = False 

7 

8try: 

9 import epics 

10 HAS_PYEPICS = True 

11except ImportError: 

12 HAS_PYEPICS = False 

13 

14from . import larchscan 

15 

16def pv_fullname(name): 

17 """ make sure an Epics PV name ends with .VAL or .SOMETHING! 

18 

19 Parameters 

20 ---------- 

21 pvname: name of PV 

22 

23 Returns 

24 ------- 

25 string with full PV name 

26 

27 """ 

28 name = str(name) 

29 if '.' not in name: 

30 name = "%s.VAL" % name 

31 return name 

32 

33def pv_units(pv, default=''): 

34 """get units for pv object, with optional default value 

35 

36 Parameters 

37 ---------- 

38 pv: pv object (created by PV()) 

39 default: string value for default units 

40 

41 Returns 

42 ------- 

43 string with units 

44 

45 """ 

46 try: 

47 units = pv.units 

48 except: 

49 units = '' 

50 if units in (None, ''): 

51 units = default 

52 return units 

53 

54 

55 

56def nullfcn(*args, **kws): 

57 "pyepics is not installed" 

58 return None 

59 

60caget = caput = cainfo = PV = nullfcn 

61__DOC__ = "pyepics is not installed" 

62epics_exports = {} 

63scan_exports = {} 

64 

65_larch_name = '_epics' 

66_larch_builtins = {'_epics': {}} 

67 

68 

69if HAS_PYEPICS: 

70 from .xrf_detectors import Epics_MultiXMAP, Epics_Xspress3 

71 from .xrfcontrol import EpicsXRFApp 

72 

73 caget = epics.caget 

74 caput = epics.caput 

75 cainfo = epics.cainfo 

76 PV = epics.get_pv 

77 __DOC__ = """ 

78Functions for Epics Channel Access, using pyepics interface. 

79For further details, consult the pyepics documentation 

80 

81 Functions 

82 ------------- 

83 caget(pvname, as_string=False, count=None, timeout=None) 

84 get and return value for an Epics Process Variable 

85 with options to ensure return value is a string, 

86 to limit the count for array values, or to specify 

87 a maximum time to wait for a value. 

88 caput(pvname, value, wait=False, timeout=60) 

89 put a value to an Epics Process Variable, optionally 

90 waiting to return until record is fully processed, 

91 with a timeout value. 

92 cainfo(pvname, print_out=True) 

93 print out information about Process Variable. with 

94 print_out = False, returns string of information. 

95 PV(pvname) 

96 create a Process Variable object with get()/put() 

97 and several other methods. 

98 pv_units(pvname) 

99 return units for PV 

100 pv_fullname(pvname) 

101 return fullname (that is, including '.VAL' if needed) for PV 

102""" 

103 

104 _larch_builtins = {'_epics': dict(PV=PV, caget=caget, caput=caput, 

105 cainifo=cainfo, pv_units=pv_units, 

106 pv_fullname=pv_fullname)} 

107 

108 if larchscan.HAS_EPICSSCAN: 

109 _larch_builtins['_scan'] = dict(scan_from_db=larchscan.scan_from_db, 

110 connect_scandb=larchscan.connect_scandb, 

111 do_scan=larchscan.do_scan, 

112 do_slewscan=larchscan.do_scan, 

113 get_dbinfo=larchscan.get_dbinfo, 

114 set_dbinfo=larchscan.set_dbinfo)