SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
DAEMonitor.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using Seci.Definitions;
5 
6 namespace Seci.Standard
7 {
17  public static class DaeMonitor
18  {
19  private static String _filePath;
20 
21  internal static String FilePath { get { return _filePath; } }
22 
26  internal static void Initialise()
27  {
28  _filePath = Status.DaeMonitorVI;
29 
30  //Load VI
31  LabView.LabViewApp.LoadVI(_filePath, true);
32  LabView.LabViewApp.StartVI(_filePath);
33  //ShowVi();
34  }
35 
39  internal static void ShowVi()
40  {
41  LabView.LabViewApp.ShowVI(_filePath);
42  }
43 
47  internal static void HideVi()
48  {
49  LabView.LabViewApp.HideVI(_filePath);
50  }
51 
56  public static void WriteBlockList()
57  {
58  int nAlias = 0;
59  //See how many alias there are
60  for (int i = 0; i < Managers.BlockMgr.Blocks.Count; ++i)
61  {
62  if (!String.IsNullOrEmpty(Managers.BlockMgr.Blocks[i].Alias))
63  {
64  ++nAlias;
65  }
66  }
67 
68  String[,] values1 = new String[Managers.BlockMgr.Blocks.Count + nAlias, 15];
69 
70  int entryIndex = 0;
71 
72  for (int i = 0; i < Managers.BlockMgr.Blocks.Count; ++i)
73  {
74  createEntry(Managers.BlockMgr.Blocks[i], entryIndex, ref values1, false);
75  ++entryIndex;
76 
77  if (!String.IsNullOrEmpty(Managers.BlockMgr.Blocks[i].Alias))
78  {
79  createEntry(Managers.BlockMgr.Blocks[i], entryIndex, ref values1, true);
80  ++entryIndex;
81  }
82  }
83 
84  try
85  {
86  LabView.LabViewApp.SetRawValue(_filePath, "Parameter details", values1);
87  }
88  catch
89  {
90  }
91  }
92 
93  private static void createEntry(BlockInfo block, int i, ref String[,] array, Boolean isAlias)
94  {
95  if (!isAlias)
96  {
97  array[i, 0] = block.BlockName;
98  }
99  else
100  {
101  array[i, 0] = block.Alias;
102  }
103 
104  array[i, 1] = block.ParentVI;
105 
106  if (block.ReadControl.EndsWith(")"))
107  {
108  array[i, 2] = block.ReadControl.Substring(0, block.ReadControl.LastIndexOf(" ("));
109  }
110  else
111  {
112  array[i, 2] = block.ReadControl;
113  }
114 
115  if (block.WriteControl != null)
116  {
117  if (block.WriteControl.EndsWith(")"))
118  {
119  array[i, 3] = block.WriteControl.Substring(0, block.WriteControl.LastIndexOf(" ("));
120  }
121  else
122  {
123  array[i, 3] = block.WriteControl;
124  }
125  }
126  else
127  {
128  array[i, 3] = "none";
129  }
130 
131  if (block.GoButton != null)
132  {
133  if (block.GoButton.EndsWith(")"))
134  {
135  array[i, 4] = block.GoButton.Substring(0, block.GoButton.LastIndexOf(" ("));
136  }
137  else
138  {
139  array[i, 4] = block.GoButton;
140  }
141  }
142  else
143  {
144  array[i, 4] = "none";
145  }
146 
147  array[i, 5] = ""; //Display - not needed
148  array[i, 6] = ""; //Log - not needed
149  array[i, 7] = Convert.ToInt16(block.UnderRunControl).ToString();
150 
151  if (block.ReadType == ControlType.STRING || block.ReadType == ControlType.BOOLEAN)
152  {
153  array[i, 8] = block.RunControlValue;
154  array[i, 9] = "";
155  }
156  else
157  {
158  array[i, 8] = block.LowerLimit.ToString();
159  array[i, 9] = block.UpperLimit.ToString();
160  }
161 
162  array[i, 10] = ""; //Save - not needed?
163  if (isAlias)
164  {
165  array[i, 11] = block.BlockName;
166  }
167  //values1[i, 12] = Managers.BlockMgr.Blocks[i].NexusGroup;
168  array[i, 13] = block.BlockUnits;
169  array[i, 14] = block.WaitForControl;
170  }
171 
176  internal static void UpdateBlockValues()
177  {
178  String[,] values1 = new String[Managers.BlockMgr.Blocks.Count, 2];
179 
180  for (int i = 0; i < Managers.BlockMgr.Blocks.Count; ++i)
181  {
182  values1[i, 0] = Managers.BlockMgr.Blocks[i].BlockName;
183  values1[i, 1] = Managers.BlockMgr.Blocks[i].CurrentValue;
184  }
185 
186  try
187  {
188  LabView.LabViewApp.SetRawValue(_filePath, "Control values", values1);
189  }
190  catch
191  {
192  }
193  }
194 
196  {
197  public Boolean UnderRC;
198  public Double Low;
199  public Double High;
200  public String StringLimit;
201 
202  public ReadbackValues()
203  {
204  UnderRC = false;
205  Low = Double.NegativeInfinity;
206  High = Double.PositiveInfinity;
207  StringLimit = null;
208  }
209  }
210 
211  private static ReadbackValues extractInformation(Object[,] vals, int i, bool? isNumeric)
212  {
213  ReadbackValues rb = new ReadbackValues();
214 
215  rb.UnderRC = Convert.ToBoolean(Convert.ToInt16(vals[i, 7]));
216 
217  if (isNumeric == true)
218  {
219  Double low = Double.NegativeInfinity;
220  Double high = Double.PositiveInfinity;
221  if (Double.TryParse(vals[i, 8].ToString(), out low))
222  {
223  rb.Low = low;
224  }
225  else
226  {
227  //Is probably nonsense so revert back to default
228  rb.Low = Double.NegativeInfinity;
229  }
230 
231  if (Double.TryParse(vals[i, 9].ToString(), out high))
232  {
233  rb.High = high;
234  }
235  else
236  {
237  //Is probably nonsense so revert back to default
238  rb.High = Double.PositiveInfinity;
239  }
240  }
241  else if (isNumeric == false)
242  {
243  rb.StringLimit = vals[i, 8].ToString();
244  }
245  else
246  {
247  //For back compatibility - before the introduction of Read Types
248  Double low = Double.NegativeInfinity;
249  Double high = Double.PositiveInfinity;
250  if (Double.TryParse(vals[i, 8].ToString(), out low) && Double.TryParse(vals[i, 9].ToString(), out high))
251  {
252  //Numeric value
253  rb.Low = low;
254  rb.High = high;
255  }
256  else
257  {
258  rb.StringLimit = vals[i, 8].ToString();
259  }
260  }
261 
262  return rb;
263  }
264 
270  internal static void GetRunControlSettings()
271  {
272  //Get a reference
273  BlockDictionary blocks = Managers.BlockMgr.Blocks;
274  Object[,] vals = (Object[,])LabView.LabViewApp.GetRawValue(_filePath, "Parameter details");
275  bool? isNumeric = null;
276  Boolean updateTable = false;
277 
278  if (vals != null)
279  {
280  for (int i = 0; i < vals.GetLength(0); ++i)
281  {
282  if (blocks.Contains(vals[i, 0].ToString()))
283  {
284  BlockInfo block = blocks[vals[i, 0].ToString()];
285  bool blockChanged = false;
286  ReadbackValues rb = new ReadbackValues();
287 
288  if (block.ReadType == ControlType.NUMERIC)
289  {
290  isNumeric = true;
291  rb = extractInformation(vals, i, true);
292 
293  if (block.UnderRunControl != rb.UnderRC)
294  {
295  block.UnderRunControl = rb.UnderRC;
296  blockChanged = true;
297  }
298 
299  if (block.LowerLimit != rb.Low)
300  {
301  block.LowerLimit = rb.Low;
302  blockChanged = true;
303  }
304 
305  if (block.UpperLimit != rb.High)
306  {
307  block.UpperLimit = rb.High;
308  blockChanged = true;
309  }
310 
311  }
312  else if (block.ReadType == ControlType.STRING || block.ReadType == ControlType.BOOLEAN)
313  {
314  isNumeric = false;
315  rb = extractInformation(vals, i, false);
316 
317  if (block.UnderRunControl != rb.UnderRC)
318  {
319  block.UnderRunControl = rb.UnderRC;
320  blockChanged = true;
321  }
322 
323  if (block.RunControlValue != rb.StringLimit)
324  {
325  block.RunControlValue = rb.StringLimit;
326  blockChanged = true;
327  }
328  }
329  else
330  {
331  rb = extractInformation(vals, i, null);
332 
333  if (block.UnderRunControl != rb.UnderRC)
334  {
335  block.UnderRunControl = rb.UnderRC;
336  blockChanged = true;
337  }
338 
339  if (!String.IsNullOrEmpty(rb.StringLimit) && block.RunControlValue != rb.StringLimit)
340  {
341  block.RunControlValue = rb.StringLimit;
342  blockChanged = true;
343  }
344  else
345  {
346  if (block.LowerLimit != rb.Low || block.UpperLimit != rb.High)
347  {
348  block.LowerLimit = rb.Low;
349  block.UpperLimit = rb.High;
350  blockChanged = true;
351  }
352  }
353  }
354 
355  if (blockChanged)
356  {
357  updateTable = true;
358  }
359 
360  if (!String.IsNullOrEmpty(blocks[vals[i, 0].ToString()].Alias))
361  {
362  if (!blockChanged)
363  {
364  bool aliasChanged = false;
365  ++i;
366 
367  if (i < vals.GetLength(0))
368  {
369  ReadbackValues rba = extractInformation(vals, i, isNumeric);
370 
371  if (block.UnderRunControl != rba.UnderRC)
372  {
373  block.UnderRunControl = rba.UnderRC;
374  aliasChanged = true;
375  }
376 
377  if (isNumeric == true)
378  {
379  if (block.LowerLimit != rba.Low)
380  {
381  block.LowerLimit = rba.Low;
382  aliasChanged = true;
383  }
384 
385  if (block.UpperLimit != rba.High)
386  {
387  block.UpperLimit = rba.High;
388  aliasChanged = true;
389  }
390  }
391  else if (isNumeric == false)
392  {
393  if (block.RunControlValue != rba.StringLimit)
394  {
395  block.RunControlValue = rba.StringLimit;
396  aliasChanged = true;
397  }
398  }
399  else
400  {
401  if (!String.IsNullOrEmpty(rba.StringLimit) && block.RunControlValue != rba.StringLimit)
402  {
403  block.RunControlValue = rba.StringLimit;
404  aliasChanged = true;
405  }
406  else
407  {
408  if (block.LowerLimit != rba.Low || block.UpperLimit != rba.High)
409  {
410  block.LowerLimit = rba.Low;
411  block.UpperLimit = rba.High;
412  aliasChanged = true;
413  }
414  }
415  }
416 
417  if (aliasChanged)
418  {
419  //The alias has changed, so the block has to be updated to match
420  updateTable = true;
421  }
422 
423  }
424  }
425 
426  }
427  }
428  else
429  {
430  //Block has probably been deleted.
431  }
432  }
433 
434  if (updateTable)
435  {
436  //Had to disable this because it could create a race condition with Genie, if someone does this too quickly
437  //cset \control block1 lowlimit=5
438  //cset \control block1 highlimit=10
439 
440  //WriteBlockList();
441  }
442 
443  }
444 
445  }
446 
447  }
448 }
Boolean Contains(String blockName)
Wrapper for standard Dictionary &quot;Contains&quot; All keys are lowercase.
static void WriteBlockList()
Method for writing the relevant block settings to the VI. This is for Open GENIE&#39;s GetBlocks command...
Definition: DAEMonitor.cs:56
This class is used for storing the information for any blocks that are created and provides methods f...
Definition: BlockInfo.cs:18
static void createEntry(BlockInfo block, int i, ref String[,] array, Boolean isAlias)
Definition: DAEMonitor.cs:93
static ReadbackValues extractInformation(Object[,] vals, int i, bool?isNumeric)
Definition: DAEMonitor.cs:211
static String _filePath
Definition: DAEMonitor.cs:19
Specialised version of the Dictionary class which can be converted to XML. Also has some additional s...
This class is a wrapper for the DAE Monitor VI. The DAE Monitor VI is where SECI puts the block setti...
Definition: DAEMonitor.cs:17