2 using System.Collections.Generic;
3 using System.Collections;
6 using System.Diagnostics;
7 using System.Runtime.InteropServices;
8 using Seci.Definitions;
12 namespace Seci.LabView
25 private static strongnameLabview.Application
_LV;
30 private static Dictionary<String, LabViewPanel>
_VIs;
50 private static List<String> _VIsNotLoaded =
new List<String>();
53 public static List<String> VIsNotLoaded {
get {
return _VIsNotLoaded; } }
55 public static Boolean IsNull {
get {
return _LV == null; } }
57 #region Start/Stop LabVIEW
68 _VIs =
new Dictionary<string, LabViewPanel>();
69 _panelsSettings =
new SerialisableList<LabViewPanelInfo>();
77 _LV =
new strongnameLabview.Application();
80 _controlsExporter = _LV.GetVIReference(executionDir +
"\\Required VIs\\Controls_Exporter.vi",
"",
false, 0);
81 _titleExporter = _LV.GetVIReference(executionDir +
"\\Required VIs\\GetPanelName.vi",
"",
false, 0);
106 System.Diagnostics.Process[] procList;
108 procList = System.Diagnostics.Process.GetProcessesByName(
"LabView");
110 if (procList.GetLength(0) > 0)
116 System.Threading.Thread.Sleep(1000);
121 catch (Exception err)
123 Helpers.ErrorLogger.SeciError(
"stopLabView", err);
141 Boolean hidden =
false;
148 fi.IsReadOnly =
false;
150 StreamReader SR =
new StreamReader(fi.FullName);
154 while ((line = SR.ReadLine()) != null)
156 if (line.StartsWith(
"hideRootWindow", StringComparison.Ordinal) && !hidden)
158 text +=
"hideRootWindow=True" + Environment.NewLine;
161 else if (!line.StartsWith(
"toolPaletteLoc", StringComparison.Ordinal) && !line.StartsWith(
"menu.", StringComparison.Ordinal))
163 text += line + Environment.NewLine;
169 text +=
"hideRootWindow=True" + Environment.NewLine;
172 catch (Exception err)
175 Seci.Helpers.ErrorLogger.SeciError(
"ConfigureLabVIEW", err);
183 if (!String.IsNullOrEmpty(text))
185 StreamWriter SW =
new StreamWriter(fi.FullName);
191 catch (Exception err)
193 Seci.Helpers.ErrorLogger.SeciError(
"ConfigureLabVIEW", err);
207 String version = _LV.Version;
218 #region Load\Close and Start\Stop VI
226 public static Boolean
LoadVI(String fileName, Boolean includeClusters)
228 return loadVI(fileName, null, includeClusters);
239 return loadVI(panelInfo.
FilePath, panelInfo, includeClusters);
258 if (!_VIs.ContainsKey(filepath.ToLower()))
260 strongnameLabview.VirtualInstrument myVI;
261 myVI = _LV.GetVIReference(filepath,
"",
false, 0);
264 if (panelInfo != null)
266 _panelsSettings.Add(panelInfo);
269 _VIs.Add(filepath.ToLower(), newPanel);
271 GetControls(filepath, includeClusters);
273 getFrontPanelTitle(filepath);
298 _VIs[fileName.ToLower()].GetFrontPanelTitle(_titleExporter, fileName);
314 return _VIs[fileName.ToLower()].FrontPanelTitle;
323 getFrontPanelTitle(fileName);
336 public static Boolean
CloseVI(String fileName)
341 strongnameLabview.VirtualInstrument myVI;
342 myVI = _VIs[fileName.ToLower()].VI;
345 if (myVI.ExecState != strongnameLabview.ExecStateEnum.eIdle)
351 myVI.FPWinOpen =
true;
353 myVI.CloseFrontPanel();
355 _VIs.Remove(fileName.ToLower());
360 if (panel.
FilePath.ToLower() == fileName.ToLower())
362 _panelsSettings.Remove(panel);
384 return _VIs.ContainsKey(fileName.ToLower());
397 strongnameLabview.VirtualInstrument VI = _VIs[fileName.ToLower()].VI;
399 if (VI.ExecState == strongnameLabview.ExecStateEnum.eRunning || VI.ExecState == strongnameLabview.ExecStateEnum.eRunTopLevel)
420 public static Boolean
StartVI(String fileName)
425 strongnameLabview.VirtualInstrument VI = _VIs[fileName.ToLower()].VI;
427 if (VI.ExecState == strongnameLabview.ExecStateEnum.eIdle)
446 public static Boolean
StopVI(String fileName)
451 strongnameLabview.VirtualInstrument VI = _VIs[fileName.ToLower()].VI;
453 if (VI.ExecState == strongnameLabview.ExecStateEnum.eIdle || VI.ExecState == strongnameLabview.ExecStateEnum.eRunTopLevel)
486 FileInfo fi =
new FileInfo(
Status.
ExecutionDir +
"\\Required VIs\\getlibraryinfo.vi");
490 throw new FileNotFoundException(
"Could not find getlibraryinfo.vi!");
496 strongnameLabview.VirtualInstrument readerVI = _LV.GetVIReference(Status.ExecutionDir +
"\\Required VIs\\getlibraryinfo.vi",
"",
false, 0);
497 readerVI.SetControlValue(
"Library Name", fileName);
503 String temp = readerVI.GetControlValue(
"VI Names").ToString();
505 List<String> viDetails =
new List<string>();
506 viDetails.AddRange(temp.Split(
'\n'));
519 #region Displaying VIs
528 public static Boolean
ShowVI(String fileName)
533 strongnameLabview.VirtualInstrument VI = _VIs[fileName.ToLower()].VI;
534 VI.FPWinIsFrontMost =
true;
540 String name = VI.FPWinTitle;
541 int handle = Helpers.NativeMethods.FindWindow(null, name);
546 handle = Helpers.NativeMethods.FindWindow(null, name +
" Front Panel");
551 handle = Helpers.NativeMethods.FindWindow(null, name +
" Front Panel *");
557 Helpers.NativeMethods.SetForegroundWindow(handle);
560 catch (Exception err)
564 Helpers.ErrorLogger.SeciError(
"DisplayVI", err);
582 public static Boolean
HideVI(String fileName)
587 strongnameLabview.VirtualInstrument VI = _VIs[fileName.ToLower()].VI;
590 VI.FPWinOpen =
false;
593 catch (Exception err)
596 Helpers.ErrorLogger.LabViewError(
"hideVI", err.Message);
612 Dictionary<string, LabViewPanel>.KeyCollection keys = _VIs.Keys;
614 foreach (String fileName
in keys)
640 strongnameLabview.VirtualInstrument VI = _VIs[fileName.ToLower()].VI;
641 object[] obj = (Object[])VI.FPWinBounds;
644 int[] bounds =
new int[obj.GetLength(0)];
646 for (
int i = 0; i < obj.GetLength(0); ++i)
648 bounds[i] = Convert.ToInt32(obj[i]);
653 catch (Exception err)
657 Helpers.ErrorLogger.SeciError(
"getBounds", err);
679 strongnameLabview.VirtualInstrument VI = _VIs[fileName.ToLower()].VI;
681 Object[] oldBounds = (Object[])VI.FPWinBounds;
683 oldBounds[2] = Convert.ToInt16(oldBounds[2]) - Convert.ToInt16(oldBounds[0]) + bounds[0];
684 oldBounds[3] = Convert.ToInt16(oldBounds[3]) - Convert.ToInt16(oldBounds[1]) + bounds[1];
685 oldBounds[0] = bounds[0];
686 oldBounds[1] = bounds[1];
688 VI.FPWinBounds = oldBounds;
707 if (fileName != null)
709 strongnameLabview.VirtualInstrument VI = _VIs[fileName.ToLower()].VI;
710 VI.FPState = strongnameLabview.FPStateEnum.eFPMinimized;
720 if (fileName != null)
722 strongnameLabview.VirtualInstrument VI = _VIs[fileName.ToLower()].VI;
724 VI.FPState = strongnameLabview.FPStateEnum.eFPStandard;
735 if (fileName != null)
737 strongnameLabview.VirtualInstrument VI = _VIs[fileName.ToLower()].VI;
739 if (VI.FPState == strongnameLabview.FPStateEnum.eFPClosed || VI.FPState == strongnameLabview.FPStateEnum.eFPHidden)
756 if (fileName != null)
758 strongnameLabview.VirtualInstrument VI = _VIs[fileName.ToLower()].VI;
759 VI.FPTitleBarVisible = visible;
765 #region Get Front panel controls
774 public static Boolean
GetControls(String fileName, Boolean includeClusters)
779 _VIs[fileName.ToLower()].getVIControls(_controlsExporter, fileName, includeClusters);
801 return _VIs[fileName.ToLower()].getListOfControls();
812 return _VIs[fileName.ToLower()].GetControlType(control);
817 #region Get control value
827 public static String[]
GetValue(String fileName, String controlName)
833 if (controlName.LastIndexOf(
" (", StringComparison.Ordinal) != -1)
835 controlName = controlName.Substring(0, controlName.LastIndexOf(
" ("));
838 return _VIs[fileName.ToLower()].getControlValue(controlName);
858 public static Object
GetRawValue(String fileName, String controlName)
864 if (controlName.LastIndexOf(
" (", StringComparison.Ordinal) != -1)
866 controlName = controlName.Substring(0, controlName.LastIndexOf(
" (", StringComparison.Ordinal));
869 return _VIs[fileName.ToLower()].getRawControlValue(controlName);
888 public static Object[]
GetCluster(String fileName, String clusterName)
893 return _VIs[fileName.ToLower()].getWholeCluster(clusterName);
904 #region Set control value
913 public static Boolean
SetValue(String fileName, String controlName, Object value)
919 if (controlName.LastIndexOf(
" (") != -1)
921 controlName = controlName.Substring(0, controlName.LastIndexOf(
" ("));
924 _VIs[fileName.ToLower()].setControlValue(controlName, value);
946 public static Boolean
SetRawValue(String fileName, String controlName, Object value)
952 if (controlName.LastIndexOf(
" (", StringComparison.Ordinal) != -1)
954 controlName = controlName.Substring(0, controlName.LastIndexOf(
" (", StringComparison.Ordinal));
957 _VIs[fileName.ToLower()].setRawControlValue(controlName, value);
979 public static Boolean
SetCluster(String fileName, String clusterName, Object[] values)
984 _VIs[fileName.ToLower()].setWholeCluster(clusterName, values);
1001 internal static SerialisableList<LabViewPanelInfo> GetAllPanelsInfo()
1003 SerialisableList<LabViewPanelInfo> list = _panelsSettings.Clone() as SerialisableList<LabViewPanelInfo>;
1012 internal static void SetPanelsInfo(SerialisableList<LabViewPanelInfo> panels)
1014 _panelsSettings = panels;
1025 List<String> keys =
new List<string>();
1026 keys.AddRange(_VIs.Keys);
1028 foreach (String key
in keys)
1030 if (key.ToLower() == block.ParentVI.ToLower())
1033 block.ReadControl = _VIs[key].FindControlNameAndType(block.ReadControl);
1037 block.WriteControl = _VIs[key].FindControlNameAndType(block.WriteControl);
1042 block.GoButton = _VIs[key].FindControlNameAndType(block.GoButton);
1057 internal static List<String> GetListOfAllVIs(Boolean includeDefault)
1059 List<String> paths =
new List<string>();
1063 paths.AddRange(_VIs.Keys);
1067 foreach (LabViewPanelInfo panel
in _panelsSettings)
1069 paths.Add(panel.FilePath.ToLower());
1080 internal static void SetVisibilityToDefault(String fileName)
1082 if (_VIs.ContainsKey(fileName.ToLower()))
1084 foreach (LabViewPanelInfo panel
in _panelsSettings)
1086 if (panel.FilePath == fileName)
1088 if (panel.ShowPanel)
static Boolean StopVI(String fileName)
Stop the specified VI from running.
static SerialisableList< LabViewPanelInfo > _panelsSettings
List containing the settings for the panels. This is the information that is saved in the configurati...
This class contains the DCOM connection to the LabVIEW application and stores a reference to all the ...
static String LabViewIniFilePath
static Boolean SetValue(String fileName, String controlName, Object value)
Standard method for setting a control's value on the front panel.
This class is used for storing the information for any blocks that are created and provides methods f...
static int[] GetBounds(String fileName)
Method to get the bounds of a VI's front panel. It is messy bcause the application returns the values...
A simple custom exception used for LabVIEW exceptions
static strongnameLabview.VirtualInstrument _controlsExporter
A VI that is used to export the controls list of other VIs.
static Boolean HideAllVIs()
Method to hide all the VIs' front panels. Done via the LabVIEW application not Win32 API...
static Boolean SetCluster(String fileName, String clusterName, Object[] values)
Method for setting a cluster or array's value. A cluster is an untyped array, that may contain a rang...
static Boolean LoadVI(String fileName, Boolean includeClusters)
Method for loading a VI.
Class for holding the standard run-time settings for SECI. A large percentage of the information held...
static Boolean MoveFrontPanel(String fileName, int[] bounds)
Method to set the position of a VI's front panel. This does not change the width or height of the pan...
static Boolean ShowVI(String fileName)
Method for displaying a VI and bringing it to the front. The front panel can be made visible through ...
static Boolean GetControls(String fileName, Boolean includeClusters)
Method for getting a list of the controls on a VI's front panel. The list of controls are stored in t...
static Boolean CloseVI(String fileName)
Method for closing a VI. The VI cannot be closed if it is still running, so it has to be aborted firs...
static Boolean AreYouThere()
static Boolean SetRawValue(String fileName, String controlName, Object value)
Method for setting a raw value on a front panel's control. This method sends the value straight to th...
static void MinimiseVI(String fileName)
Method to minimise the front panel
static Boolean HideVI(String fileName)
Method to hide a VI's front panel. Done via the LabVIEW application not Win32 API.
static String ExecutionDir
static Dictionary< String, LabViewPanel > _VIs
Dictionary for storing the VIs as they are loaded - stored using their filepath as a key...
static Boolean StopLabView()
Method for stopping LabVIEW. The safest way to kill LabVIEW is to kill the process as this guarantees...
static void RestoreVI(String fileName)
Method to restore the front panel (i.e. no longer minimised)
static void UpdateFrontPanelTitle(String fileName)
Update the stored window title for the front panel of the VI
static String[] GetValue(String fileName, String controlName)
Standard Method for retrieving a value of a front panel's control. The control has to exist in the co...
static Object[] GetCluster(String fileName, String clusterName)
Method for retrieving the values of a cluster/array as one lump. A cluster is an untyped array...
static String GetControlTime(String fileName, String control)
This class contains the reference to the LabVIEW VI and keeps a list of all the front panel controls...
static Object GetRawValue(String fileName, String controlName)
Method for retrieving a raw value of a front panel's control. This method returns the control value e...
static Boolean IsVIHidden(String fileName)
Method to check whether a VI is hidden or not
static Boolean StartLabView(String executionDir)
Create an instance of LabVIEW, if one has not been started. Also starts the controls exporter VI...
static List< String > GetLLBInfo(String fileName)
Method for getting a list of VIs in a LabVIEW Library file (.llb). The is done via a National Instrum...
static void getFrontPanelTitle(String fileName)
Update the stored window title for a specific front panel
This class contains all the information about a LabVIEW VI that needs to be saved in the configuratio...
static void configureLabVIEW()
Method for editing the LabVIEW.ini file. This is set to do the following:
static strongnameLabview.VirtualInstrument _titleExporter
A VI that is used to get the title of the front panel.
static Boolean IsVIPresent(String fileName)
Method for checking whether a VI is present in the dictionary.
static Boolean StartVI(String fileName)
Start the specified VI running.
static bool loadVI(String filepath, LabViewPanelInfo panelInfo, Boolean includeClusters)
Main method for loading a VI. Uses the LabVIEW application command GetVIReference to load the VI The ...
static Boolean LoadVI(LabViewPanelInfo panelInfo, Boolean includeClusters)
Method for loading a VI.
static strongnameLabview.Application _LV
The LabVIEW application.
static List< String > GetListOfControls(String fileName)
Method for retrieving a list of a front panel's controls.
static void SetTitleBarVisibility(String fileName, Boolean visible)
Method to set the appearance of a VI's front panel. If set to false then the VI will be shown without...
static String GetFrontPanelTitle(String fileName)
Gets the current window title of the VI's front panel
static Boolean IsVIRunning(String fileName)
Method for checking whether a VI is a running state.