2 using System.Collections.Generic;
3 using System.Collections;
18 private strongnameLabview.VirtualInstrument
_VI;
28 public strongnameLabview.VirtualInstrument VI {
get {
return _VI; } }
29 public String FrontPanelTitle {
get {
return _frontPanelTitle; } }
51 exporter.SetControlValue(
"VI Path", fileName);
53 _frontPanelTitle = exporter.GetControlValue(
"Title").ToString();
54 exporter.SetControlValue(
"Title",
"");
68 public void getVIControls(strongnameLabview.VirtualInstrument exporter, String fileName, Boolean includeClusters)
72 String savefile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
"\\LVPanelControls.txt";
73 exportVIControls(exporter, fileName, savefile);
74 extractVIControls(savefile, includeClusters);
79 Helpers.ErrorLogger.LabViewError(
"GetControls", e.Message +
": " + fileName);
95 private static void exportVIControls(strongnameLabview.VirtualInstrument exporter, String fileName, String saveFile)
98 FileInfo fi =
new FileInfo(saveFile);
106 exporter.SetControlValue(
"VI Path", fileName);
107 exporter.SetControlValue(
"Output Path", saveFile);
128 FileInfo FI =
new FileInfo(fileName);
133 using (StreamReader sr =
new StreamReader(fileName))
136 bool FoundStart =
false;
140 String temp = sr.ReadLine();
142 if (temp.StartsWith(
"<CONTENT>", StringComparison.Ordinal))
148 }
while (sr.Peek() >= 0);
151 if (FoundStart ==
true)
160 myLine = sr.ReadLine();
161 myLine = myLine.Trim();
164 if (myLine.StartsWith(
"<PARTS>", StringComparison.Ordinal))
169 myLine = sr.ReadLine();
170 myLine = myLine.Trim();
171 }
while (!myLine.Contains(
"</PARTS>"));
174 if (myLine.Contains(
"<LF>"))
178 String myLine2 = sr.ReadLine();
179 myLine = myLine.Substring(0, myLine.IndexOf(
"<LF>", StringComparison.Ordinal)) + myLine2;
180 myLine = myLine.Trim();
187 if (myLine.StartsWith(
"<CONTROL ID"))
190 controlName = findControlName(myLine);
193 if (controlName != null)
196 controlType = findControlType(myLine);
199 if ((controlType ==
"Cluster"))
202 getClusterInfo(sr, controlName, null, includeClusters);
204 else if (controlType ==
"Radio Buttons")
210 addRadioButton(sr, controlName, null);
212 else if (controlType ==
"Ring")
214 addRing(sr, controlName, null);
216 else if (controlType ==
"Listbox")
218 addListbox(sr, controlName, null);
220 else if (controlType ==
"Numeric" || controlType ==
"Boolean"
221 || controlType ==
"String" || controlType ==
"Enum"
222 || controlType ==
"Array")
225 addSimpleControl(sr, controlName, controlType, null);
238 }
while (sr.Peek() >= 0);
267 if (line.Contains(
"type=\"String\""))
271 else if (line.Contains(
"type=\"Numeric\""))
275 else if (line.Contains(
"type=\"Boolean\""))
279 else if (line.Contains(
"type=\"Array\""))
283 else if (line.Contains(
"type=\"Cluster\""))
287 else if (line.Contains(
"type=\"Radio Buttons\""))
289 return "Radio Buttons";
291 else if (line.Contains(
"type=\"Enum\""))
295 else if (line.Contains(
"type=\"Ring\""))
299 else if (line.Contains(
"type=\"Listbox\""))
303 else if (line.Contains(
"type=\"Type Definition\""))
309 else if (line.Contains(
"type=\"Thermometer\""))
314 else if (line.Contains(
"type=\"Tank\""))
319 else if (line.Contains(
"type=\"Slide\""))
324 else if (line.Contains(
"type=\"Dial\""))
329 else if (line.Contains(
"type=\"Knob\""))
334 else if (line.Contains(
"type=\"Meter\""))
353 String[] tempString = line.Split(
'\"');
356 if (tempString.GetLength(0) == 5)
358 return tempString[3].ToString();
375 private void addSimpleControl(StreamReader sr, String name, String type, SerialisableList<int> clusterIndices)
381 if (type ==
"Numeric")
386 AddControlToDictionary(newControl);
388 else if (type ==
"String")
393 AddControlToDictionary(newControl);
395 else if (type ==
"Boolean")
400 AddControlToDictionary(newControl);
402 else if (type ==
"Enum")
407 AddControlToDictionary(newControl);
409 else if (type ==
"Array")
414 AddControlToDictionary(newControl);
422 myLine = sr.ReadLine();
423 myLine = myLine.Trim();
425 if (myLine.Contains(
"<CONTROL"))
429 else if (myLine.Contains(
"</CONTROL>"))
434 }
while (count != 0);
437 catch (System.ArgumentException)
447 throw new ArgumentException(e.Message);
459 private void addRing(StreamReader sr, String ringName, SerialisableList<int> clusterIndices)
465 String[] items = null;
469 myLine = sr.ReadLine();
470 myLine = myLine.Trim();
476 if (myLine.StartsWith(
"<PART ID=12 order=0 type=\"Ring Text\">", StringComparison.Ordinal))
479 String temp = myLine.Substring(myLine.IndexOf(
"<STRING>", StringComparison.Ordinal) + 8);
480 temp = temp.Remove(temp.IndexOf(
"</STRING></STRINGS>", StringComparison.Ordinal));
481 temp = temp.Replace(
"</STRING><STRING>",
"|");
483 items = temp.Split(
'|');
487 }
while (myLine.Contains(
"</CONTROL>") ==
false);
493 AddControlToDictionary(newControl);
498 throw new ArgumentException(e.Message);
512 private void addListbox(StreamReader sr, String boxName, SerialisableList<int> clusterIndices)
518 String[] items = null;
522 myLine = sr.ReadLine();
523 myLine = myLine.Trim();
529 if (myLine.StartsWith(
"<PRIV><ITEMS><STRING>", StringComparison.Ordinal))
532 String temp = myLine.Substring(myLine.IndexOf(
"<STRING>", StringComparison.Ordinal) + 8);
533 temp = temp.Remove(temp.IndexOf(
"</STRING></ITEMS></PRIV", StringComparison.Ordinal));
534 temp = temp.Replace(
"</STRING><STRING>",
"|");
536 items = temp.Split(
'|');
540 }
while (myLine.Contains(
"</CONTROL>") ==
false);
546 AddControlToDictionary(newControl);
551 throw new ArgumentException(e.Message);
563 if (!_controls.ContainsKey(newControl.Name))
565 _controls.Add(newControl.Name, newControl);
568 catch (Exception err)
584 private void addRadioButton(StreamReader sr, String radioName, SerialisableList<int> clusterIndices)
590 List<String> items =
new List<String>();
594 myLine = sr.ReadLine();
595 myLine = myLine.Trim();
598 if (myLine.StartsWith(
"<CONTROL ID", StringComparison.Ordinal))
601 items.Insert(0, findControlName(myLine));
604 }
while (myLine.Contains(
"</CONTENT>") ==
false);
610 AddControlToDictionary(newControl);
616 throw new ArgumentException(e.Message);
631 private void getClusterInfo(StreamReader sr, String clusterName, SerialisableList<int> clusterList, Boolean includeClusters)
639 int clusterCount = 0;
643 if (clusterList == null)
646 clusterList =
new SerialisableList<int>();
651 myLine = sr.ReadLine();
652 myLine = myLine.Trim();
658 if (myLine.StartsWith(
"<CONTROL ID", StringComparison.Ordinal))
661 controlName = findControlName(myLine);
664 controlType = findControlType(myLine);
667 if (controlType ==
"Cluster")
671 clusterList.Add(clusterCount);
674 getClusterInfo(sr, clusterName +
":" + controlName, clusterList, includeClusters);
677 clusterList.RemoveAt(clusterList.Count - 1);
679 else if (controlType ==
"Radio Buttons")
681 clusterList.Add(clusterCount);
685 addRadioButton(sr, clusterName +
":" + controlName, clusterList);
689 clusterList.RemoveAt(clusterList.Count - 1);
691 else if (controlType ==
"Ring")
694 clusterList.Add(clusterCount);
699 addRing(sr, clusterName +
":" + controlName, clusterList);
703 clusterList.RemoveAt(clusterList.Count - 1);
705 else if (controlType ==
"Numeric" || controlType ==
"Boolean"
706 || controlType ==
"String" || controlType ==
"Enum"
707 || controlType ==
"Array")
711 clusterList.Add(clusterCount);
716 addSimpleControl(sr, clusterName +
":" + controlName, controlType, clusterList);
720 clusterList.RemoveAt(clusterList.Count - 1);
729 }
while (myLine.Contains(
"</CONTENT>") ==
false);
735 throw new ArgumentException(e.Message);
748 List<String> listControls =
new List<String>();
750 foreach (String name
in keys)
752 listControls.Add(_controls[name].GetNameAndType());
760 throw new ArgumentException(e.Message);
766 if (name.EndsWith(
")"))
768 name = name.Substring(0, name.LastIndexOf(
'('));
771 return _controls[name.Trim()].GetControlType();
776 #region Get control value
793 return control.GetValue(ref _VI);
798 throw new ArgumentException(e.Message);
813 return _VI.GetControlValue(controlName);
818 throw new ArgumentException(e.Message);
834 Object[] vals = (Object[])_VI.GetControlValue(clusterName);
841 throw new ArgumentException(e.Message);
847 #region Set values on Panel
862 control.SetValue(ref _VI, value);
873 _VI.SetControlValue(controlName, value);
888 _VI.SetControlValue(clusterName, values);
894 throw new ArgumentException(e.Message);
906 internal String FindControlNameAndType(String partialName)
908 List<String> keys =
new List<string>();
909 keys.AddRange(_controls.Keys);
911 foreach (String key
in keys)
913 if (key == partialName)
915 return _controls[key].GetNameAndType();
Object[] getWholeCluster(string clusterName)
Method for grabbing a whole cluster directly from LabVIEW. No formatting or checking applied...
static String findControlName(String line)
Method for extracting the control name.
This class inherits from LVControl class and is specialised for String controls.
void getClusterInfo(StreamReader sr, String clusterName, SerialisableList< int > clusterList, Boolean includeClusters)
Method for getting the information from a cluster. A cluster is a container for other types of contro...
void setRawControlValue(String controlName, Object value)
Method for setting a control value via DCOM with no checks from SECI. The control does not have to be...
This class inherits from LVControl class and is specialised for Ring controls. A Ring is like an enum...
void AddControlToDictionary(Controls.LvControl newControl)
Method for adding controls to the control dictionary
Dictionary< String, Controls.LvControl > _controls
Dictionary for containing the VI's control information. The control's name is the key...
This class inherits from LVControl class and is specialised for Numeric controls. ...
A simple custom exception used for LabVIEW exceptions
void GetFrontPanelTitle(strongnameLabview.VirtualInstrument exporter, String fileName)
Gets the title of the front panel
This class inherits from LVControl class and is specialised for reading and writing to LabVIEW array ...
void setControlValue(String controlName, Object value)
Method for setting a control value. Only sets values for controls inside the dictionary. If the control is in a cluster the name of the control is of the form: "clustername:controlname".
void addRing(StreamReader sr, String ringName, SerialisableList< int > clusterIndices)
Method for adding a Ring control to the dictionary. A Ring is like an enum, but it does not have to r...
This class inherits from LVControl class and is specialised for Boolean controls. ...
void extractVIControls(String fileName, Boolean includeClusters)
Main method for extracting the control information from the XML file that was produced by the exportV...
String GetControlType(String name)
This class inherits from LVControl class and is specialised for Enum controls.
static void exportVIControls(strongnameLabview.VirtualInstrument exporter, String fileName, String saveFile)
Method for extracting the control information from the VI. Uses an intermediate VI for saving the inf...
void addSimpleControl(StreamReader sr, String name, String type, SerialisableList< int > clusterIndices)
Method for adding simple controls to the controls dictionary. Used for Numerics, Booleans, Strings, Enums and Arrays.
LabViewPanel(strongnameLabview.VirtualInstrument VI)
Constructor
String[] getControlValue(String controlName)
Method for retrieving a value from a control. Only returns values for controls inside the dictionary...
Object getRawControlValue(String controlName)
Method for return a control value straight from DCOM with no clean-up. The control does not have to b...
This class contains the reference to the LabVIEW VI and keeps a list of all the front panel controls...
strongnameLabview.VirtualInstrument _VI
The reference to the actual VI
A simple custom exception used for a LabVIEW control cannot be read
void getVIControls(strongnameLabview.VirtualInstrument exporter, String fileName, Boolean includeClusters)
The method that initialises the finding of the controls on the front panel. The controls are read fro...
void setWholeCluster(string clusterName, Object[] values)
Method for setting a whole cluster directly. No formatting or checking applied. Cluster are not store...
void addRadioButton(StreamReader sr, String radioName, SerialisableList< int > clusterIndices)
Method for adding a Radio Button control to the dictionary. Radio buttons only return the index of th...
void addListbox(StreamReader sr, String boxName, SerialisableList< int > clusterIndices)
Method for adding a Listbox control to the dictionary. A Listbox is like a enum; however the enum dat...
static String findControlType(String line)
Method for determining the control type and what it should be treated as.
List< String > getListOfControls()
Method for requesting a list of the controls on the front panel of this VI.
This class is the abstract base class of the objects used to store the VI control information...