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 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 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; }