[4] | 1 | function [S, IndexList] = family2status(Family, DeviceList) |
---|
| 2 | %FAMILY2STATUS - Returns the device status |
---|
| 3 | % If using family name, device list method, |
---|
| 4 | % S = family2status(Family, DeviceList) |
---|
| 5 | % |
---|
| 6 | % If using channel or tango name method, |
---|
| 7 | % S = family2status(ChannelNames) |
---|
| 8 | % S = family2status(TangoNames) |
---|
| 9 | % |
---|
| 10 | % If using common name method, |
---|
| 11 | % S = family2status(Family, CommonName) |
---|
| 12 | % |
---|
| 13 | % INPUTS |
---|
| 14 | % 1. Family = Family Name |
---|
| 15 | % Data Structure |
---|
| 16 | % Accelerator Object |
---|
| 17 | % Cell Array of Accelerator Objects or Family Names |
---|
| 18 | % For CommonNames, Family=[] searches all families |
---|
| 19 | % ChannelName = Channel access channel name |
---|
| 20 | % Matrix of channel names |
---|
| 21 | % Cell array of channel names |
---|
| 22 | % 2. DeviceList = [Sector Device #] or [element #] list (Cell Array of DeviceList) |
---|
| 23 | % {Default or empty list: whole family} |
---|
| 24 | % Note: The default list is different for this function then all other functions. |
---|
| 25 | % Usually the default is in service devices which would always be true if |
---|
| 26 | % that was the default for this function. |
---|
| 27 | % |
---|
| 28 | % OUTPUTS |
---|
| 29 | % 1. S = 1 - device is in service |
---|
| 30 | % 0 - device is out of service |
---|
| 31 | % Empty if Family or CommonName is found not found |
---|
| 32 | % 2. IndexList - Index vector relative to the device list where |
---|
| 33 | % the device is in service. |
---|
| 34 | |
---|
| 35 | % |
---|
| 36 | % Written by Gregory J. Portmann |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | if nargin == 0 |
---|
| 41 | error('At least one input required'); |
---|
| 42 | end |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | %%%%%%%%%%%%%%%%%%%%% |
---|
| 46 | % Cell Array Inputs % |
---|
| 47 | %%%%%%%%%%%%%%%%%%%%% |
---|
| 48 | if iscell(Family) |
---|
| 49 | for i = 1:length(Family) |
---|
| 50 | if nargin < 2 |
---|
| 51 | [S{i}, IndexList{i}] = family2status(Family{i}); |
---|
| 52 | else |
---|
| 53 | if iscell(DeviceList) |
---|
| 54 | [S{i}, IndexList{i}] = family2status(Family{i}, DeviceList{i}); |
---|
| 55 | else |
---|
| 56 | [S{i}, IndexList{i}] = family2status(Family{i}, DeviceList); |
---|
| 57 | end |
---|
| 58 | end |
---|
| 59 | end |
---|
| 60 | return |
---|
| 61 | end |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 65 | % Family or data structure inputs beyond this point % |
---|
| 66 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 67 | if isstruct(Family) |
---|
| 68 | % Data structure inputs |
---|
| 69 | if nargin < 2 |
---|
| 70 | if isfield(Family,'DeviceList') |
---|
| 71 | DeviceList = Family.DeviceList; |
---|
| 72 | else |
---|
| 73 | DeviceList = []; |
---|
| 74 | end |
---|
| 75 | end |
---|
| 76 | if isfield(Family,'FamilyName') |
---|
| 77 | Family = Family.FamilyName; |
---|
| 78 | else |
---|
| 79 | error('For data structure inputs FamilyName field must exist') |
---|
| 80 | end |
---|
| 81 | else |
---|
| 82 | % Family string input |
---|
| 83 | if nargin < 2 |
---|
| 84 | DeviceList = []; |
---|
| 85 | end |
---|
| 86 | end |
---|
| 87 | |
---|
| 88 | % Note: This is a different default than normal good status only |
---|
| 89 | if isfamily(Family) |
---|
| 90 | if isempty(DeviceList) |
---|
| 91 | DeviceList = family2dev(Family, 0); |
---|
| 92 | end |
---|
| 93 | if (size(DeviceList,2) == 1) |
---|
| 94 | DeviceList = elem2dev(Family, DeviceList); |
---|
| 95 | end |
---|
| 96 | end |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | %%%%%%%%%%%%%%%%%%%%%%% |
---|
| 100 | % Channel / TANGO name method % |
---|
| 101 | %%%%%%%%%%%%%%%%%%%%%%% |
---|
| 102 | if ~isfamily(Family(1,:)) |
---|
| 103 | % Try to convert to a family and device |
---|
| 104 | |
---|
| 105 | ChannelNames = Family; |
---|
| 106 | for i = 1:size(ChannelNames,1) |
---|
| 107 | Family = tango2family(ChannelNames(i,:)); |
---|
| 108 | % Family = channel2family(ChannelNames(i,:)); |
---|
| 109 | if isempty(Family) |
---|
| 110 | error('Tango name could not be converted to a Family.'); |
---|
| 111 | % error('Channel name could not be converted to a Family.'); |
---|
| 112 | end |
---|
| 113 | [FamilyIndex, ACCELERATOR_OBJECT] = isfamily(Family); |
---|
| 114 | DeviceList = tango2dev(ChannelNames(i,:), ACCELERATOR_OBJECT); |
---|
| 115 | % DeviceList = channel2dev(ChannelNames(i,:), ACCELERATOR_OBJECT); |
---|
| 116 | if isempty(DeviceList) | isempty(DeviceList) |
---|
| 117 | error('Tango name could not be converted to a Family and DeviceList.'); |
---|
| 118 | % error('Channel name could not be converted to a Family and DeviceList.'); |
---|
| 119 | end |
---|
| 120 | S(i,:) = family2status(Family, DeviceList); |
---|
| 121 | end |
---|
| 122 | return |
---|
| 123 | end |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 127 | % CommonName Input: Convert common names to a DeviceList % |
---|
| 128 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 129 | if isstr(DeviceList) |
---|
| 130 | DeviceList = common2dev(DeviceList, Family); |
---|
| 131 | if isempty(DeviceList) |
---|
| 132 | error('DeviceList was a string but common names could not be found.'); |
---|
| 133 | end |
---|
| 134 | end |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | %%%%%%%%%%%% |
---|
| 138 | % Get data % |
---|
| 139 | %%%%%%%%%%%% |
---|
| 140 | S = getfamilydata(Family, 'Status', DeviceList); |
---|
| 141 | S = S(:); |
---|
| 142 | if nargout >= 2 |
---|
| 143 | IndexList = find(S==1); |
---|
| 144 | end |
---|