SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
Bridge.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.Remoting
7 {
12  class Bridge
13  {
14  #region LabVIEW
15 
22  public static Object GetLabViewValue(String vi, String control)
23  {
24  try
25  {
26  return LabView.LabViewApp.GetRawValue(vi, control);
27  }
28  catch
29  {
30  return null;
31  }
32  }
33 
41  public static Boolean SetLabViewValue(String vi, String control, Object value)
42  {
43  try
44  {
45  return LabView.LabViewApp.SetRawValue(vi, control, value);
46  }
47  catch
48  {
49  return false;
50  }
51  }
52 
53  public static String[] GetVIsFullpath()
54  {
55  try
56  {
57  List<String> vis = LabView.LabViewApp.GetListOfAllVIs(true);
58  return vis.ToArray();
59  }
60  catch
61  {
62  return null;
63  }
64  }
65 
66  #endregion
67 
68  #region Blocks
69 
76  public static String GetBlockValue(String blockName)
77  {
78  try
79  {
80  return Managers.BlockMgr.GetBlockValue(blockName);
81  }
82  catch
83  {
84  return null;
85  }
86  }
87 
88  public static Object GetRawBlockValue(String blockName)
89  {
90  try
91  {
92  BlockInfo temp = Managers.BlockMgr.Blocks[blockName.ToLower()];
93  return GetLabViewValue(temp.ParentVI, temp.ReadControl);
94  }
95  catch
96  {
97  return null;
98  }
99  }
100 
107  public static Object GetRawSetpoint(String blockName)
108  {
109  try
110  {
111  BlockInfo temp = Managers.BlockMgr.Blocks[blockName.ToLower()];
112  return GetLabViewValue(temp.ParentVI, temp.WriteControl);
113  }
114  catch
115  {
116  return null;
117  }
118  }
119 
120  public static Boolean SetRawBlockValue(String blockName, object value)
121  {
122  try
123  {
124  BlockInfo temp = Managers.BlockMgr.Blocks[blockName.ToLower()];
125  SetLabViewValue(temp.ParentVI, temp.WriteControl, value);
126 
127  return true;
128  }
129  catch
130  {
131  return false;
132  }
133  }
134 
143  public static String[] GetAllBlockValues(Boolean visibleOnly, Boolean includeSetpoint, Boolean includeGroup, Boolean includeWaitState)
144  {
145  try
146  {
147  return Managers.BlockMgr.GetAllBlockValues(visibleOnly, includeSetpoint, includeGroup, includeWaitState).ToArray();
148  }
149  catch
150  {
151  return null;
152  }
153  }
154 
159  public static String[] GetBlockNames(Boolean includeHidden)
160  {
161 
162  return GetBlockNames(includeHidden, false);
163  }
164 
165 
170  public static String[] GetBlockNames(Boolean includeHidden, Boolean includeAliases)
171  {
172  try
173  {
174  String[] keys = Managers.BlockMgr.Blocks.GetKeys();
175  List<String> results = new List<string>();
176 
177  for (int i = 0; i < keys.GetLength(0); ++i)
178  {
179  var temp = Managers.BlockMgr.Blocks[keys[i]];
180  if (!includeHidden && !temp.Visible)
181  {
182  continue;
183  }
184 
185  results.Add(temp.BlockName);
186 
187  if (!String.IsNullOrEmpty(temp.Alias))
188  {
189  results.Add(temp.Alias);
190  }
191  }
192 
193  return results.ToArray();
194  }
195  catch
196  {
197  return null;
198  }
199  }
200 
205  public static String[,] GetBlockAliases()
206  {
207  try
208  {
209  String[] keys = Managers.BlockMgr.Blocks.GetKeys();
210  String[] aliases = Managers.BlockMgr.Blocks.GetAliases();
211 
212  String[,] results = new String[keys.GetLength(0), 2];
213 
214  for (int i = 0; i < keys.GetLength(0); ++i)
215  {
216  results[i, 0] = keys[i];
217  results[i, 1] = aliases[i];
218  }
219 
220  return results;
221  }
222  catch
223  {
224  return null;
225  }
226  }
227 
233  public static String[,] GetBlocks()
234  {
235  try
236  {
237  return Managers.BlockMgr.Blocks.GetLabVIEWInfo();
238  }
239  catch
240  {
241  return null;
242  }
243 
244  }
245 
254  public static Boolean SetBlockValue(String blockName, String value)
255  {
256  try
257  {
258  //First check that it is not already in motion
259  if (!checkForWaitFor(blockName))
260  {
261  BlockDictionary blocks = Managers.BlockMgr.Blocks;
262 
263  if (blocks.Count != 0)
264  {
265  if (blocks.Contains(blockName))
266  {
267  //Set value
268  BlockInfo temp = (BlockInfo)blocks[blockName];
269 
270  //Check block enabled
271  if (temp.BlockEnabled)
272  {
273  //Set value
274  if (LabView.LabViewApp.SetValue(temp.ParentVI, temp.WriteControl, value))
275  {
276 
277  //May need to press button
278  if (!String.IsNullOrEmpty(temp.GoButton))
279  {
280  LabView.LabViewApp.SetValue(temp.ParentVI, temp.GoButton, true);
281  }
282 
283  //Pause for a second
284  System.Threading.Thread.Sleep(1000);
285 
286  return true;
287  }
288  }
289  }
290  }
291  }
292  return false;
293  }
294  catch
295  {
296  return false;
297  }
298  }
299 
305  public static Boolean UnderRunControl(String blockName)
306  {
307  return Managers.BlockMgr.Blocks[blockName].UnderRunControl;
308  }
309 
317  public static Boolean CheckForWaitingState(String blockName)
318  {
319  try
320  {
321  return checkForWaitFor(blockName);
322  }
323  catch
324  {
325  return false;
326  }
327 
328  }
329 
335  private static Boolean checkForWaitFor(String blockName)
336  {
337  if (Managers.BlockMgr.Blocks.Contains(blockName))
338  {
339  if (!String.IsNullOrEmpty(Managers.BlockMgr.Blocks[blockName].WaitForControl))
340  {
341  return Convert.ToBoolean(LabView.LabViewApp.GetValue(Managers.BlockMgr.Blocks[blockName].ParentVI, Managers.BlockMgr.Blocks[blockName].WaitForControl));
342  }
343  }
344 
345  return false;
346  }
347 
353  public static String[,] GetNexusInfo()
354  {
355  try
356  {
357  //Get all blocks including any in a component
358  BlockDictionary blocks = Managers.BlockMgr.Blocks;
359 
360  String[,] results = new String[blocks.Count, 5];
361 
362  int count = 0;
363 
364  for (int i = 0; i < blocks.Count; ++i)
365  {
366  results[count, 0] = blocks[i].BlockName;
367  results[count, 1] = blocks[i].NexusName;
368  results[count, 2] = blocks[i].NexusGroup;
369  results[count, 3] = blocks[i].ParentVI;
370  results[count, 4] = blocks[i].ReadControl;
371  ++count;
372  }
373 
374  return results;
375  }
376  catch
377  {
378  return null;
379  }
380  }
381 
388  public static Boolean IsInRange(String blockName)
389  {
390  return !Managers.BlockMgr.Blocks[blockName].OutOfRange();
391  }
392 
393  public static void EnableBlocksLogging(Boolean enable)
394  {
395  Managers.BlockMgr.LogValuesEnabled = enable;
396  }
397 
398  public static Boolean BlocksLoggingStatus()
399  {
400  return Managers.BlockMgr.LogValuesEnabled;
401  }
402 
403  #endregion
404 
405  #region DAE
406 
411  public static Boolean BeginRun()
412  {
413  try
414  {
415  Standard.Dae.BeginRun();
416 
417  //Should we check that the run has begun?
418 
419  return true;
420  }
421  catch
422  {
423  return false;
424  }
425  }
426 
431  public static Boolean EndRun()
432  {
433  try
434  {
435  Standard.Dae.EndRun();
436 
437  //Should we check that this worked?
438 
439  return true;
440  }
441  catch
442  {
443  return false;
444  }
445  }
446 
447 
452  public static Boolean PauseRun()
453  {
454  try
455  {
456  Standard.Dae.PauseRun();
457 
458  //Should we check that this worked?
459 
460  return true;
461  }
462  catch
463  {
464  return false;
465  }
466  }
467 
468 
473  public static Boolean ResumeRun()
474  {
475  try
476  {
477  Standard.Dae.ResumeRun();
478 
479  //Should we check that this worked?
480 
481  return true;
482  }
483  catch
484  {
485  return false;
486  }
487  }
488 
489 
494  public static Boolean AbortRun()
495  {
496  try
497  {
498  Standard.Dae.AbortRun();
499 
500  //Should we check that this worked?
501 
502  return true;
503  }
504  catch
505  {
506  return false;
507  }
508  }
509 
510 
515  public static Boolean SaveRun()
516  {
517  try
518  {
519  Standard.Dae.SaveRun();
520 
521  //Should we check that this worked?
522 
523  return true;
524  }
525  catch
526  {
527  return false;
528  }
529  }
530 
531 
536  public static String GetRunStatus()
537  {
538  return Standard.Dae.RunStatus;
539  }
540 
545  public static String[] GetRunInfo()
546  {
547  return Standard.Dae.GetFormattedValues(true, Definitions.Status.IsMuonInstrument).ToArray();
548  }
549 
550  #endregion
551 
552  #region Configurations
553 
558  public static String GetCurrentConfig()
559  {
560  try
561  {
562  return Managers.ConfigurationMgr.ConfigName;
563  }
564  catch
565  {
566  return null;
567  }
568  }
569 
574  public static String[] GetListOfConfigs()
575  {
576  try
577  {
578  System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Status.ConfigDir);
579 
580  System.IO.FileInfo[] files = di.GetFiles("*.conf");
581 
582  String[] configs = new String[files.GetLength(0)];
583 
584  for (int i = 0; i < files.GetLength(0); ++i)
585  {
586  configs[i] = files[i].Name;
587  }
588 
589  return configs;
590  }
591  catch
592  {
593  return null;
594  }
595  }
596 
608  public static int ChangeConfig(String configName)
609  {
610  try
611  {
612  if (!String.IsNullOrEmpty(configName))
613  {
614  if (configName.EndsWith(".conf") || configName.EndsWith(".comp"))
615  {
616  return Managers.ConfigurationMgr.RemoteConfigurationChange(configName);
617  }
618  }
619 
620  return 1;
621  }
622  catch
623  {
624  return 2;
625  }
626  }
627 
628  public static Boolean IsBusy()
629  {
630  return Seci.Managers.SeciMgr.IsBusy;
631  }
632 
633  #endregion
634 
635  #region Misc
636 
640  public static void ClearGraphs()
641  {
642  Managers.SeciMgr.ClearGraphs();
643  }
644 
645  #endregion
646  }
647 }
static Object GetLabViewValue(String vi, String control)
Get value directly from LabVIEW with no checks or conversions.
Definition: Bridge.cs:22
Boolean Contains(String blockName)
Wrapper for standard Dictionary &quot;Contains&quot; All keys are lowercase.
static Boolean SaveRun()
Asks the DAE to save a run - does not check to see if the run actually saved.
Definition: Bridge.cs:515
static String[] GetBlockNames(Boolean includeHidden)
Get the names of all the blocks
Definition: Bridge.cs:159
static Boolean checkForWaitFor(String blockName)
Does the actual checking of the wait for indicator
Definition: Bridge.cs:335
static Boolean BlocksLoggingStatus()
Definition: Bridge.cs:398
static Object GetRawBlockValue(String blockName)
Definition: Bridge.cs:88
static void EnableBlocksLogging(Boolean enable)
Definition: Bridge.cs:393
static String[] GetListOfConfigs()
Get a list of the available configurations (does not currently include components).
Definition: Bridge.cs:574
This class is used for storing the information for any blocks that are created and provides methods f...
Definition: BlockInfo.cs:18
static String GetBlockValue(String blockName)
Get the current value of a block. The block can be in the configuration or any of the components...
Definition: Bridge.cs:76
static String GetRunStatus()
Get the current run status from the DAE.
Definition: Bridge.cs:536
static String[] GetBlockNames(Boolean includeHidden, Boolean includeAliases)
Get the names of all the blocks
Definition: Bridge.cs:170
static String[,] GetBlockAliases()
Get the aliases of all the blocks
Definition: Bridge.cs:205
This class is for accessing Seci from an external source. All the COM and Remoting calls go through t...
Definition: Bridge.cs:12
static Object GetRawSetpoint(String blockName)
Get the setpoint value for a block. The block can be in the configuration or any of the components...
Definition: Bridge.cs:107
static Boolean SetLabViewValue(String vi, String control, Object value)
Set value directly in LabVIEW with no checks or conversions.
Definition: Bridge.cs:41
static int ChangeConfig(String configName)
Request a change of configuration. May return true, but this does not mean the configuration will cha...
Definition: Bridge.cs:608
static String[,] GetBlocks()
Get all the block information necessary for a &quot;GetBlocks&quot; in Open GENIE Should not be used as CSET sh...
Definition: Bridge.cs:233
static Boolean SetBlockValue(String blockName, String value)
Set the setpoint value of a block. The block can be in the configuration or any of the components...
Definition: Bridge.cs:254
static Boolean UnderRunControl(String blockName)
Definition: Bridge.cs:305
static void ClearGraphs()
Requests that any graphs in the user interface are reset
Definition: Bridge.cs:640
static Boolean IsInRange(String blockName)
See if a block is currently within the run-control bounds. Note: returns true if it is not under run-...
Definition: Bridge.cs:388
static String GetCurrentConfig()
Get the name of the current configuration.
Definition: Bridge.cs:558
static Boolean EndRun()
Asks the DAE to end a run - does not check to see if the run actually ended.
Definition: Bridge.cs:431
static Boolean PauseRun()
Asks the DAE to pause a run - does not check to see if the run actually paused.
Definition: Bridge.cs:452
static String[] GetVIsFullpath()
Definition: Bridge.cs:53
static Boolean SetRawBlockValue(String blockName, object value)
Definition: Bridge.cs:120
static Boolean AbortRun()
Asks the DAE to abort a run - does not check to see if the run actually aborted.
Definition: Bridge.cs:494
static String[] GetRunInfo()
Get the current run information from the DAE.
Definition: Bridge.cs:545
Specialised version of the Dictionary class which can be converted to XML. Also has some additional s...
static Boolean ResumeRun()
Asks the DAE to resume a paused run - does not check to see if the run actually resumed.
Definition: Bridge.cs:473
static String[] GetAllBlockValues(Boolean visibleOnly, Boolean includeSetpoint, Boolean includeGroup, Boolean includeWaitState)
Get the current values of all the blocks, including any in the components.
Definition: Bridge.cs:143
static Boolean BeginRun()
Asks the DAE to begin a run - does not check to see if the run actually started.
Definition: Bridge.cs:411
static Boolean CheckForWaitingState(String blockName)
Check to see if a block &#39;wait for control&#39; is true - if so it means the current block value may be un...
Definition: Bridge.cs:317
static Boolean IsBusy()
Definition: Bridge.cs:628
static String[,] GetNexusInfo()
Gets the NeXus information for all the blocks, including those in any components. Currently...
Definition: Bridge.cs:353