private void StartViApplication() { //Create VI object //this.viApp = labViewApp.GetVIReference(this.labViewFile, "", true, 0); this.viApp = labViewApp.GetVIReference(this.labViewFile); if (this.viApp == null) { Console.WriteLine("TresaPOC : An error occurred getting the VI reference. Make sure the VI path you entered is correct."); return; } //Create input parameter names object to pass to the VI /*object paramNames = new object[] * { * "Serial Port", //input Arduino serial port configuiration * "Digital Output Channel", //input Arduino digital pin * "LED Value", //input Arduino Switch ON/OFF Button * "Stop Button" //input Arduino Stop Button * }; * * //Create input parameter values to pass to the VI * object paramValues = new object[] * { * "COM3", //input Arduino serial port configuiration * 13, //input Arduino digital pin * 0, //input Arduino Switch ON/OFF Button * 0 //input Arduino Stop Button * }; * * // Call the VI with the "Call2" method. "Call2" is very similar to "Call" except "Call2" * // has a few more common input parameters. Both are like calling a subVI or a function call * // while the "Run" method is more like hitting the run button on a VI. Also, parameters * // are passed in and out by way of the first two parameters in the call method. * * //Call VI and provide input parameters * this.viApp.Call2(ref paramNames, ref paramValues, true, false, false, true);*/ this.viApp.FPWinOpen = true; this.viApp.SetControlValue("Serial Port", cbPorts.Text); this.viApp.SetControlValue("Digital Output Channel", nuDigitalInput.Value); this.viApp.SetControlValue("LED Value", 0); this.viApp.SetControlValue("Stop Button", 0); //Run the VI with default input values, you will see the values on the front panel update if it is open this.viApp.Run(true); }
public int StopVI(VirtualInstrument vi) { string controlName = "stop"; int status = 4; if (vi != null) { status = 1; object state = null; bool found = false; try { state = vi.GetControlValue(controlName); if (state != null) { status = 2; found = true; } else { Utilities.WriteLog(controlName + " control not found: null returned"); } } catch (Exception e) { Utilities.WriteLog(controlName + " control not found: Exception: " + e.Message); } if (found) { try { vi.SetControlValue(controlName, true); int count = 0; int maxCount = 1000; while (vi.ExecState == ExecStateEnum.eRunning && count < maxCount) { count++; Thread.Sleep(20); } if (count == maxCount) { // Timeout error status = 3; } vi.SetControlValue(controlName, false); if ((vi.ExecState != ExecStateEnum.eRunning) && (vi.ExecState != ExecStateEnum.eRunTopLevel)) { Utilities.WriteLog("stopping VI: " + vi.Name + " status=" + (int)GetVIStatus(vi)); status = 0; } } catch (Exception ex) { Utilities.WriteLog("Error: setControl " +controlName +": " + ex.Message); } } } return status; }
public int RunVI(VirtualInstrument vi) { int status = -1; if (vi != null) { vi.OpenFrontPanel(true, FPStateEnum.eVisible); vi.Run(true); status = (int)GetVIStatus(vi); } return status; }
public int ResetVI(VirtualInstrument vi) { int status = -1; if (vi != null) { vi.ReinitializeAllToDefault(); status = (int)GetVIStatus(vi); } return status; }
public int SetControlValue(VirtualInstrument vi,string name, object value) { int status = -1; if (vi != null) { object state = null; bool found = false; try { state = vi.GetControlValue(name); if (state != null) { status = 0; found = true; } } catch (Exception e) { Utilities.WriteLog(name + " control not found: " + e.Message); } if (found) { vi.SetControlValue(name, value); status = (int)GetVIStatus(vi); } } return status; }
public int SetControlValues(VirtualInstrument vi, string[] names, object[] values) { int status = -1; if (vi != null) { object state = null; bool found = false; if (names.Length > 0 && names.Length == values.Length) { for (int i = 0; i < names.Length; i++) { try { state = vi.GetControlValue(names[i]); if (state != null) { status = 0; found = true; } } catch (Exception e) { Logger.WriteLine(names[i] + " control not found: " + e.Message); } if (found) { vi.SetControlValue(names[i], values[i]); status = (int)GetVIStatus(vi); } } } } return status; }
public virtual string submitRemoteCommand(string actionStr, string valueStr, VirtualInstrument viRef) { return submitRemoteCommand(actionStr, valueStr, viServer, viRef); }
public VirtualInstrument GetSubVI(VirtualInstrument parent, string name) { VirtualInstrument subvi = null; // This call does not work it returns an array of strings //string[] subs = (string[])parent.Callees; //subvi. //foreach (string viName in subs) //{ // if (viName.CompareTo(name) == 0) // { // subvi = true; // break; // } //} return subvi; }
public virtual int SetLockState(VirtualInstrument vi, Boolean state) { if (state) { SubmitAction("lockvi", qualifiedName(vi)); } else { SubmitAction("unlockvi", qualifiedName(vi)); } return GetLockState(vi); }
public int GetLockState(VirtualInstrument vi) { bool cached = false; int status = -1; if (vi != null) { status = ( int) vi.GetLockState(out cached); } return status; }
public int GetFPState(VirtualInstrument vi) { int status = -1; if (vi != null) { FPStateEnum state = vi.FPState; status = (int)state; } return status; }
public int GetVIStatus(VirtualInstrument vi) { // Not loaded == -1 int status = -1; if (vi != null) { ExecStateEnum state = vi.ExecState; status = (int)state; } return status; }
public string qualifiedName(VirtualInstrument vi) { string qName = null; if (vi != null) { StringBuilder buf = new StringBuilder(); string libraryName = null; try { Library lib = vi.Library; Project proj = null; if (lib != null) { libraryName = lib.Name; proj = lib.Project; if (proj != null) { if ((proj.Name != null) && (proj.Name.Length > 0)) buf.Append(proj.Name + "/"); if ((proj.MyComputer != null) && (proj.MyComputer.Name != null) && (proj.MyComputer.Name.Length > 0)) buf.Append(proj.MyComputer.Name + "/"); } if ((libraryName != null) && libraryName.Length > 0) { buf.Append(libraryName + ":"); } } } catch (InvalidCastException ivcEx) { Utilities.WriteLog("Library error: " + ivcEx.Message); } buf.Append(vi.Name); qName = buf.ToString(); } return qName; }
public int StopVI(VirtualInstrument vi) { int status = -1; if (vi != null) { status = 0; object state = null; bool found = false; try { state = vi.GetControlValue("stop"); if (state != null) { status = 1; found = true; } else { Utilities.WriteLog("stop control not found: null returned"); } } catch (Exception e) { Exception stopEx = new Exception("Control NotFound: stop", e); Utilities.WriteLog("stop control not found: " + e.Message); throw stopEx; } if (found) { try { vi.SetControlValue("stop", true); Thread.Sleep(10); vi.SetControlValue("stop", false); Utilities.WriteLog("stopping VI: " + vi.Name + " status=" + (int)GetVIStatus(vi)); status = 2; } catch (Exception ex) { Exception setControl = new Exception("setControl: stop", ex); Utilities.WriteLog("Error: setControl stop: " + ex.Message); throw setControl; } } } return status; }
public int CloseVI(VirtualInstrument vi) { int status = -1; if (vi != null) { StopVI(vi); vi.Abort(); vi.CloseFrontPanel(); status = (int)GetVIStatus(vi); } return status; }
public bool HasSubVI(VirtualInstrument parent, string name) { bool subvi = false; // This call does not work it returns an array of strings string[] subs = (string[]) parent.Callees; foreach( string viName in subs){ if (viName.CompareTo(name) == 0) { subvi = true; break; } } return subvi; }
public int SetBounds(VirtualInstrument vi, int left, int top, int right, int bottom) { int status = -1; if (vi != null) { object[] bounds = new object[4]; bounds[0] = (object)left; bounds[1] = (object)top; bounds[2] = (object)right; bounds[3] = (object)bottom; vi.FPWinBounds = (object)bounds; status = 1; } return status; }
public int RemoveVI(VirtualInstrument vi) { int status = -1; if(vi != null) { string message = "Trying to remove " + vi.Name; //vi.SetLockState(LabVIEW.VILockStateEnum.eLockedNoPwdState,false,"",false); vi.Abort(); vi.CloseFrontPanel(); vi = null; } return status; }
public bool HasControl(VirtualInstrument vi, string name) { bool status = false; object value = null; try { value = vi.GetControlValue(name); status = true; } catch (Exception e) { Utilities.WriteLog(name + " control not found: " + e.Message); } return status; }
public virtual string submitRemoteCommand(string actionStr, string valueStr, _Application appRef, VirtualInstrument viRef) { /* * Initialize the variables and define the strings corresponding to * the VI connector labels. Note the strings are case sensitive **/ StringBuilder message = new StringBuilder(actionStr + ": "); if (valueStr != null) message.Append(" Data=" + valueStr); string dataStr = valueStr; VirtualInstrument actionVI = this.getRemoteCommandVI(); if (actionVI != null) { string[] connectors = new String[6]; object[] data = new object[6]; connectors[0] = "action"; connectors[1] = "data"; connectors[2] = "response"; connectors[3] = "errorOut"; connectors[4] = "appRef"; connectors[5] = "viRef"; //The wrapper function expects to be passed a object type by reference. //We pass the string array to the object type here object param1 = (object)connectors; //Define the variable that will pass the expression to be evaluated to //LabVIEW and typecast it to type object data[0] = (object)actionStr; if (dataStr == null) data[1] = (object)""; else data[1] = (object)dataStr; if (appRef != null) { data[4] = appRef; } if (viRef != null) { data[5] = viRef; } object param2 = (object)data; //Call the VI actionVI.Call(ref param1, ref param2); //Display the result //Data returned if (((object[])param2)[2] != null) message.Append(" response: " + ((object[])param2)[2].ToString()); //Error returned if (((object[])param2)[3] != null) message.Append(" Error: " + ((object[])param2)[3].ToString()); } else { message.Append(" ERROR: RemoteCommandMgr not found"); } Utilities.WriteLog(message.ToString()); return message.ToString(); }
public object GetControlValue(VirtualInstrument vi, string name) { object value = null; if (vi != null) { try { value = vi.GetControlValue(name); } catch (Exception e) { Utilities.WriteLog(name + " control not found: " + e.Message); throw new Exception(name + " control not found:", e); } } return value; }