Coverage for larch/epics/__init__.py: 61%

36 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2024-10-16 21:04 +0000

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 

14 

15def pv_fullname(name): 

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

17 

18 Parameters 

19 ---------- 

20 pvname: name of PV 

21 

22 Returns 

23 ------- 

24 string with full PV name 

25 

26 """ 

27 name = str(name) 

28 if '.' not in name: 

29 name = "%s.VAL" % name 

30 return name 

31 

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

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

34 

35 Parameters 

36 ---------- 

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

38 default: string value for default units 

39 

40 Returns 

41 ------- 

42 string with units 

43 

44 """ 

45 try: 

46 units = pv.units 

47 except: 

48 units = '' 

49 if units in (None, ''): 

50 units = default 

51 return units 

52 

53 

54 

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

56 "pyepics is not installed" 

57 return None 

58 

59caget = caput = cainfo = PV = nullfcn 

60__DOC__ = "pyepics is not installed" 

61epics_exports = {} 

62scan_exports = {} 

63 

64_larch_name = '_epics' 

65_larch_builtins = {'_epics': {}} 

66 

67 

68if HAS_PYEPICS: 

69 from .xrf_detectors import Epics_MultiXMAP, Epics_Xspress3 

70 from .xrfcontrol import EpicsXRFApp 

71 

72 caget = epics.caget 

73 caput = epics.caput 

74 cainfo = epics.cainfo 

75 PV = epics.get_pv 

76 __DOC__ = """ 

77Functions for Epics Channel Access, using pyepics interface. 

78For further details, consult the pyepics documentation 

79 

80 Functions 

81 ------------- 

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

83 get and return value for an Epics Process Variable 

84 with options to ensure return value is a string, 

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

86 a maximum time to wait for a value. 

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

88 put a value to an Epics Process Variable, optionally 

89 waiting to return until record is fully processed, 

90 with a timeout value. 

91 cainfo(pvname, print_out=True) 

92 print out information about Process Variable. with 

93 print_out = False, returns string of information. 

94 PV(pvname) 

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

96 and several other methods. 

97 pv_units(pvname) 

98 return units for PV 

99 pv_fullname(pvname) 

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

101""" 

102 

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

104 cainifo=cainfo, pv_units=pv_units, 

105 pv_fullname=pv_fullname)}