The Sample program demonstrates the main functionality of the OTX-Runtime API. It can be used as a reference for the expected runtime behavior of the API and the source code below is like a reference guide about the proper programming of the API.
Code snippet of the OTX-Runtime API Sample Program.
11 using System.Collections.Generic;
12 using System.Diagnostics;
16 using System.Threading;
17 using System.Threading.Tasks;
18 using System.Windows.Forms;
19 using Microsoft.Win32;
21 namespace OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample
23 public partial class SampleForm : Form
25 private const int VALUE_STRING_MAX_LENGTH = 1024;
27 private UserSettings userSettings = UserSettings.Default;
30 private List<IRuntimeContext> runtimeContexts =
new List<IRuntimeContext>();
31 private Dictionary<IRuntimeContext, DateTime> runtimeContextsExecutionStartTime =
new Dictionary<IRuntimeContext, DateTime>();
33 private IProject project =
null;
34 private IPlayerProject playerProject =
null;
35 private IProcedure procedureToExecute =
null;
37 private TreeNode startupNode =
null;
39 private IRuntimeManager globalRuntimeManager =
null;
41 private HmiWindow hmiWindow;
43 private DateTime lastTime = DateTime.Now;
45 private DefaultCustomScreenImplementation customScreenImplementation;
46 private ContextVariableImplementation contextVariableImplementation;
48 private StateVariableImplementation stateVariableImplementation;
49 private DefaultMeasureImplementation measureImplementation;
50 private DefaultExternalServiceProviderImplementation serviceProviderImplementation;
52 private BasicScreenOutputImpl basicScreenOutputImpl;
53 private CustomScreenOutputImpl customScreenOutputImpl;
54 private LoggingOutputImpl loggingOutputImpl;
55 private ContextVariableOutputImpl contextVariableOutputImpl;
57 private StateVariableOutputImpl stateVariableOutputImpl;
58 private MeasureOutputImpl measureOutputImpl;
59 private I18nOutputImpl i18NOutputImpl;
60 private ExternalServiceProviderOutputImpl serviceProviderOutputImpl;
62 private SqlOutputImpl sqlOutputImpl;
63 private CommonDialogsOutputImpl commonDialogsOutputImpl;
65 private SampleForm creatorForm;
67 private string runtimeContextName;
68 private long procedureExecutionCount;
69 private long cyclicExecutionCount;
71 private static string fileVersion;
73 private static int defaultPollingTime = 500;
74 private static int defaultBatteryVoltageThreshold = 6000;
75 private bool useConnectionState =
false;
76 private bool? KL15State =
null;
79 private bool isLoadding =
false;
81 private ushort defaultDiagPort = SampleConstants.DEFAULT_DM_PORT;
82 private ushort defaultRuntimePort = SampleConstants.DEFAULT_RT_PORT;
83 private string defaultDiagPipeName = SampleConstants.DEFAULT_DM_PIPE_NAME;
84 private string defaultRuntimePipeName = SampleConstants.DEFAULT_RT_PIPE_NAME;
86 private readonly
object printTextLock =
new object();
87 private readonly
object eventListenerLock =
new object();
89 private bool cyclicExecuteAsyncIsProcessing =
false;
90 private System.Windows.Forms.Timer webServerTimer =
new System.Windows.Forms.Timer();
92 public static bool isAcceptEmptyLicenseValue;
93 private static List<SampleForm> listForms =
new List<SampleForm>();
97 fileVersion = RuntimeConfig.Instance.Version;
98 String licenseKeyFromOTForOTPLicense =
OpenTestSystem.Common.LicensingV5.Util.CreateLicenseKeyFromOTForOTPLicense();
100 isAcceptEmptyLicenseValue = licenseKeyFromOTForOTPLicense.Equals(
"") ? false :
true;
102 if (!String.IsNullOrEmpty(licenseKeyFromOTForOTPLicense) && LicensingUtil.CheckLicenseKeyFormat(licenseKeyFromOTForOTPLicense))
104 LicenseManager.SetLicenseKey(licenseKeyFromOTForOTPLicense);
108 String licenseKey = Setting.UserSettings.Default.LicenseKey;
109 licenseKey = LicensingUtil.Decrypt(licenseKey);
110 if (LicensingUtil.CheckLicenseKeyFormat(licenseKey))
112 LicenseManager.SetLicenseKey(licenseKey);
116 MessageBox.Show(
"There is an invalid license key format. Please set your new key in license box.",
"Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
120 SystemEvents.DisplaySettingsChanged +=
new EventHandler(SystemEvents_DisplaySettingsChanged);
123 static void SystemEvents_DisplaySettingsChanged(
object sender, EventArgs e)
127 foreach (Form frm
in listForms)
131 if (frm.InvokeRequired)
133 frm.Invoke(
new Action(() => { frm.Refresh(); }));
146 public SampleForm(
string title = SampleConstants.MAIN_INSTANCE_NAME, SampleForm creatorForm =
null)
148 this.ShowInTaskbar =
false;
150 this.creatorForm = creatorForm;
152 this.webServerTimer.Interval = 1000;
153 this.webServerTimer.Enabled =
true;
154 this.webServerTimer.Tick += WebServerTimer_Tick;
156 InitializeComponent();
160 PrintText(
"Application started");
163 private void SampleForm_Load(
object sender, EventArgs e)
165 PrintText(
"Start Initialization...");
168 InitializeSampleDefaultValues();
169 this.UpdateWebServerButton();
171 if (this.creatorForm !=
null)
173 this.checkBoxStartAllParents.Visible =
true;
174 this.checkBoxStartAllParents.Checked = this.creatorForm.checkBoxStartAllParents.Checked;
177 SetRuntimeContextName();
178 SetTitle(this.title);
179 SetLocation(this.creatorForm);
181 this.toolTip1.SetToolTip(labelProcedureExecutionTimes,
"Total procedure execution time.");
182 this.toolTip1.SetToolTip(textBoxTimeout,
"Timeout for procedure execution in milliseconds. The default value 0 means without timeout.");
183 this.toolTip1.SetToolTip(checkBoxUseConnectionState,
"Use expected connection state during procedure execution.");
184 this.toolTip1.SetToolTip(labelBatteryState,
"State of the battery (KL 30)");
185 this.toolTip1.SetToolTip(checkBoxIgnition,
"Expected ignition (KL 15) state during procedure execution");
186 this.toolTip1.SetToolTip(labelIgnitionState,
"State of the ignition (KL 15)");
187 this.toolTip1.SetToolTip(buttonCheckBatteryIgnition,
"Check current battery (KL30) and ignition (KL15) state.");
188 this.toolTip1.SetToolTip(textBoxPollingTime,
"Time in milliseconds between the next check of the connection state during the procedure execution (Polling). The default value is 500 ms.");
189 this.toolTip1.SetToolTip(textBoxVoltageThreshold,
"Voltage threshold in millivolt from which the battery voltage, see GetBatteryVoltage is enough for KL30 = On. The default value is 6000 mV.");
191 LoadContextFile(globalRuntimeManager);
193 PrintText(
"... Initialization finished.");
194 this.ShowInTaskbar =
true;
197 private void SampleForm_Shown(
object sender, EventArgs e)
199 this.cbFilePath.SelectionLength = 0;
202 private void SetRuntimeContextName()
204 if (this.creatorForm !=
null && !String.IsNullOrEmpty(
this.creatorForm.runtimeContextName))
206 System.Text.RegularExpressions.Match regExpMatch = System.Text.RegularExpressions.Regex.Match(this.creatorForm.runtimeContextName,
@"\d*$");
208 if (
int.TryParse(regExpMatch.Value, out number))
211 this.textBoxRuntimeContextName.Text = this.creatorForm.runtimeContextName.Substring(0, regExpMatch.Index) + number.ToString();
216 private void SetTitle(
string title)
218 if (String.IsNullOrWhiteSpace(title))
219 title = SampleConstants.MAIN_INSTANCE_NAME;
221 bool runningAsAdmin = System.Security.Principal.WindowsIdentity.GetCurrent().Owner.IsWellKnown(System.Security.Principal.WellKnownSidType.BuiltinAdministratorsSid);
223 this.Text = String.Format(
224 "emotive OTX-Runtime API for DotNet - Reference Application - Version {0} - {1} Bit - {2} - Thread-ID {3}{4}",
226 Environment.Is64BitProcess ?
"64" :
"32",
228 Thread.CurrentThread.ManagedThreadId,
229 runningAsAdmin ?
" - Administrator" :
string.Empty
232 if (!String.IsNullOrEmpty(
this.cbFilePath.Text))
233 this.Text = this.Text +
" - " + Path.GetFileName(this.cbFilePath.Text);
235 if (!String.IsNullOrEmpty(
this.runtimeContextName))
236 this.Text = this.Text +
" - " + this.runtimeContextName;
239 private const int FORM_OFFSET = 25;
241 private void SetLocation(SampleForm creatorForm)
243 if (creatorForm !=
null)
245 int xOffset = FORM_OFFSET;
246 int yOffset = FORM_OFFSET;
248 if (creatorForm.creatorForm !=
null)
250 xOffset = creatorForm.Location.X - creatorForm.creatorForm.Location.X;
251 yOffset = creatorForm.Location.Y - creatorForm.creatorForm.Location.Y;
254 this.Location =
new Point(creatorForm.Location.X + xOffset, creatorForm.Location.Y + yOffset);
255 this.Size = creatorForm.Size;
259 private void CreateCustomImpl()
261 CreateDefaultCustomImpl();
262 CreateOutputWindowCustomImpl();
265 private void CreateDefaultCustomImpl()
267 PrintText(
"Create default custom implementation");
269 customScreenImplementation =
new DefaultCustomScreenImplementation();
270 customScreenImplementation.KeyDown += CustomScreenImplementation_KeyDown;
272 contextVariableImplementation =
new ContextVariableImplementation();
273 contextVariableImplementation.ContextVariableRead += ContextVariableRead;
275 stateVariableImplementation =
new StateVariableImplementation();
276 stateVariableImplementation.StateVariableValueChanged += StateVariableValueChanged;
278 measureImplementation =
new DefaultMeasureImplementation();
279 serviceProviderImplementation =
new DefaultExternalServiceProviderImplementation();
282 private void CreateOutputWindowCustomImpl()
284 PrintText(
"Create output window custom implementation");
286 basicScreenOutputImpl =
new BasicScreenOutputImpl();
287 customScreenOutputImpl =
new CustomScreenOutputImpl();
288 loggingOutputImpl =
new LoggingOutputImpl();
289 contextVariableOutputImpl =
new ContextVariableOutputImpl();
291 stateVariableOutputImpl =
new StateVariableOutputImpl();
292 measureOutputImpl =
new MeasureOutputImpl();
293 i18NOutputImpl =
new I18nOutputImpl();
294 serviceProviderOutputImpl =
new ExternalServiceProviderOutputImpl();
296 sqlOutputImpl =
new SqlOutputImpl();
297 commonDialogsOutputImpl =
new CommonDialogsOutputImpl();
299 basicScreenOutputImpl.LogEvent += PrintText;
300 customScreenOutputImpl.LogEvent += PrintText;
301 loggingOutputImpl.LogEvent += PrintText;
302 contextVariableOutputImpl.LogEvent += PrintText;
304 stateVariableOutputImpl.LogEvent += PrintText;
305 measureOutputImpl.LogEvent += PrintText;
306 i18NOutputImpl.LogEvent += PrintText;
307 serviceProviderOutputImpl.LogEvent += PrintText;
309 sqlOutputImpl.LogEvent += PrintText;
310 commonDialogsOutputImpl.LogEvent += PrintText;
313 private void InitializeSampleDefaultValues()
315 PrintText(
"Initialize default values");
317 this.comboBoxTraceLevel.Items.AddRange(Enum.GetNames(typeof(TraceLevels)));
320 treeViewOtxProject.ImageList = imageList1;
322 textBoxRtPortPipe.Name = SampleConstants.RT_PORT_PIPE_TEXT_BOX_NAME;
323 textBoxDiagPortPipe.Name = SampleConstants.DM_PORT_PIPE_TEXT_BOX_NAME;
327 this.EnableConnectionState();
330 private void LoadSetting()
332 SaveSettingUtil.Reload();
337 SetupTraceFileMaxCountAndSize();
340 SetupDefaultPortAndPipeName();
342 cbFilePath.Text = userSettings.Ptx_Ppx_Directory;
343 if (!String.IsNullOrEmpty(userSettings.Ptx_Ppx_DirectoryList))
345 this.cbFilePath.Items.AddRange(userSettings.Ptx_Ppx_DirectoryList.Split(
';'));
347 AddComboBoxFileOrPath(this.cbFilePath);
349 SetupCustomImplType();
351 SetupWindowLocation();
353 checkBoxAsyncExecution.Checked = userSettings.Asynchron;
354 checkBoxCyclicExecution.Checked = userSettings.Cyclic;
355 checkBoxCyclicReload.Checked = userSettings.CyclicReload;
356 checkBoxNewRuntimeManager.Checked = userSettings.NewRunTimeManager;
357 checkBoxAdd2Output.Checked = userSettings.AddMessageToOutput;
358 checkBoxStartAllParents.Checked = userSettings.StartAllParents;
361 checkBoxUseConnectionState.Checked = userSettings.ConnectionState;
362 checkBoxIgnition.CheckState = userSettings.Ignition == 1 ? CheckState.Checked : (userSettings.Ignition == 0 ? CheckState.Unchecked : CheckState.Indeterminate);
364 SetupVoltageThreshold();
366 this.textBoxRuntimeContextName.Text = userSettings.RuntimeContextName.ToString();
368 catch (System.Exception e)
370 PrintText(e.Message);
371 userSettings.Reset();
375 bool isPathChanging =
false;
376 private void AddComboBoxFileOrPath(ComboBox comboBox)
378 if (comboBox !=
null && !isPathChanging)
380 isPathChanging =
true;
382 string path = comboBox.Text;
384 if (Directory.Exists(path) || File.Exists(path))
386 while (comboBox.Items.Contains(path))
388 comboBox.Items.Remove(path);
391 while (comboBox.Items.Contains(path.TrimEnd(
new char[] {
'/',
'\\' })))
393 comboBox.Items.Remove(path.TrimEnd(
new char[] {
'/',
'\\' }));
396 path = path.TrimEnd(
new char[] {
'/',
'\\' });
398 comboBox.Items.Insert(0, path);
399 comboBox.Text = path;
400 comboBox.SelectAll();
403 isPathChanging =
false;
407 private void SetupTraceFileMaxCountAndSize()
409 textBoxTraceFileMaxCount.Text = userSettings.TraceFileMaxCount.ToString();
410 textBoxTraceFileMaxSize.Text = userSettings.TraceFileMaxSize.ToString();
413 private void SetupDefaultPortAndPipeName()
415 defaultDiagPort = userSettings.DiagManagerPort;
416 defaultRuntimePort = userSettings.RuntimePort;
418 defaultDiagPipeName = userSettings.DiagManagerPipeName;
419 defaultRuntimePipeName = userSettings.RuntimePipeName;
421 IpcTypes ipcTypes = IpcTypes.SOCKET;
422 Enum.TryParse<IpcTypes>(userSettings.IpcType, out ipcTypes);
424 if (comboBoxIpcType.Items.Count == 0)
426 comboBoxIpcType.Items.Add(IpcTypes.SOCKET);
427 comboBoxIpcType.Items.Add(IpcTypes.PIPE);
430 comboBoxIpcType.SelectedItem = ipcTypes;
433 private void SetupTraceLevel()
435 RuntimeConfig.Instance.TraceLevel = userSettings.TraceLevels;
436 comboBoxTraceLevel.SelectedItem = RuntimeConfig.Instance.TraceLevel.ToString();
439 private void SetupTraceFolder()
441 if (userSettings.TracingDirectory !=
string.Empty)
442 RuntimeConfig.Instance.TraceFolder = userSettings.TracingDirectory;
444 textBoxTraceFolder.Text = RuntimeConfig.Instance.TraceFolder;
447 private void SetupCustomImplType()
449 if (userSettings.CustomImplTypes == CustomImplTypes.OutputImpl)
451 radioButtonOuputWindow.Checked =
true;
453 else if (userSettings.CustomImplTypes == CustomImplTypes.NoCustom)
455 radioButtonNoCustomImplementation.Checked =
true;
459 radioButtonDefaultImplementation.Checked =
true;
463 private void SetupWindowSize()
465 int width = userSettings.WindowWidth;
466 int height = userSettings.WindowHeight;
467 this.Size =
new Size(width, height);
470 private void SetupWindowLocation()
472 int locationX = userSettings.WindowLocationX;
473 int locationY = userSettings.WindowLocationY;
474 Point location =
new Point(locationX, locationY);
476 if (CheckFormIsInBound(location))
478 this.Location = location;
482 this.CenterToScreen();
485 private bool CheckFormIsInBound(Point location)
489 Screen formContainScreens = Screen.AllScreens.Where(screen => screen.Bounds.Contains(location) ==
true).FirstOrDefault();
491 return formContainScreens !=
null;
493 catch (System.Exception)
499 private void SetupTimeOut()
501 string timeOutString = userSettings.TimeOut.ToString();
502 this.textBoxTimeout.Text = timeOutString;
505 private void SetupPollingTime()
507 string pollingTimeString = userSettings.PollingTime.ToString();
508 this.textBoxPollingTime.Text = pollingTimeString;
511 private void SetupVoltageThreshold()
513 string voltageThreshold = userSettings.VoltageThreshold.ToString();
514 this.textBoxVoltageThreshold.Text = voltageThreshold;
517 private void comboBoxIpcType_SelectedValueChanged(
object sender, EventArgs e)
520 textBoxDiagPortPipe.TextChanged -= textBoxPortPipe_TextChanged;
521 var ipcType = (IpcTypes)comboBoxIpcType.SelectedItem;
525 case IpcTypes.SOCKET:
527 portPipeLabel.Text =
"Runner / DiagManager Ports";
529 textBoxDiagPortPipe.Text = defaultDiagPort.ToString();
530 textBoxDiagPortPipe.TextChanged += textBoxPortPipe_TextChanged;
532 textBoxRtPortPipe.Text = defaultRuntimePort.ToString();
537 portPipeLabel.Text =
"Runner / DiagManager Pipes";
539 textBoxDiagPortPipe.Text = defaultDiagPipeName;
540 textBoxDiagPortPipe.TextChanged += textBoxPortPipe_TextChanged;
542 textBoxRtPortPipe.Text = defaultRuntimePipeName;
550 private void textBoxPortPipe_TextChanged(
object sender, EventArgs e)
552 PrintText(
"Create RuntimeManager...");
556 this.globalRuntimeManager = CreateRuntimeManager();
558 catch (System.Exception ex)
560 switch ((sender as TextBox).Name)
562 case SampleConstants.RT_PORT_PIPE_TEXT_BOX_NAME:
564 PrintText(String.Format(
"Invalid Otx Runtime {0}", IpcPortPipeString()));
567 case SampleConstants.DM_PORT_PIPE_TEXT_BOX_NAME:
569 PrintText(String.Format(
"Invalid Diag Manager {0}", IpcPortPipeString()));
577 PrintText(
"No RuntimeManager created");
580 if (this.globalRuntimeManager ==
null)
582 PrintText(
"RuntimeManager is null.");
586 private IRuntimeManager CreateRuntimeManager()
588 IRuntimeManager runtimeManager =
null;
592 switch ((IpcTypes)comboBoxIpcType.SelectedItem)
594 case IpcTypes.SOCKET:
596 runtimeManager = CreateSocketRuntimeManager();
602 runtimeManager = CreatePipeRuntimeManager();
607 PrintText($
"... {ipcType} RuntimeManager created (MinBinVersion: {RuntimeConfig.Instance.MinBinVersion})");
609 InitializeRuntimeEvents(runtimeManager);
610 SetCustomImplementation(runtimeManager);
612 catch (InvalidLicenseException ex)
615 PrintText(
"... No RuntimeManager created.");
617 return runtimeManager;
620 return runtimeManager;
623 private string IpcPortPipeString()
625 switch ((IpcTypes)comboBoxIpcType.SelectedItem)
627 case IpcTypes.SOCKET:
628 return SampleConstants.PORT_STRING;
630 return SampleConstants.PIPE_STRING;
637 private IRuntimeManager CreateSocketRuntimeManager()
639 ushort rtPort = Convert.ToUInt16(textBoxRtPortPipe.Text);
643 return RuntimeManagerFactory.CreateSocketRuntimeManager(rtPort);
647 ushort diagPort = Convert.ToUInt16(textBoxDiagPortPipe.Text);
648 return RuntimeManagerFactory.CreateSocketRuntimeManager(rtPort, diagPort);
652 private IRuntimeManager CreatePipeRuntimeManager()
656 return RuntimeManagerFactory.CreatePipeRuntimeManager(textBoxRtPortPipe.Text);
660 return RuntimeManagerFactory.CreatePipeRuntimeManager(textBoxRtPortPipe.Text, textBoxDiagPortPipe.Text);
664 private bool NoDiag()
666 return String.IsNullOrWhiteSpace(textBoxDiagPortPipe.Text);
669 private void InitializeRuntimeEvents(IRuntimeManager runtimeManager)
671 if (runtimeManager ==
null)
674 runtimeManager.ProcedurePending -= ProcedurePending;
675 runtimeManager.ProcedureStarted -= ProcedureStarted;
676 runtimeManager.ProcedurePaused -= ProcedurePaused;
677 runtimeManager.ProcedureContinued -= ProcedureContinued;
678 runtimeManager.ProcedureFinished -= ProcedureFinished;
679 runtimeManager.ProcedureAborted -= ProcedureAborted;
680 runtimeManager.ProcedureStopped -= ProcedureStopped;
681 runtimeManager.ProcedureTimeout -= ProcedureTimeout;
682 runtimeManager.DiagConnectionStateChanged -= DiagConnectionStateChanged;
683 runtimeManager.InOutParameterValueChanged -= InOutParameterValueChanged;
685 runtimeManager.ProcedurePending += ProcedurePending;
686 runtimeManager.ProcedureStarted += ProcedureStarted;
687 runtimeManager.ProcedurePaused += ProcedurePaused;
688 runtimeManager.ProcedureContinued += ProcedureContinued;
689 runtimeManager.ProcedureFinished += ProcedureFinished;
690 runtimeManager.ProcedureAborted += ProcedureAborted;
691 runtimeManager.ProcedureStopped += ProcedureStopped;
692 runtimeManager.ProcedureTimeout += ProcedureTimeout;
693 runtimeManager.DiagConnectionStateChanged += DiagConnectionStateChanged;
694 runtimeManager.InOutParameterValueChanged += InOutParameterValueChanged;
696 PrintText(
"Initialization of runtime events finished");
699 private void radioButtonCustomImpl_CheckedChanged(
object sender =
null, System.EventArgs e =
null)
701 if (this.globalRuntimeManager ==
null)
704 if (sender !=
null && (sender as RadioButton).Checked ==
false)
707 this.SetCustomImplementation(this.globalRuntimeManager);
710 private void SetCustomImplementation(IRuntimeManager runtimeManager)
712 if (runtimeManager ==
null)
715 var currentCustomImpl = GetCurrentCustomImpl();
717 switch (currentCustomImpl)
719 case CustomImplTypes.OutputImpl:
721 SetOutputWindowImplementation(runtimeManager);
724 case CustomImplTypes.DefaultCustomImpl:
726 SetDefaultCustomImplementation(runtimeManager);
729 case CustomImplTypes.NoCustom:
731 RemoveCustomImplementation(runtimeManager);
738 if (currentCustomImpl != CustomImplTypes.None)
740 PrintText(
"Set up custom implementation finished");
744 private CustomImplTypes GetCurrentCustomImpl()
746 if (radioButtonOuputWindow.Checked)
747 return CustomImplTypes.OutputImpl;
748 else if (radioButtonDefaultImplementation.Checked)
749 return CustomImplTypes.DefaultCustomImpl;
750 else if (radioButtonNoCustomImplementation.Checked)
751 return CustomImplTypes.NoCustom;
753 return CustomImplTypes.None;
756 private void SetOutputWindowImplementation(IRuntimeManager runtimeManager)
758 if (runtimeManager ==
null)
761 runtimeManager.SetCustomImplementation(basicScreenOutputImpl);
762 runtimeManager.SetCustomImplementation(customScreenOutputImpl);
763 runtimeManager.SetCustomImplementation(loggingOutputImpl);
764 runtimeManager.SetCustomImplementation(contextVariableOutputImpl);
766 runtimeManager.SetCustomImplementation(stateVariableOutputImpl);
767 runtimeManager.SetCustomImplementation(measureOutputImpl);
768 runtimeManager.SetCustomImplementation(i18NOutputImpl);
769 runtimeManager.SetCustomImplementation(serviceProviderOutputImpl);
771 runtimeManager.SetCustomImplementation((ISqlImplementation)
null);
772 runtimeManager.SetCustomImplementation(commonDialogsOutputImpl);
775 private void SetDefaultCustomImplementation(IRuntimeManager runtimeManager)
777 if (runtimeManager ==
null)
780 runtimeManager.SetCustomImplementation((IBasicScreenImplementation)
null);
781 runtimeManager.SetCustomImplementation(customScreenImplementation);
782 runtimeManager.SetCustomImplementation((ILoggingImplementation)
null);
783 runtimeManager.SetCustomImplementation(contextVariableImplementation);
785 runtimeManager.SetCustomImplementation(stateVariableImplementation);
786 runtimeManager.SetCustomImplementation(measureImplementation);
787 runtimeManager.SetCustomImplementation((Ii18nImplementation)
null);
788 runtimeManager.SetCustomImplementation(serviceProviderImplementation);
790 runtimeManager.SetCustomImplementation(sqlOutputImpl);
791 runtimeManager.SetCustomImplementation((ICommonDialogsImplementation)
null);
794 private void RemoveCustomImplementation(IRuntimeManager runtimeManager)
796 if (runtimeManager ==
null)
799 runtimeManager.SetCustomImplementation((IBasicScreenImplementation)
null);
800 runtimeManager.SetCustomImplementation((ICustomScreenImplementation)
null);
801 runtimeManager.SetCustomImplementation((ILoggingImplementation)
null);
802 runtimeManager.SetCustomImplementation((IContextVariableImplementation)
null);
804 runtimeManager.SetCustomImplementation((IStateVariableImplementation)
null);
805 runtimeManager.SetCustomImplementation((IMeasureImplementation)
null);
806 runtimeManager.SetCustomImplementation((Ii18nImplementation)
null);
807 runtimeManager.SetCustomImplementation((IExternalServiceProviderImplementation)
null);
809 runtimeManager.SetCustomImplementation((ISqlImplementation)
null);
810 runtimeManager.SetCustomImplementation((ICommonDialogsImplementation)
null);
813 private void ProcedurePending(IRuntimeContext context)
817 Invoke(
new MethodInvoker(delegate ()
819 ProcedurePending(context);
824 lock (eventListenerLock)
826 this.PrintText(
string.Format(
"Event ProcedurePending occurred - {0} - ExecutionState = {1}", context.Procedure.FullName, context.ExecutionState.ToString()));
827 UpdateExecutionState(context);
828 ShowConnectionStateMessage(context);
832 private void ProcedureStarted(IRuntimeContext context)
836 Invoke(
new MethodInvoker(delegate ()
838 ProcedureStarted(context);
843 lock (eventListenerLock)
845 this.PrintText(
string.Format(
"Event ProcedureStarted occurred - {0} - ExecutionState = {1} - RuntimeId = {2} - ProcessId = {3}", context.Procedure.FullName, context.ExecutionState.ToString(), context.RuntimeId, context.ProcessId));
846 UpdateExecutionState(context);
850 private void ProcedurePaused(IRuntimeContext context, ExecutionStateChangeReason reason)
854 Invoke(
new MethodInvoker(delegate ()
856 ProcedurePaused(context, reason);
861 lock (eventListenerLock)
863 this.PrintText(
string.Format(
"Event ProcedurePaused occurred - {0} - ExecutionState = {1} - ExecutionStateChangeReason = {2}", context.Procedure.FullName, context.ExecutionState.ToString(), reason.ToString()));
864 UpdateExecutionState(context, reason);
867 ShowConnectionStateMessage(context);
872 private void ProcedureContinued(IRuntimeContext context)
876 Invoke(
new MethodInvoker(delegate ()
878 ProcedureContinued(context);
883 lock (eventListenerLock)
885 this.PrintText(
string.Format(
"Event ProcedureContinued occurred - {0} - ExecutionState = {1}", context.Procedure.FullName, context.ExecutionState.ToString()));
886 UpdateExecutionState(context);
890 private void ProcedureStopped(IRuntimeContext context)
894 Invoke(
new MethodInvoker(delegate ()
896 ProcedureStopped(context);
901 lock (eventListenerLock)
903 this.PrintText(
string.Format(
"Event ProcedureStopped occurred - {0} - ExecutionState = {1}", context.Procedure.FullName, context.ExecutionState.ToString()));
904 UpdateExecutionState(context);
908 private void ProcedureTimeout(IRuntimeContext context)
912 Invoke(
new MethodInvoker(delegate ()
914 ProcedureTimeout(context);
919 lock (eventListenerLock)
921 cyclicExecuteAsyncIsProcessing =
false;
922 this.PrintText(
string.Format(
"Event ProcedureTimeout occurred - {0} - ExecutionState = {1}", context.Procedure.FullName, context.ExecutionState.ToString()));
923 UpdateExecutionState(context);
927 private void DiagConnectionStateChanged(ClampState batteryState, ClampState ignitionState)
931 Invoke(
new MethodInvoker(delegate ()
933 DiagConnectionStateChanged(batteryState, ignitionState);
938 lock (eventListenerLock)
940 this.PrintText(
string.Format(
"Event DiagConnectionStateChanged occurred - BatteryState = {0}, IgnitionState = {1}", batteryState.ToString(), ignitionState.ToString()));
941 System.Media.SystemSounds.Beep.Play();
943 SetBatteryIgnitionState(batteryState, ignitionState);
948 private void ProcedureFinished(IRuntimeContext context)
952 Invoke(
new MethodInvoker(delegate ()
954 ProcedureFinished(context);
959 lock (eventListenerLock)
961 IProcedureParameter procedureParameter;
962 string procedureName = context.Procedure.FullName;
963 string parameterOuput;
965 for (
int i = 0; i < context.Procedure.Parameters.Count(); i++)
967 procedureParameter = context.Procedure.Parameters.ElementAt(i);
968 parameterOuput =
"Parameter Changed - " + procedureParameter.Name +
"(" + procedureParameter.DataType +
") = ";
970 if (procedureParameter.Value !=
null)
972 parameterOuput += ShortenedValueString(procedureParameter);
976 parameterOuput +=
null;
979 this.PrintText(parameterOuput);
982 UpdateGridviewParameter(context.Procedure);
984 this.PrintText(
string.Format(
"ProcedureFinished({0}) ExecutionState({1}) - Execution duration {2} - Running time {3} - Used memory {4})",
985 context.Procedure.FullName,
986 context.ExecutionState.ToString(),
987 (DateTime.Now -
this.runtimeContextsExecutionStartTime[context]).ToString(
"hh':'mm':'ss','fff"),
988 TimeSpan.FromMilliseconds(context.ExecutionTime).ToString(
"hh':'mm':'ss','fff"),
989 string.Format(
"{0:0,0} kB", context.ProcessMemory / 1024))
992 UpdateExecutionState(context);
994 cyclicExecuteAsyncIsProcessing =
false;
998 private void ProcedureAborted(IRuntimeContext context)
1002 Invoke(
new MethodInvoker(delegate ()
1004 ProcedureAborted(context);
1009 this.PrintText(
string.Format(
"ProcedureAborted({0}) ExecutionState({1})", context.Procedure.FullName, context.ExecutionState.ToString()));
1011 if (context.HasRuntimeException)
1013 PrintException(context.RuntimeException,
"Reason: API ");
1016 if (context.HasOtxException)
1018 PrintException(context.OtxException,
"Reason: OTX ");
1020 cyclicExecuteAsyncIsProcessing =
false;
1021 UpdateExecutionState(context);
1024 private void UpdateExecutionState(IRuntimeContext context, ExecutionStateChangeReason? reason =
null)
1026 if (context !=
null)
1028 switch (context.ExecutionState)
1032 this.procedureExecutionCount++;
1034 AddRuntimeContext(context);
1035 DisplayProcedureExecutionState(context);
1037 this.buttonExecuteMain.Enabled = checkBoxAsyncExecution.Checked;
1038 this.buttonExecuteSelectedProcedure.Enabled = checkBoxAsyncExecution.Checked;
1040 UpdateExecutionStateButtons(
true);
1041 UpdatePauseButton(
true);
1047 this.procedureExecutionCount--;
1050 DisplayProcedureExecutionState(context);
1059 DisplayProcedureExecutionState(context);
1060 UpdateExecutionStateButtons(
true);
1061 UpdatePauseButton(
true,
false);
1067 this.procedureExecutionCount--;
1069 RemoveRuntimeContext(context);
1070 DisplayProcedureExecutionState(context);
1072 this.buttonExecuteMain.Enabled = !checkBoxCyclicExecution.Checked;
1073 this.buttonExecuteSelectedProcedure.Enabled = !checkBoxCyclicExecution.Checked;
1075 UpdateExecutionStateButtons(
false);
1076 UpdatePauseButton(
true,
false);
1078 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
1079 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
1085 this.procedureExecutionCount--;
1087 RemoveRuntimeContext(context);
1088 DisplayProcedureExecutionState(context);
1090 this.buttonExecuteMain.Enabled =
true;
1091 this.buttonExecuteSelectedProcedure.Enabled =
true;
1093 UpdateExecutionStateButtons(
false);
1094 UpdatePauseButton(
true,
false);
1096 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
1097 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
1103 this.procedureExecutionCount--;
1105 RemoveRuntimeContext(context);
1106 DisplayProcedureExecutionState(context);
1108 this.buttonExecuteMain.Enabled =
true;
1109 this.buttonExecuteSelectedProcedure.Enabled =
true;
1111 UpdateExecutionStateButtons(
false);
1112 UpdatePauseButton(
true,
false);
1114 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
1115 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
1120 System.Media.SystemSounds.Hand.Play();
1122 this.procedureExecutionCount--;
1124 RemoveRuntimeContext(context);
1125 DisplayProcedureExecutionState(context);
1127 this.buttonExecuteMain.Enabled =
true;
1128 this.buttonExecuteSelectedProcedure.Enabled =
true;
1130 UpdateExecutionStateButtons(
false);
1131 UpdatePauseButton(
true,
false);
1133 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
1134 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
1139 StartStopUpdateGuiTimer();
1143 private void StartStopUpdateGuiTimer()
1145 if (this.procedureExecutionCount <= 0)
1147 this.updateGuiTimer.Enabled =
false;
1148 this.labelSeparator1.Visible =
false;
1149 this.labelProcedureExecutionTimes.Visible =
false;
1151 else if (!this.updateGuiTimer.Enabled)
1153 this.updateGuiTimer.Enabled =
true;
1157 private void updateGuiTimer_Tick(
object sender, EventArgs e)
1159 DisplayProcedureExecutionTimes();
1162 private void DisplayProcedureExecutionTimes()
1164 string text =
string.Empty;
1166 if (this.runtimeContextsExecutionStartTime.Count > 0)
1168 foreach (var item
in this.runtimeContextsExecutionStartTime)
1170 var duration = DateTime.Now - item.Value;
1171 text +=
string.Format(
"{0}: {1} | ", item.Key.Procedure.Name, duration.ToString(
"hh':'mm':'ss"));
1173 text = text.TrimEnd(
new char[] {
' ',
'|' });
1176 this.labelProcedureExecutionTimes.Text = text;
1177 this.labelSeparator1.Visible =
true;
1178 this.labelProcedureExecutionTimes.Visible =
true;
1181 private void InOutParameterValueChanged(IRuntimeContext context, IProcedureInOutParameter parameter)
1185 Invoke(
new MethodInvoker(delegate ()
1187 InOutParameterValueChanged(context, parameter);
1192 lock (eventListenerLock)
1196 string valueStr = ShortenedValueString(parameter);
1197 string message = String.Format(
"Parameter '{0}' new value = {1}", parameter.Name, valueStr);
1199 UpdateGridviewParameter(parameter);
1201 catch (InvalidCastException ex)
1203 PrintText(ex.Message);
1208 private static string ShortenedValueString(IProcedureParameter parameter)
1212 var valueStr = ValueConverter.Value2String(parameter.Value);
1213 if (valueStr.Length > VALUE_STRING_MAX_LENGTH)
1214 return valueStr.Substring(0, VALUE_STRING_MAX_LENGTH) +
"...";
1221 return string.Empty;
1224 private void UpdatePauseButton(
bool pauseAvailable,
bool enabled =
true)
1226 this.buttonPause.Enabled = enabled;
1227 this.buttonPause.Checked = !pauseAvailable;
1228 this.buttonPause.Image = pauseAvailable
1229 ? global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.Pause
1230 : global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.Continue;
1233 private void UpdateExecutionStateButtons(
bool wasExecuted)
1235 if (this.useConnectionState)
1237 this.labelTimeout.Enabled = !wasExecuted;
1238 this.textBoxTimeout.Enabled = !wasExecuted;
1239 this.checkBoxUseConnectionState.Enabled = !wasExecuted;
1240 this.labelExpectedState.Enabled = !wasExecuted;
1241 this.checkBoxIgnition.Enabled = !wasExecuted;
1242 this.labelPollingTime.Enabled = !wasExecuted;
1243 this.textBoxPollingTime.Enabled = !wasExecuted;
1244 this.labelVoltageThreshold.Enabled = !wasExecuted;
1245 this.textBoxVoltageThreshold.Enabled = !wasExecuted;
1250 if (checkBoxAsyncExecution.Checked ==
false)
1252 this.buttonExecuteMain.Enabled =
false;
1253 this.buttonExecuteSelectedProcedure.Enabled =
false;
1256 this.buttonStop.Enabled =
true;
1260 if (project !=
null && project.MainProcedure !=
null)
1262 this.buttonExecuteMain.Enabled =
true;
1265 this.buttonExecuteSelectedProcedure.Enabled =
true;
1267 this.buttonStop.Enabled =
false;
1271 private void DisplayProcedureExecutionState(IRuntimeContext context,
string errorMessage =
"")
1273 if (
string.IsNullOrEmpty(errorMessage))
1275 this.labelIconProcedureExecutionState.Image = global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.Info16;
1277 if (this.procedureExecutionCount <= 0)
1279 this.procedureExecutionCount = 0;
1282 this.labelProcedureExecutionState.Text =
"Execution is paused, click \"Continue\"...";
1286 this.labelProcedureExecutionState.Text =
"Select a procedure and click \"Start\"...";
1289 else if (this.procedureExecutionCount == 1)
1291 this.labelProcedureExecutionState.Text =
"1 Procedure is running";
1295 this.labelProcedureExecutionState.Text =
string.Format(
"{0} Procedures are running", this.procedureExecutionCount);
1300 this.labelIconProcedureExecutionState.Image = global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.Error16;
1301 this.labelProcedureExecutionState.Text = errorMessage;
1304 private void SyncWithParent(
object parentControl,
object control =
null,
bool newThread =
false)
1306 if (parentControl !=
null)
1308 if (this.creatorForm !=
null && this.checkBoxStartAllParents.Checked)
1310 if (parentControl is Button)
1314 ThreadPool.QueueUserWorkItem(state => ParentButtonClick(parentControl as Button));
1318 ParentButtonClick(parentControl as Button);
1321 else if (parentControl is TextBox && control !=
null)
1323 string text = (control as TextBox).Text;
1326 ThreadPool.QueueUserWorkItem(state => ParentTextBoxSetText(parentControl as TextBox, text));
1330 ParentTextBoxSetText(parentControl as TextBox, text);
1333 else if (parentControl is CheckBox && control !=
null)
1335 CheckState checkState = (control as CheckBox).CheckState;
1338 ThreadPool.QueueUserWorkItem(state => ParentCheckBoxSetCheckState(parentControl as CheckBox, checkState));
1342 ParentCheckBoxSetCheckState(parentControl as CheckBox, checkState);
1345 else if (parentControl is ComboBox && control !=
null)
1347 int index = (control as ComboBox).SelectedIndex;
1350 ThreadPool.QueueUserWorkItem(state => ParentComboBoxSetIndex(parentControl as ComboBox, index));
1354 ParentComboBoxSetIndex(parentControl as ComboBox, index);
1357 else if (parentControl is NumericUpDown && control !=
null)
1359 int value = decimal.ToInt32((control as NumericUpDown).Value);
1361 ThreadPool.QueueUserWorkItem(state => ParentNumericUpDownSetValue(parentControl as NumericUpDown, value));
1363 ParentNumericUpDownSetValue(parentControl as NumericUpDown, value);
1369 private void ParentButtonClick(Button button)
1371 if (button.InvokeRequired)
1373 this.creatorForm.Invoke(
new Action(() => button.PerformClick()));
1377 button.PerformClick();
1381 private void ParentTextBoxSetText(TextBox textBox,
string text)
1383 if (textBox.InvokeRequired)
1385 this.creatorForm.Invoke(
new Action(() => textBox.Text = text));
1389 textBox.Text = text;
1393 private void ParentCheckBoxSetCheckState(CheckBox checkBox, CheckState checkState)
1395 if (checkBox.InvokeRequired)
1397 this.creatorForm.Invoke(
new Action(() => checkBox.CheckState = checkState));
1401 checkBox.CheckState = checkState;
1405 private void ParentComboBoxSetIndex(ComboBox comboBox,
int index)
1407 if (comboBox.InvokeRequired)
1409 this.creatorForm.Invoke(
new Action(() => comboBox.SelectedIndex = index));
1413 comboBox.SelectedIndex = index;
1417 private void buttonBrowseTraceFolder_Click(
object sender, EventArgs e)
1419 folderBrowserDialog1.SelectedPath = this.textBoxTraceFolder.Text;
1420 folderBrowserDialog1.ShowNewFolderButton =
true;
1422 DialogResult result = folderBrowserDialog1.ShowDialog();
1423 if (result == DialogResult.OK)
1425 this.textBoxTraceFolder.Text = folderBrowserDialog1.SelectedPath;
1429 private void buttonOpenTraceFolder_Click(
object sender, EventArgs e)
1431 string path = this.textBoxTraceFolder.Text;
1432 if (Directory.Exists(path))
1434 Process.Start(path);
1439 private void textBoxTraceFolder_TextChanged(
object sender, EventArgs e)
1441 if (this.globalRuntimeManager ==
null)
1444 string path = this.textBoxTraceFolder.Text;
1446 if (path != RuntimeConfig.Instance.TraceFolder)
1448 if (Directory.Exists(path))
1450 RuntimeConfig.Instance.TraceFolder = textBoxTraceFolder.Text;
1451 this.buttonOpenTraceFolder.Enabled =
true;
1453 PrintText(
"Set trace folder to " + RuntimeConfig.Instance.TraceFolder);
1457 this.buttonOpenTraceFolder.Enabled =
false;
1462 this.buttonOpenTraceFolder.Enabled =
true;
1465 SyncWithParent(this.creatorForm?.textBoxTraceFolder, this.textBoxTraceFolder);
1469 private void comboBoxTraceLevel_SelectedValueChanged(
object sender, EventArgs e)
1471 if (this.globalRuntimeManager ==
null)
1474 var traceLevel = (
TraceLevels)comboBoxTraceLevel.SelectedIndex;
1475 if (traceLevel == RuntimeConfig.Instance.TraceLevel)
1478 RuntimeConfig.Instance.TraceLevel = traceLevel;
1479 PrintText(
"Updated trace level");
1482 private void buttonBrowseFile_Click(
object sender, EventArgs e)
1484 DialogResult result = openFileDialog1.ShowDialog();
1485 if (result == DialogResult.OK)
1487 cbFilePath.Text = openFileDialog1.FileName;
1489 this.buttonReload.PerformClick();
1493 private void cbFilePath_TextChanged(
object sender, EventArgs e)
1495 AddComboBoxFileOrPath(cbFilePath);
1497 if (String.IsNullOrWhiteSpace(cbFilePath.Text) || !File.Exists(cbFilePath.Text.Trim()))
1499 buttonReload.Enabled =
false;
1503 buttonReload.Enabled =
true;
1506 SyncWithParent(this.creatorForm?.cbFilePath, this.cbFilePath);
1509 private void cbFilePath_SelectedValueChanged(
object sender, EventArgs e)
1511 if (String.IsNullOrWhiteSpace(cbFilePath.Text) || !File.Exists(cbFilePath.Text.Trim()))
1513 buttonReload.Enabled =
false;
1517 buttonReload.Enabled =
true;
1518 if (isPathChanging ==
false)
1520 this.buttonReload.PerformClick();
1524 SyncWithParent(this.creatorForm?.cbFilePath, this.cbFilePath);
1527 private void buttonReload_Click(
object sender, EventArgs e)
1529 this.LoadContextFile(this.globalRuntimeManager);
1531 SyncWithParent(this.creatorForm?.buttonReload);
1534 private void LoadContextFile(IRuntimeManager runtimeManager)
1536 PrintText(
"Load '" + cbFilePath.Text +
"'...");
1538 if (runtimeManager ==
null)
1540 PrintText(
"... No RuntimeManager exists!");
1544 if (String.IsNullOrWhiteSpace(cbFilePath.Text.Trim()))
1546 PrintText(
"... wrong file name.");
1550 SetTitle(this.title);
1555 this.isLoadding =
true;
1556 this.playerProject =
null;
1557 this.project =
null;
1558 this.contextVariableImplementation.ResetAllValues();
1559 this.stateVariableImplementation.ResetAllValues();
1562 if (Path.GetExtension(cbFilePath.Text.Trim()).Contains(
"ptx"))
1564 this.project = LoadPtx(runtimeManager);
1566 if (this.project !=
null)
1568 PrintText(
"... Project '" + project.Name +
"' successfully loaded.");
1570 ClearCustomImplemetationCaches();
1572 this.LoadPackage(this.project);
1574 ReadSettings(this.project.Settings);
1576 this.isLoadding =
false;
1580 else if (Path.GetExtension(cbFilePath.Text.Trim()).Contains(
"ppx"))
1582 this.playerProject = LoadPpx(runtimeManager);
1584 if (this.playerProject !=
null)
1586 ClearCustomImplemetationCaches();
1588 PrintText(
"... Player '" + playerProject.Name +
"' successfully loaded.");
1590 foreach (IProject item
in this.playerProject.Projects)
1593 this.LoadPackage(item);
1596 ReadSettings(this.playerProject.Settings);
1598 this.isLoadding =
false;
1603 catch (System.Exception ex)
1608 this.isLoadding =
false;
1611 private void ClearSampleGUI()
1613 this.treeViewOtxProject.Nodes.Clear();
1614 this.gridViewParameter.Rows.Clear();
1615 this.gridViewContext.Rows.Clear();
1616 this.gridViewState.Rows.Clear();
1617 this.gridViewSettings.Rows.Clear();
1620 private void ClearCustomImplemetationCaches()
1622 if (this.contextVariableImplementation !=
null)
1623 this.contextVariableImplementation.ResetAllValues();
1625 if (this.contextVariableOutputImpl !=
null)
1626 this.contextVariableOutputImpl.ResetAllValues();
1628 if (this.stateVariableImplementation !=
null)
1629 this.stateVariableImplementation.ResetAllValues();
1635 private IProject LoadPtx(IRuntimeManager runtimeManager)
1637 IProject project =
null;
1639 if (runtimeManager.IsProtected(cbFilePath.Text))
1641 project = runtimeManager.LoadPtx(cbFilePath.Text, txtPassword.Text.Trim());
1645 project = runtimeManager.LoadPtx(cbFilePath.Text);
1648 if (project.MainProcedure !=
null)
1650 buttonExecuteMain.Enabled =
true;
1657 private IPlayerProject LoadPpx(IRuntimeManager runtimeManager)
1659 IPlayerProject playerProject =
null;
1661 if (runtimeManager.IsProtected(cbFilePath.Text))
1663 playerProject = runtimeManager.LoadPpx(cbFilePath.Text, txtPassword.Text.Trim());
1667 playerProject = runtimeManager.LoadPpx(cbFilePath.Text);
1670 return playerProject;
1674 private void LoadPackage(IProject project)
1676 PrintText(
"Browse project...");
1678 IPackage[] packages = project.Packages;
1679 if (packages ==
null)
1681 IDocument document = project.StartupDocument;
1682 this.treeViewOtxProject.Nodes.Add(CreateDocumentNode(document));
1686 string treeNodeText = project.Name;
1687 if (!String.IsNullOrWhiteSpace(project.Version))
1688 treeNodeText = String.Format(
"{0} ({1})", treeNodeText, project.Version);
1690 TreeNode root =
new TreeNode(treeNodeText);
1691 root.ImageKey = root.SelectedImageKey =
"ODFProject.bmp";
1692 foreach (IPackage pack
in packages)
1694 root.Nodes.Add(this.CreatePackageNode(pack));
1697 this.treeViewOtxProject.Nodes.Add(root);
1700 this.treeViewOtxProject.Enabled = this.gridViewParameter.Enabled =
true;
1701 this.treeViewOtxProject.ExpandAll();
1702 this.treeViewOtxProject.SelectedNode = startupNode;
1703 this.treeViewOtxProject.Focus();
1705 PrintText(
"... project browsing finished.");
1709 private TreeNode CreateDocumentNode(IDocument doc)
1711 TreeNode documentNode =
new TreeNode(doc.Name);
1712 documentNode.Tag = doc;
1713 documentNode.ImageKey = documentNode.SelectedImageKey =
"DocumentOTX16.bmp";
1716 documentNode.Text +=
" (StartUp)";
1719 foreach (IProcedure p
in doc.Procedures)
1721 TreeNode procedureNode = CreateProcedureNode(p);
1722 documentNode.Nodes.Add(procedureNode);
1723 if (doc.IsStartup && p.Name ==
"main")
1725 startupNode = procedureNode;
1726 buttonExecuteMain.Enabled =
true;
1728 else if (startupNode ==
null)
1730 startupNode = procedureNode;
1734 return documentNode;
1738 private TreeNode CreateProcedureNode(IProcedure procedure)
1740 if (checkBoxCyclicReload.Checked &&
1741 procedureToExecute !=
null &&
1742 procedureToExecute.FullName == procedure.FullName)
1744 procedureToExecute = procedure;
1747 TreeNode procedureNode =
new TreeNode(procedure.Name);
1748 procedureNode.ImageKey = procedureNode.SelectedImageKey =
"Procedure.bmp";
1749 procedureNode.Tag = procedure;
1750 return procedureNode;
1754 private TreeNode CreatePackageNode(IPackage pack)
1756 TreeNode packageNode =
new TreeNode(pack.Name);
1757 packageNode.Tag = pack;
1758 packageNode.ImageKey = packageNode.SelectedImageKey =
"Package.bmp";
1760 List<IDocument> documents = pack.Documents.ToList();
1761 foreach (IDocument doc
in documents)
1763 packageNode.Nodes.Add(CreateDocumentNode(doc));
1766 foreach (IPackage package
in pack.Packages)
1768 packageNode.Nodes.Add(this.CreatePackageNode(package));
1774 private void gridView_CellContentClick(
object sender, DataGridViewCellEventArgs e)
1780 DataGridView gridView = sender as DataGridView;
1781 DataGridViewComboBoxCell comboBoxCell = gridView.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewComboBoxCell;
1782 if (comboBoxCell !=
null)
1784 gridView.BeginEdit(
true);
1785 (gridView.EditingControl as DataGridViewComboBoxEditingControl).DroppedDown =
true;
1792 gridView_CellValueChanged(sender, e);
1796 private void gridView_CellValueChanged(
object sender, DataGridViewCellEventArgs e)
1798 DataGridView gridView = sender as DataGridView;
1801 if (gridView == this.gridViewParameter)
1803 columnName = dataGridViewTextBoxColumnValue.Name;
1805 else if (gridView == this.gridViewContext)
1807 columnName = dataGridViewTextBoxColumnContextValue.Name;
1814 if (!this.isLoadding && e.RowIndex >= 0 && gridView.Columns[e.ColumnIndex].Name == columnName &&
1816 gridView.Rows[e.RowIndex].Cells[columnName] is DataGridViewCheckBoxCell ||
1817 gridView.Rows[e.RowIndex].Cells[columnName] is DataGridViewComboBoxCell
1822 this.Validate(
false);
1827 void gridViewParameter_CellValidated(
object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
1829 DataGridView gridView = sender as DataGridView;
1830 if (!this.isLoadding && gridView !=
null && e.RowIndex >= 0 && gridView.Columns[e.ColumnIndex].Name == dataGridViewTextBoxColumnValue.Name)
1832 IProcedureParameter parameter = gridView.Rows[e.RowIndex].Tag as IProcedureParameter;
1833 if (parameter.Value !=
null)
1835 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnValue.Name].Value = ConvertValue2String(parameter.Value);
1836 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnDetails.Name].Value = GetDetails(parameter.Value);
1843 void gridViewParameter_CellValidating(
object sender, System.Windows.Forms.DataGridViewCellValidatingEventArgs e)
1845 DataGridView gridView = sender as DataGridView;
1846 if (!this.isLoadding && gridView !=
null && e.RowIndex >= 0 &&
1847 gridView.Columns[e.ColumnIndex].Name == dataGridViewTextBoxColumnValue.Name &&
1848 !gridView.Rows[e.RowIndex].ReadOnly &&
1849 e.FormattedValue !=
null)
1851 IProcedureParameter parameter = gridView.Rows[e.RowIndex].Tag as IProcedureParameter;
1852 if (e.FormattedValue.ToString() == ValueConverter.Value2String(parameter.Value) || e.FormattedValue.ToString() == ConvertValue2String(parameter.Value))
1857 object value =
null;
1861 value = ValueConverter.String2Value(e.FormattedValue.ToString(), parameter.DataType);
1863 catch (System.Exception ex)
1876 System.Media.SystemSounds.Exclamation.Play();
1880 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnDataType.Name].ErrorText =
string.Empty;
1881 if (parameter is IProcedureInParameter)
1882 (parameter as IProcedureInParameter).Value = value;
1883 else if (parameter is IProcedureInOutParameter)
1884 (parameter as IProcedureInOutParameter).Value = value;
1895 void gridViewContextVariable_CellValidated(
object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
1897 DataGridView gridView = sender as DataGridView;
1898 if (!this.isLoadding && gridView !=
null &&
1900 gridView.Columns[e.ColumnIndex].Name == dataGridViewTextBoxColumnContextValue.Name)
1902 IContextVariable context = gridView.Rows[e.RowIndex].Tag as IContextVariable;
1903 if (gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag !=
null)
1905 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Value = ConvertValue2String(gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag);
1906 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextDetails.Name].Value = GetDetails(gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag);
1912 void gridViewContextVariable_CellValidating(
object sender, System.Windows.Forms.DataGridViewCellValidatingEventArgs e)
1914 DataGridView gridView = sender as DataGridView;
1915 if (!this.isLoadding && gridView !=
null &&
1917 gridView.Columns[e.ColumnIndex].Name == dataGridViewTextBoxColumnContextValue.Name &&
1918 !gridView.Rows[e.RowIndex].ReadOnly &&
1919 e.FormattedValue !=
null)
1921 IContextVariable context = gridView.Rows[e.RowIndex].Tag as IContextVariable;
1922 if (e.FormattedValue.ToString() == ValueConverter.Value2String(gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag) || e.FormattedValue.ToString() == ConvertValue2String(gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag))
1927 object value =
null;
1931 value = ValueConverter.String2Value(e.FormattedValue.ToString(), context.DataType);
1933 catch (System.Exception ex)
1946 System.Media.SystemSounds.Exclamation.Play();
1952 string fullNameContextVariable = context.Document.FullName +
'.' + context.Name;
1953 this.contextVariableImplementation.SetValue(fullNameContextVariable, value);
1954 this.contextVariableOutputImpl.SetValue(fullNameContextVariable, value);
1955 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag = value;
1956 gridView.Rows[e.RowIndex].Cells[dataGridViewTextBoxColumnContextDataType.Name].ErrorText =
string.Empty;
1967 private void treeViewOtxProject_AfterSelect(
object sender, TreeViewEventArgs e)
1969 TreeNode node = e.Node;
1973 this.gridViewParameter.Rows.Clear();
1974 this.gridViewContext.Rows.Clear();
1975 this.gridViewState.Rows.Clear();
1977 if (node.Tag is IProcedure)
1979 IProcedure procedure = node.Tag as IProcedure;
1980 ClearCustomImplemetationCaches();
1981 UpdateGridview(procedure);
1983 buttonExecuteSelectedProcedure.Enabled =
true;
1984 this.project = GetProject(procedure);
1989 buttonExecuteSelectedProcedure.Enabled =
false;
1993 private IProject GetProject(IProcedure procedure)
1995 if (procedure !=
null)
1997 IPackage
package = procedure.Document.Package;
1998 if (package !=
null)
2000 while (package.Parent !=
null)
2002 package = package.Parent;
2005 return package.Project;
2011 private void treeViewOtxProject_DrawNode(
object sender, DrawTreeNodeEventArgs e)
2013 e.DrawDefault =
true;
2017 private void buttonReadSettings_Click(
object sender, EventArgs e)
2019 Dictionary<string, string> settings =
null;
2020 if (this.playerProject !=
null)
2022 settings = this.playerProject.Settings;
2024 else if (this.project !=
null)
2026 settings = this.project.Settings;
2028 ReadSettings(settings);
2031 private void ReadSettings(Dictionary<string, string> settings)
2033 if (settings !=
null)
2035 PrintText(
"Read settings");
2037 gridViewSettings.Rows.Clear();
2039 foreach (KeyValuePair<string, string> setting
in settings)
2041 object[] values =
new object[] { setting.Key, setting.Value };
2042 this.gridViewSettings.Rows.Add(values);
2048 private void buttonWriteSettings_Click(
object sender, EventArgs e)
2051 string valueSetting;
2052 int selectedSettingPosition = 0;
2053 Dictionary<string, string> newSettings =
new Dictionary<string, string>();
2055 if (this.gridViewSettings.SelectedRows.Count != 0)
2057 selectedSettingPosition = this.gridViewSettings.SelectedRows[0].Index;
2062 if (project !=
null || playerProject !=
null)
2064 foreach (DataGridViewRow row
in this.gridViewSettings.Rows)
2066 nameSetting = row.Cells[this.dataGridViewTextBoxColumnSettingName.Name].Value.ToString();
2067 valueSetting = row.Cells[this.dataGridViewTextBoxColumnSettingValue.Name].Value?.ToString();
2069 newSettings.Add(nameSetting, valueSetting);
2072 if (playerProject !=
null)
2074 playerProject.Settings = newSettings;
2075 ReadSettings(playerProject.Settings);
2079 project.Settings = newSettings;
2080 ReadSettings(project.Settings);
2083 this.gridViewSettings.Rows[selectedSettingPosition].Selected =
true;
2084 this.gridViewSettings.Rows[selectedSettingPosition].Cells[dataGridViewTextBoxColumnSettingValue.Name].Selected =
true;
2086 PrintText(
"Write settings finished");
2089 catch (System.Exception ex)
2095 private void checkBoxCyclicExecution_CheckedChanged(
object sender, EventArgs e)
2097 this.checkBoxCyclicReload.Enabled = this.checkBoxNewRuntimeManager.Enabled = this.checkBoxCyclicExecution.Checked;
2099 if (!this.checkBoxCyclicExecution.Checked)
2101 this.checkBoxCyclicReload.Checked = this.checkBoxNewRuntimeManager.Checked =
false;
2104 SyncWithParent(this.creatorForm?.checkBoxCyclicExecution, this.checkBoxCyclicExecution);
2107 private void checkBoxAsyncExecution_CheckedChanged(
object sender, EventArgs e)
2109 SyncWithParent(this.creatorForm?.checkBoxAsyncExecution, this.checkBoxAsyncExecution);
2112 private void checkBoxNewRuntimeManager_CheckedChanged(
object sender, EventArgs e)
2114 if (this.checkBoxNewRuntimeManager.Checked)
2116 this.checkBoxCyclicReload.Checked =
true;
2119 SyncWithParent(this.creatorForm?.checkBoxNewRuntimeManager, this.checkBoxNewRuntimeManager);
2122 private void checkBoxCyclicReload_CheckedChanged(
object sender, EventArgs e)
2124 SyncWithParent(this.creatorForm?.checkBoxCyclicReload, this.checkBoxCyclicReload);
2128 private void buttonExecuteSelectedProcedure_Click(
object sender, EventArgs e)
2132 if (treeViewOtxProject.SelectedNode !=
null && treeViewOtxProject.SelectedNode.Tag is IProcedure)
2134 IDocument document = treeViewOtxProject.SelectedNode.Parent.Tag as IDocument;
2135 List<string> listItemsReviewed =
new List<string>();
2137 this.procedureToExecute = treeViewOtxProject.SelectedNode.Tag as IProcedure;
2138 this.ExecuteProcedure();
2142 PrintText(
"Please select Procedure to execute");
2146 catch (System.Exception ex)
2151 SyncWithParent(this.creatorForm?.buttonExecuteSelectedProcedure,
null,
true);
2156 private void buttonExecuteMain_Click(
object sender, EventArgs e)
2160 if (project !=
null)
2162 treeViewOtxProject.SelectedNode = startupNode;
2163 this.procedureToExecute = project.MainProcedure;
2164 this.ExecuteProcedure();
2168 PrintText(
"There is no project has been loaded. Please reload the project");
2171 catch (System.Exception ex)
2176 SyncWithParent(this.creatorForm?.buttonExecuteMain,
null,
true);
2180 private async
void ExecuteProcedure()
2182 PrintText(
"Start procedure execution...");
2184 if (checkBoxAsyncExecution.Checked ==
false)
2186 this.buttonExecuteMain.Enabled =
false;
2187 this.buttonExecuteSelectedProcedure.Enabled =
false;
2192 if (this.globalRuntimeManager !=
null && procedureToExecute !=
null)
2194 this.buttonStop.Enabled =
true;
2196 CheckBatteryIgnitionState(this.globalRuntimeManager);
2198 if (checkBoxCyclicExecution.Checked)
2200 ThreadPool.QueueUserWorkItem(state => DoCyclic());
2205 if (checkBoxAsyncExecution.Checked)
2207 this.globalRuntimeManager.ExecuteAsync(textBoxRuntimeContextName.Text.Trim(), procedureToExecute,
this.expectedConnectionState, (ulong)Convert.ToInt32(
this.textBoxTimeout.Text));
2211 await Task.Run(() => this.globalRuntimeManager.Execute(textBoxRuntimeContextName.Text.Trim(), procedureToExecute,
this.expectedConnectionState, (ulong)Convert.ToInt32(
this.textBoxTimeout.Text)));
2217 PrintText(
"RuntimeManager is null or no Procedure is selected to run.");
2220 catch (System.Exception ex)
2224 UpdateButtonStateAfterThrowException();
2228 private void UpdateButtonStateAfterThrowException()
2230 this.buttonExecuteMain.Enabled = !checkBoxCyclicExecution.Checked;
2231 this.buttonExecuteSelectedProcedure.Enabled = !checkBoxCyclicExecution.Checked;
2233 UpdateExecutionStateButtons(
false);
2234 UpdatePauseButton(
true,
false);
2236 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
2237 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
2241 private void DoCyclic()
2243 DateTime startTime = DateTime.Now;
2248 while (checkBoxCyclicExecution.Checked)
2250 IRuntimeManager runtimeManager =
null;
2251 IRuntimeContext runtimeContext =
null;
2254 this.cyclicExecutionCount++;
2256 if (this.checkBoxNewRuntimeManager.Checked)
2258 runtimeManager = CreateRuntimeManager();
2262 runtimeManager = this.globalRuntimeManager;
2265 CheckCyclicReloadOrNewRuntimeManager(runtimeManager);
2267 cyclicExecuteAsyncIsProcessing =
true;
2268 CheckBatteryIgnitionState(this.globalRuntimeManager);
2270 if (this.checkBoxAsyncExecution.Checked)
2272 runtimeContext = runtimeManager.ExecuteAsync(textBoxRuntimeContextName.Text.Trim(), procedureToExecute,
this.expectedConnectionState, (ulong)Convert.ToInt32(
this.textBoxTimeout.Text));
2273 if (runtimeContext !=
null)
2276 Application.DoEvents();
2282 runtimeContext = runtimeManager.Execute(textBoxRuntimeContextName.Text.Trim(), procedureToExecute,
this.expectedConnectionState, (ulong)Convert.ToInt32(
this.textBoxTimeout.Text));
2287 this.cyclicExecutionCount = 0;
2292 catch (System.Exception ex)
2296 UpdateButtonStateAfterThrowException();
2300 Invoke(
new MethodInvoker(delegate ()
2302 if (this.checkBoxNewRuntimeManager.Checked)
2304 LoadContextFile(this.globalRuntimeManager);
2308 PrintText(
"Cyclic execution finished");
2310 var duration = DateTime.Now - startTime;
2311 string text = String.Format(
"Execution Statistics: Duration {0} (hh:mm:ss) with {1} cycles and {2:0} ms per cycle", duration.ToString(
@"hh\:mm\:ss"), cyclic, duration.TotalMilliseconds / cyclic);
2313 this.cyclicExecutionCount -= cyclic;
2314 if (this.cyclicExecutionCount < 0)
2316 this.cyclicExecutionCount = 0;
2319 if (this.checkBoxAdd2Output.Checked)
2325 MessageBox.Show(text);
2328 private void WaitCyclicExecuteAsyncIsProcessing()
2330 if (this.checkBoxCyclicReload.Checked ||
this.checkBoxNewRuntimeManager.Checked)
2333 while (cyclicExecuteAsyncIsProcessing)
2336 Application.DoEvents();
2342 private void CheckCyclicReloadOrNewRuntimeManager(IRuntimeManager runtimeMgr,
bool waitCyclic =
true)
2346 WaitCyclicExecuteAsyncIsProcessing();
2351 Invoke(
new MethodInvoker(delegate ()
2353 CheckCyclicReloadOrNewRuntimeManager(runtimeMgr,
false);
2358 if (this.checkBoxCyclicReload.Checked ||
this.checkBoxNewRuntimeManager.Checked)
2360 LoadContextFile(runtimeMgr);
2363 if (this.checkBoxCyclicExecution.Checked)
2365 this.checkBoxCyclicExecution.Text =
"Cyclic (" + this.cyclicExecutionCount +
")";
2369 this.checkBoxCyclicExecution.Text =
"Cyclic";
2374 private void buttonStop_Click(
object sender, EventArgs e)
2376 if (this.globalRuntimeManager !=
null)
2378 PrintText(String.Format(
"Try to stop all running procedures..."));
2379 this.globalRuntimeManager.StopAll();
2380 this.procedureExecutionCount = 0;
2384 this.checkBoxCyclicExecution.Checked =
false;
2386 SyncWithParent(this.creatorForm?.buttonStop);
2389 private void PrintException(System.Exception ex,
string additionalText =
"")
2391 PrintText(String.Format(
"!!! {2}{0}: {1}", ex.GetType().Name, ex.Message, additionalText));
2392 System.Media.SystemSounds.Hand.Play();
2395 private void PrintText(
string text)
2399 this.Invoke(
new Action(() => PrintText(text)));
2403 if (!this.checkBoxAdd2Output.Checked)
2409 lock (printTextLock)
2411 if (this.listBoxOuput.Items.Count >= 10000)
2413 buttonClearOutput_Click(
null,
null);
2416 string prefixString = GetTimeAndDurationStringSinceLastTimeAndUpdateLastTime();
2417 string itemToAdd = prefixString + text +
"\t\t";
2419 this.listBoxOuput.Items.Add(itemToAdd);
2420 this.listBoxOuput.SelectedItems.Clear();
2421 this.listBoxOuput.TopIndex = listBoxOuput.Items.Count - 1;
2423 if (this.listBoxOuput.Items.Count >= 7500)
2425 this.labelOutputOverflow.Visible =
true;
2430 Application.DoEvents();
2434 private string GetTimeAndDurationStringSinceLastTimeAndUpdateLastTime()
2436 DateTime now = DateTime.Now;
2437 var duration = now - this.lastTime;
2439 this.lastTime = now;
2441 string timeDurationString = String.Format(
"{0:HH:mm:ss.fff} {1,6:#,##0} ms ", now, duration.TotalMilliseconds);
2442 return timeDurationString;
2445 private void buttonCopyRow_Click(
object sender, EventArgs e)
2447 if (this.listBoxOuput.SelectedItems !=
null)
2449 string text =
string.Empty;
2450 foreach (
string row
in this.listBoxOuput.SelectedItems)
2452 text += row.Trim(
'\t') +
"\n";
2455 Clipboard.SetText(text);
2459 private void buttonClearOutput_Click(
object sender, EventArgs e)
2461 this.listBoxOuput.Items.Clear();
2462 this.labelOutputOverflow.Visible =
false;
2463 this.buttonCopyRow.Enabled =
false;
2467 private void UpdateGridview(IProcedure procedure)
2469 if (procedure ==
null ||
2470 procedure.Parameters ==
null)
2475 UpdateGridviewParameter(procedure);
2477 IDocument document = procedure.Document;
2478 if (document !=
null)
2480 List<string> listItemsReviewed =
new List<string>();
2481 UpdateGridViewContextVariable(document,
false, listItemsReviewed);
2483 listItemsReviewed.Clear();
2484 UpdateGridViewStateVariable(document,
false, listItemsReviewed);
2488 private void UpdateGridviewParameter(IProcedure procedure)
2490 foreach (IProcedureParameter param
in procedure.Parameters)
2492 UpdateGridviewParameter(param);
2497 private void UpdateGridviewParameter(IProcedureParameter parameter)
2499 if (parameter ==
null)
2504 bool bValueWasSet =
false;
2507 string collumnName = dataGridViewTextBoxColumnName.Name;
2508 string collumnValue = dataGridViewTextBoxColumnValue.Name;
2509 string collumnDetails = dataGridViewTextBoxColumnDetails.Name;
2510 foreach (DataGridViewRow row
in this.gridViewParameter.Rows)
2512 if (row.Cells[collumnName].Value.Equals(parameter.Name))
2516 if (parameter.Value !=
null)
2518 row.Cells[collumnValue].Value = ConvertValue2String(parameter.Value);
2521 catch (System.Exception ex)
2523 row.Cells[collumnValue].ErrorText = ex.Message;
2526 bValueWasSet =
true;
2534 string direction = parameter is IProcedureInParameter ?
"In" : (parameter is IProcedureInOutParameter ?
"InOut" :
"Out");
2535 object[] values =
new object[] { parameter.Name, direction, parameter.DataType };
2536 int index = this.gridViewParameter.Rows.Add(values);
2538 this.gridViewParameter.Rows[index].Tag = parameter;
2540 this.gridViewParameter.Rows[index].ReadOnly = parameter is IProcedureOutParameter || parameter.InitValue ==
null;
2542 if (parameter.DataType.Equals(
"Boolean"))
2544 gridViewParameter.Rows[index].Cells[collumnValue] =
new DataGridViewCheckBoxCell();
2545 DataGridViewCheckBoxCell cell = gridViewParameter.Rows[index].Cells[collumnValue] as DataGridViewCheckBoxCell;
2546 cell.Value = ConvertValue2String(parameter.Value);
2547 cell.Tag = parameter.Value;
2549 else if (parameter.Value is EnumerationElement)
2551 gridViewParameter.Rows[index].Cells[collumnValue] =
new DataGridViewComboBoxCell();
2552 DataGridViewComboBoxCell cell = gridViewParameter.Rows[index].Cells[collumnValue] as DataGridViewComboBoxCell;
2553 cell.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
2554 cell.FlatStyle = FlatStyle.Flat;
2555 cell.DisplayMember =
"Name";
2556 cell.ValueMember =
"Name";
2557 cell.DataSource = (parameter.Value as EnumerationElement).Enumeration.Elements;
2558 cell.Value = ConvertValue2String(parameter.Value);
2559 cell.Tag = parameter.Value;
2565 if (parameter.Value !=
null)
2567 gridViewParameter.Rows[index].Cells[collumnValue].Value = ConvertValue2String(parameter.Value);
2570 catch (System.Exception ex)
2572 gridViewParameter.Rows[index].Cells[collumnValue].ErrorText = ex.Message;
2576 gridViewParameter.Rows[index].Cells[collumnDetails].Value = GetDetails(parameter.Value);
2580 private string ConvertValue2String(
object value)
2584 return string.Empty;
2587 return ValueConverter.Value2String(value);
2590 private string GetDetails(
object value)
2594 return string.Empty;
2597 if (value is TranslationKey translationKey)
2599 if (!
string.IsNullOrEmpty(translationKey.TextIdMappingName))
2601 return string.Format(
"MappingName: {0}", translationKey.TextIdMappingName);
2604 else if (value is EnumerationElement enumerationElement)
2606 if (enumerationElement.TranslationKey !=
null)
2608 if (!
string.IsNullOrEmpty(enumerationElement.TranslationKey.TextId) && !
string.IsNullOrEmpty(enumerationElement.TranslationKey.TextIdMappingName))
2610 return string.Format(
"TextId: {0}, MappingName: {1}", enumerationElement.TranslationKey.TextId, enumerationElement.TranslationKey.TextIdMappingName);
2612 else if (!
string.IsNullOrEmpty(enumerationElement.TranslationKey.TextId))
2614 return string.Format(
"TextId: {0}", enumerationElement.TranslationKey.TextId);
2617 return string.Format(
"MappingName: {0}", enumerationElement.TranslationKey.TextIdMappingName);
2621 return string.Empty;
2625 private void UpdateGridViewContextVariable(IDocument document,
bool withPrefix, List<string> listItemsReviewed)
2627 string @
namespace = string.Concat(document.Package.Name, ".", document.Name);
2628 if (listItemsReviewed.Contains(@
namespace))
2633 listItemsReviewed.Add(@
namespace);
2634 foreach (IContextVariable contextVariable
in document.ContextVariables)
2636 if (contextVariable ==
null)
2641 bool bValueWasSet =
false;
2644 foreach (DataGridViewRow row
in this.gridViewContext.Rows)
2646 if (row.Cells[
this.dataGridViewTextBoxColumnContextName.Name].Value !=
null && row.Cells[
this.dataGridViewTextBoxColumnContextName.Name].Value.Equals(withPrefix ? (document.Package.FullName +
"." + document.Name +
"." + contextVariable.Name) : contextVariable.Name))
2648 if (radioButtonDefaultImplementation.Checked)
2650 object contextVariableValue = this.contextVariableImplementation.GetValue(
null, contextVariable,
null);
2651 row.Cells[this.dataGridViewTextBoxColumnContextValue.Name].Value = contextVariableValue !=
null ? ConvertValue2String(contextVariableValue) : null;
2655 row.Cells[this.dataGridViewTextBoxColumnContextValue.Name].Value = contextVariable.InitValue !=
null ? ConvertValue2String(contextVariable.InitValue) : null;
2658 bValueWasSet =
true;
2666 object[] values =
null;
2667 values =
new object[] { withPrefix ? (document.Package.FullName +
"." + document.Name +
"." + contextVariable.Name) : contextVariable.Name, contextVariable.DataType };
2668 int index = this.gridViewContext.Rows.Add(values);
2670 object contextVariableValue = contextVariable.InitValue;
2672 this.gridViewContext.Rows[index].Tag = contextVariable;
2673 this.gridViewContext.Rows[index].ReadOnly = contextVariable.InitValue ==
null;
2674 this.gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name].Tag = contextVariable.InitValue;
2675 if (contextVariable.DataType.Equals(
"Boolean"))
2677 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name] =
new DataGridViewCheckBoxCell();
2678 DataGridViewCheckBoxCell cell = gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name] as DataGridViewCheckBoxCell;
2679 cell.Value = ConvertValue2String(contextVariableValue);
2680 cell.Tag = contextVariableValue;
2682 else if(contextVariableValue is EnumerationElement)
2684 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name] =
new DataGridViewComboBoxCell();
2685 DataGridViewComboBoxCell cell = gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name] as DataGridViewComboBoxCell;
2686 cell.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
2687 cell.FlatStyle = FlatStyle.Flat;
2688 cell.DisplayMember =
"Name";
2689 cell.ValueMember =
"Name";
2690 cell.DataSource = (contextVariableValue as EnumerationElement).Enumeration.Elements;
2691 cell.Value = ConvertValue2String(contextVariableValue);
2692 cell.Tag = contextVariableValue;
2698 if (contextVariableValue !=
null)
2700 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name].Value = ConvertValue2String(contextVariableValue);
2704 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name].Value =
null;
2707 catch (System.Exception ex)
2709 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextValue.Name].ErrorText = ex.Message;
2713 gridViewContext.Rows[index].Cells[dataGridViewTextBoxColumnContextDetails.Name].Value = GetDetails(contextVariableValue);
2719 foreach (IDocument importDoc
in document.Imports)
2721 UpdateGridViewContextVariable(importDoc,
true, listItemsReviewed);
2724 catch (System.Exception ex)
2731 private void StateVariableValueChanged(IStateVariable stateVariable,
object value)
2733 if (this.InvokeRequired)
2735 this.Invoke(
new Action(() => StateVariableValueChanged(stateVariable, value)));
2739 string mappingStr = String.Format(
"[MappedTo: {0}{1}]",
2740 stateVariable.MappingName,
2741 (stateVariable.MappingIndex > -1 ?
"[" + stateVariable.MappingIndex +
"]" : String.Empty));
2742 string strValue =
"null";
2745 strValue = ValueConverter.Value2String(value);
2751 string outputLog = String.Format(
"StateVariableChanged({0} {1}.{2}{3} = {4})",
2752 stateVariable.DataType,
2753 stateVariable.Document.FullName,
2757 PrintText(outputLog);
2758 UpdateGridViewStateVariable(stateVariable);
2761 private void ContextVariableRead(IContextVariable contextVariable,
object value)
2763 if (this.InvokeRequired)
2765 this.Invoke(
new Action(() => ContextVariableRead(contextVariable, value)));
2769 string mappingStr = String.Format(
"[MappedTo: {0}{1}]",
2770 contextVariable.MappingName,
2771 (contextVariable.MappingIndex > -1 ?
"[" + contextVariable.MappingIndex +
"]" : String.Empty));
2772 string strValue =
"null";
2775 strValue = ValueConverter.Value2String(value);
2780 string outputLog = String.Format(
"ContextVariableRead({0} {1}.{2}{3} = {4})",
2781 contextVariable.DataType,
2782 contextVariable.Document.FullName,
2783 contextVariable.Name,
2787 PrintText(outputLog);
2790 private void UpdateGridViewStateVariable(IDocument document,
bool withPrefix, List<string> listItemsReviewed)
2792 string @
namespace = string.Concat(document.Package.Name, ".", document.Name);
2793 if (listItemsReviewed.Contains(@
namespace))
2798 listItemsReviewed.Add(@
namespace);
2799 foreach (IStateVariable stateVariable
in document.StateVariables)
2801 object[] values =
null;
2802 values =
new object[] { withPrefix ? (document.Package.FullName +
"." + document.Name +
"." + stateVariable.Name) : stateVariable.Name, stateVariable.DataType };
2803 int index = this.gridViewState.Rows.Add(values);
2805 this.gridViewState.Rows[index].Tag = stateVariable;
2807 if (stateVariable.DataType.Equals(
"Boolean"))
2809 gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name] =
new DataGridViewCheckBoxCell();
2810 DataGridViewCheckBoxCell cell = gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name] as DataGridViewCheckBoxCell;
2811 cell.Value = ConvertValue2String(stateVariable.InitValue);
2812 cell.Tag = stateVariable.InitValue;
2814 else if (stateVariable.InitValue is EnumerationElement)
2816 gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name] =
new DataGridViewComboBoxCell();
2817 DataGridViewComboBoxCell cell = gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name] as DataGridViewComboBoxCell;
2818 cell.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
2819 cell.FlatStyle = FlatStyle.Flat;
2820 cell.DisplayMember =
"Name";
2821 cell.ValueMember =
"Name";
2822 cell.DataSource = (stateVariable.InitValue as EnumerationElement).Enumeration.Elements;
2823 cell.Value = ConvertValue2String(stateVariable.InitValue);
2824 cell.Tag = stateVariable.InitValue;
2830 if (stateVariable.InitValue !=
null)
2832 gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name].Value = ConvertValue2String(stateVariable.InitValue);
2835 catch (System.Exception ex)
2837 gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateValue.Name].ErrorText = ex.Message;
2841 if (stateVariable.InitValue !=
null)
2843 gridViewState.Rows[index].Cells[dataGridViewTextBoxColumnStateDetails.Name].Value = GetDetails(stateVariable.InitValue);
2849 foreach (IDocument importDoc
in document.Imports)
2851 UpdateGridViewStateVariable(importDoc,
true, listItemsReviewed);
2854 catch (System.Exception ex)
2862 private void UpdateGridViewStateVariable(IStateVariable stateVar)
2864 if (stateVar ==
null)
2870 foreach (DataGridViewRow row
in this.gridViewState.Rows)
2872 if (row.Cells[
this.dataGridViewTextBoxColumnStateName.Name].Value !=
null && row.Tag == stateVar)
2874 object stateVariableValue =
null;
2876 if (radioButtonDefaultImplementation.Checked)
2877 stateVariableValue = this.stateVariableImplementation.GetValue(stateVar);
2879 stateVariableValue = stateVar.InitValue;
2881 if (stateVariableValue !=
null)
2885 row.Cells[this.dataGridViewTextBoxColumnStateValue.Name].Value = ConvertValue2String(stateVariableValue);
2887 catch (System.Exception ex)
2889 row.Cells[this.dataGridViewTextBoxColumnStateValue.Name].ErrorText = ex.Message;
2892 row.Cells[this.dataGridViewTextBoxColumnStateDetails.Name].Value = GetDetails(stateVariableValue);
2896 row.Cells[this.dataGridViewTextBoxColumnStateValue.Name].Value =
null;
2897 row.Cells[this.dataGridViewTextBoxColumnStateDetails.Name].Value =
string.Empty;
2903 Application.DoEvents();
2906 private void buttonNewInstance_Click(
object sender, EventArgs e)
2908 Form form =
new SampleForm(SampleConstants.CHILD_INSTANCE_NAME,
this);
2912 private void buttonNewInstanceNewThread_Click(
object sender, EventArgs e)
2914 Thread thread =
new Thread(
new ThreadStart(NewInstanceInThread));
2915 thread.SetApartmentState(ApartmentState.STA);
2919 private void NewInstanceInThread()
2921 Application.Run(
new SampleForm(SampleConstants.CHILD_INSTANCE_NAME,
this));
2924 private void buttonHmi_Click(
object sender, EventArgs e)
2926 if (this.buttonHmi.Checked)
2928 hmiWindow =
new HmiWindow();
2929 hmiWindow.FormClosing += HmiWindow_FormClosing;
2930 hmiWindow.SizeChanged += HmiWindow_SizeChanged;
2931 hmiWindow.Activated += HmiWindow_Activated;
2934 hmiWindow.Size =
new Size(userSettings.HmiWindowWidth, userSettings.HmiWindowHeight);
2935 hmiWindow.Location =
new Point(this.Location.X +
this.Size.Width,
this.Location.Y);
2936 if (this.creatorForm !=
null && this.creatorForm.hmiWindow !=
null)
2938 this.hmiWindow.Size = this.creatorForm.hmiWindow.Size;
2941 hmiWindow.BringToFront();
2943 customScreenImplementation.HmiScreenContainer = this.hmiWindow.HmiControl;
2945 else if (this.hmiWindow !=
null)
2947 this.hmiWindow.Close();
2950 SyncWithParent(this.creatorForm?.buttonHmi, this.buttonHmi);
2953 private void HmiWindow_FormClosing(
object sender, FormClosingEventArgs e)
2955 customScreenImplementation.HmiScreenContainer =
null;
2956 this.hmiWindow =
null;
2958 this.buttonHmi.Checked =
false;
2961 private void HmiWindow_Activated(
object sender, EventArgs e)
2963 if (customScreenImplementation !=
null)
2965 customScreenImplementation.ActivateHmiScreen();
2969 private void HmiWindow_SizeChanged(
object sender, EventArgs e)
2971 userSettings.HmiWindowWidth = this.hmiWindow.Width;
2972 userSettings.HmiWindowHeight = this.hmiWindow.Height;
2974 if (customScreenImplementation !=
null)
2976 customScreenImplementation.RefreshHmiScreen();
2980 private void CustomScreenImplementation_KeyDown(Runtime.Api.Custom.KeyEventArgs e)
2982 string key =
"Unknown";
2983 if (e is WpfKeyEventArgs)
2985 WpfKeyEventArgs wpfArgs = e as WpfKeyEventArgs;
2986 key = wpfArgs.Key.ToString();
2987 if (wpfArgs.ModifierKey == System.Windows.Input.ModifierKeys.Alt &&
2988 wpfArgs.Key == System.Windows.Input.Key.F4)
2992 else if (wpfArgs.Key == System.Windows.Input.Key.F10 || wpfArgs.Key == System.Windows.Input.Key.LeftAlt || wpfArgs.Key == System.Windows.Input.Key.RightAlt)
2997 else if (e is FormKeyEventArgs)
2999 FormKeyEventArgs formArgs = e as FormKeyEventArgs;
3000 if (formArgs.ModifierKey == Keys.Alt &&
3001 formArgs.Key == Keys.F4)
3005 else if (formArgs.Key == Keys.F10 || formArgs.Key == Keys.Alt)
3009 key = formArgs.Key.ToString();
3012 this.PrintText(
"CustomScreenImplementation_KeyDown(" + key +
")");
3016 private void SampleForm_FormClosing(
object sender, FormClosingEventArgs e)
3018 listForms.Remove(
this);
3021 if (this.globalRuntimeManager !=
null)
3023 this.globalRuntimeManager.StopAll();
3024 this.globalRuntimeManager.ProcedurePending -= ProcedurePending;
3025 this.globalRuntimeManager.ProcedureStarted -= ProcedureStarted;
3026 this.globalRuntimeManager.ProcedurePaused -= ProcedurePaused;
3027 this.globalRuntimeManager.ProcedureContinued -= ProcedureContinued;
3028 this.globalRuntimeManager.ProcedureFinished -= ProcedureFinished;
3029 this.globalRuntimeManager.ProcedureStopped -= ProcedureStopped;
3030 this.globalRuntimeManager.ProcedureAborted -= ProcedureAborted;
3031 this.globalRuntimeManager.InOutParameterValueChanged -= InOutParameterValueChanged;
3034 this.stateVariableImplementation.StateVariableValueChanged -= StateVariableValueChanged;
3036 basicScreenOutputImpl.LogEvent -= PrintText;
3037 customScreenOutputImpl.LogEvent -= PrintText;
3038 loggingOutputImpl.LogEvent -= PrintText;
3039 contextVariableOutputImpl.LogEvent -= PrintText;
3041 stateVariableOutputImpl.LogEvent -= PrintText;
3042 measureOutputImpl.LogEvent -= PrintText;
3043 i18NOutputImpl.LogEvent -= PrintText;
3044 serviceProviderOutputImpl.LogEvent -= PrintText;
3046 sqlOutputImpl.LogEvent -= PrintText;
3047 commonDialogsOutputImpl.LogEvent -= PrintText;
3052 private void SaveSettings()
3054 if (this.creatorForm ==
null)
3057 userSettings.Ptx_Ppx_Directory = cbFilePath.Text.Trim();
3058 userSettings.Ptx_Ppx_DirectoryList =
string.Join(
";", this.cbFilePath.Items.Cast<Object>().Select(item => item.ToString()).ToArray());
3060 userSettings.TraceFileMaxCount = Convert.ToInt32(this.textBoxTraceFileMaxCount.Text.Trim());
3061 userSettings.TraceFileMaxSize = Convert.ToInt32(this.textBoxTraceFileMaxSize.Text.Trim());
3062 userSettings.TraceLevels = RuntimeConfig.Instance.TraceLevel;
3063 userSettings.TracingDirectory = textBoxTraceFolder.Text.Trim();
3065 userSettings.WindowWidth = this.Size.Width;
3066 userSettings.WindowHeight = this.Size.Height;
3067 userSettings.WindowLocationX = this.Location.X;
3068 userSettings.WindowLocationY = this.Location.Y;
3069 userSettings.CustomImplTypes = GetCurrentCustomImpl();
3070 SaveSocketPortOrPipeName();
3072 userSettings.Asynchron = checkBoxAsyncExecution.Checked;
3073 userSettings.Cyclic = checkBoxCyclicExecution.Checked;
3074 userSettings.CyclicReload = checkBoxCyclicReload.Checked;
3075 userSettings.NewRunTimeManager = checkBoxNewRuntimeManager.Checked;
3076 userSettings.AddMessageToOutput = checkBoxAdd2Output.Checked;
3077 userSettings.StartAllParents = checkBoxStartAllParents.Checked;
3079 userSettings.TimeOut = (ulong)Convert.ToInt32(
this.textBoxTimeout.Text.Trim());
3080 userSettings.ConnectionState = checkBoxUseConnectionState.Checked;
3081 userSettings.Ignition = checkBoxIgnition.CheckState == CheckState.Checked ? 1 : (checkBoxIgnition.CheckState == CheckState.Unchecked ? 0 : -1);
3082 userSettings.PollingTime = Convert.ToInt32(this.textBoxPollingTime.Text.Trim());
3083 userSettings.VoltageThreshold = Convert.ToInt32(this.textBoxVoltageThreshold.Text.Trim());
3085 userSettings.RuntimeContextName = this.textBoxRuntimeContextName.Text.Trim();
3087 SaveSettingUtil.Save();
3091 private void SaveSocketPortOrPipeName()
3093 var ipcType = (IpcTypes)comboBoxIpcType.SelectedItem;
3097 case IpcTypes.SOCKET:
3101 userSettings.DiagManagerPort = Convert.ToUInt16(textBoxDiagPortPipe.Text.Trim());
3102 userSettings.RuntimePort = Convert.ToUInt16(textBoxRtPortPipe.Text.Trim());
3103 userSettings.IpcType = IpcTypes.SOCKET.ToString();
3105 catch (System.Exception)
3107 userSettings.DiagManagerPort = SampleConstants.DEFAULT_DM_PORT;
3108 userSettings.RuntimePort = SampleConstants.DEFAULT_RT_PORT;
3115 string diagManagerPipeName = textBoxDiagPortPipe.Text.Trim();
3116 string runtimePipeName = textBoxRtPortPipe.Text.Trim();
3118 userSettings.DiagManagerPipeName = (diagManagerPipeName !=
string.Empty) ? diagManagerPipeName : SampleConstants.DEFAULT_DM_PIPE_NAME;
3119 userSettings.RuntimePipeName = (runtimePipeName !=
string.Empty) ? runtimePipeName : SampleConstants.DEFAULT_RT_PIPE_NAME;
3120 userSettings.IpcType = IpcTypes.PIPE.ToString();
3129 private void textBoxRuntimeContextName_TextChanged(
object sender, EventArgs e)
3131 this.runtimeContextName = this.textBoxRuntimeContextName.Text = this.textBoxRuntimeContextName.Text.Trim();
3132 SetTitle(this.title);
3135 private void listBoxOuput_SelectedIndexChanged(
object sender, EventArgs e)
3137 this.buttonCopyRow.Enabled = this.listBoxOuput.SelectedItems.Count > 0;
3140 private void buttonPause_Click(
object sender, EventArgs e)
3142 lock (this.runtimeContexts)
3144 if (this.buttonPause.Checked)
3146 foreach (IRuntimeContext runtimeContext
in this.runtimeContexts)
3150 runtimeContext.Pause();
3156 foreach (IRuntimeContext runtimeContext
in this.runtimeContexts)
3160 runtimeContext.Continue();
3166 SyncWithParent(this.creatorForm?.buttonPause, this.buttonPause);
3169 private void AddRuntimeContext(IRuntimeContext context)
3171 lock (this.runtimeContexts)
3173 if (!this.runtimeContexts.Contains(context))
3175 this.runtimeContexts.Add(context);
3178 if (!runtimeContextsExecutionStartTime.ContainsKey(context))
3180 runtimeContextsExecutionStartTime.Add(context, DateTime.Now);
3185 private void RemoveRuntimeContext(IRuntimeContext context)
3187 lock (this.runtimeContexts)
3189 if (this.runtimeContexts.Contains(context))
3191 this.runtimeContexts.Remove(context);
3194 if (runtimeContextsExecutionStartTime.ContainsKey(context))
3196 runtimeContextsExecutionStartTime.Remove(context);
3201 private bool IsPauseEnabled()
3203 lock (this.runtimeContexts)
3205 foreach (IRuntimeContext runtimeContext
in this.runtimeContexts)
3217 private bool IsContinueEnable()
3219 lock (this.runtimeContexts)
3221 foreach (IRuntimeContext runtimeContext
in this.runtimeContexts)
3233 private void SetExpectedState()
3235 if (this.useConnectionState)
3237 if (this.KL15State ==
null)
3241 else if (this.KL15State.Value)
3256 private void checkBoxUseConnectionState_CheckedChanged(
object sender, EventArgs e)
3258 this.useConnectionState = this.checkBoxUseConnectionState.Checked;
3259 this.EnableConnectionState();
3260 this.SetExpectedState();
3262 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBattery16;
3263 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnition16;
3265 SyncWithParent(this.creatorForm?.checkBoxUseConnectionState, this.checkBoxUseConnectionState);
3268 private void CheckBoxKL15_CheckStateChanged(
object sender, System.EventArgs e)
3270 switch (this.checkBoxIgnition.CheckState)
3272 case CheckState.Checked:
3273 this.KL15State =
true;
3275 case CheckState.Unchecked:
3276 this.KL15State =
false;
3279 this.KL15State =
null;
3283 this.SetExpectedState();
3285 SyncWithParent(this.creatorForm?.checkBoxIgnition, this.checkBoxIgnition);
3288 private void EnableConnectionState()
3290 this.labelExpectedState.Enabled = this.useConnectionState;
3291 this.labelBatteryState.Enabled = this.useConnectionState;
3292 this.checkBoxIgnition.Enabled = this.useConnectionState;
3293 this.labelPollingTime.Enabled = this.useConnectionState;
3294 this.textBoxPollingTime.Enabled = this.useConnectionState;
3295 this.labelVoltageThreshold.Enabled = this.useConnectionState;
3296 this.textBoxVoltageThreshold.Enabled = this.useConnectionState;
3297 this.buttonCheckBatteryIgnition.Enabled = this.useConnectionState;
3300 private void buttonCheckBatteryIgnition_Click(
object sender, EventArgs e)
3302 CheckBatteryIgnitionState(this.globalRuntimeManager);
3304 SyncWithParent(this.creatorForm?.buttonCheckBatteryIgnition, this.buttonCheckBatteryIgnition);
3307 private void textBoxPollingTime_TextChanged(
object sender, EventArgs e)
3311 if (Convert.ToInt32(
this.textBoxPollingTime.Text) <= 0)
3313 this.textBoxPollingTime.Text = defaultPollingTime.ToString();
3318 this.textBoxPollingTime.Text = defaultPollingTime.ToString();
3321 SyncWithParent(this.creatorForm?.textBoxPollingTime, this.textBoxPollingTime);
3324 private void textBoxBatteryVoltageThreshold_TextChanged(
object sender, EventArgs e)
3328 if (Convert.ToInt32(
this.textBoxVoltageThreshold.Text) <= 0)
3330 this.textBoxVoltageThreshold.Text = defaultBatteryVoltageThreshold.ToString();
3335 this.textBoxVoltageThreshold.Text = defaultBatteryVoltageThreshold.ToString();
3338 SyncWithParent(this.creatorForm?.textBoxVoltageThreshold, this.textBoxVoltageThreshold);
3341 private void CheckBatteryIgnitionState(IRuntimeManager runtimeManager)
3343 if (this.useConnectionState)
3345 runtimeManager.DiagConnectionState.PollingTime = Convert.ToInt32(this.textBoxPollingTime.Text);
3346 runtimeManager.DiagConnectionState.BatteryVoltageThreshold = Convert.ToInt32(this.textBoxVoltageThreshold.Text);
3347 ClampState batteryState = runtimeManager.DiagConnectionState.BatteryState;
3348 ClampState ignitionState = runtimeManager.DiagConnectionState.IgnitionState;
3350 SetBatteryIgnitionState(batteryState, ignitionState);
3352 PrintText(
"Check DiagConnection State - BatteryState = " + batteryState.ToString() +
", IgnitionState = " + ignitionState.ToString());
3356 private void SetBatteryIgnitionState(ClampState batteryState, ClampState ignitionState)
3358 switch (batteryState)
3361 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBatteryNotAvailable16;
3364 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBatteryOff16;
3367 this.labelBatteryState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconBatteryOn16;
3371 switch (ignitionState)
3374 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnitionNotAvailable16;
3377 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnitionOff16;
3380 this.labelIgnitionState.Image =
OpenTestSystem.
Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.IconIgnitionOn16;
3385 private void ShowConnectionStateMessage(IRuntimeContext runtimeContext)
3387 if (runtimeContext !=
null)
3389 System.Media.SystemSounds.Beep.Play();
3391 switch (this.expectedConnectionState)
3394 this.PrintText(
"----------------------------------------------------------------------------------------------------------------------------------------------");
3395 this.PrintText(
"-- Not expected connection state: Either it is not possible to communicate with the VCI or the battery is not connected. Please connect it! --");
3396 this.PrintText(
"----------------------------------------------------------------------------------------------------------------------------------------------");
3399 this.PrintText(
"------------------------------------------------------------------------------------");
3400 this.PrintText(
"-- Not expected connection state: The ignition must be OFF. Please switch it OFF! --");
3401 this.PrintText(
"------------------------------------------------------------------------------------");
3404 this.PrintText(
"----------------------------------------------------------------------------------");
3405 this.PrintText(
"-- Not expected connection state: The ignition must be ON. Please switch it ON! --");
3406 this.PrintText(
"----------------------------------------------------------------------------------");
3414 private void checkBoxAdd2Output_CheckedChanged(
object sender, EventArgs e)
3416 SyncWithParent(this.creatorForm?.checkBoxAdd2Output, this.checkBoxAdd2Output);
3419 private void ParentNumericUpDownSetValue(NumericUpDown numericUpDown,
int value)
3421 var action =
new Action(() => numericUpDown.Value = value);
3422 if (numericUpDown.InvokeRequired)
3423 this.creatorForm.Invoke(action);
3428 private void comboBoxTraceLevel_SelectedIndexChanged(
object sender, EventArgs e)
3430 SyncWithParent(this.creatorForm?.comboBoxTraceLevel, this.comboBoxTraceLevel);
3432 private void txtPassword_TextChanged(
object sender, EventArgs e)
3434 SyncWithParent(this.creatorForm?.txtPassword, this.txtPassword);
3437 private void textBoxTimeout_TextChanged(
object sender, EventArgs e)
3439 SyncWithParent(this.creatorForm?.textBoxTimeout, this.textBoxTimeout);
3442 private void textBoxTraceFileMaxSize_TextChanged(
object sender, EventArgs e)
3444 if (globalRuntimeManager ==
null)
3447 PrintText(
"Set TraceFileMaxSize to " + this.textBoxTraceFileMaxSize.Text);
3451 RuntimeConfig.Instance.TraceFileMaxSize = Convert.ToInt32(this.textBoxTraceFileMaxSize.Text);
3452 SyncWithParent(this.creatorForm?.textBoxTraceFileMaxSize, this.textBoxTraceFileMaxSize);
3455 catch (System.Exception ex)
3458 this.textBoxTraceFileMaxSize.Text = RuntimeConfig.Instance.TraceFileMaxSize.ToString();
3462 private void textBoxTraceFileMaxCount_TextChanged(
object sender, EventArgs e)
3464 if (globalRuntimeManager ==
null)
3467 PrintText(
"Set TraceFileMaxCount to " + this.textBoxTraceFileMaxCount.Text);
3471 RuntimeConfig.Instance.TraceFileMaxCount = Convert.ToInt32(this.textBoxTraceFileMaxCount.Text);
3472 SyncWithParent(this.creatorForm?.textBoxTraceFileMaxCount, this.textBoxTraceFileMaxCount);
3474 catch (System.Exception ex)
3477 this.textBoxTraceFileMaxCount.Text = RuntimeConfig.Instance.TraceFileMaxCount.ToString();
3481 private void WebServerTimer_Tick(
object sender, EventArgs e)
3483 this.UpdateWebServerButton();
3486 int isStartWebSever = -1;
3487 private void UpdateWebServerButton()
3489 if (this.InvokeRequired)
3491 this.Invoke(
new Action(() => UpdateWebServerButton()));
3495 if (customScreenImplementation ==
null)
3497 this.buttonStartStopWebServer.Enabled =
false;
3501 this.buttonStartStopWebServer.Enabled =
true;
3502 if (DefaultCustomScreenImplementation.IsStartedHtmlWebserver())
3504 if (isStartWebSever == 1)
3509 this.buttonStartStopWebServer.Image = global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.StopWebServer;
3510 isStartWebSever = 1;
3514 if (isStartWebSever == 0)
3519 this.buttonStartStopWebServer.Image = global::OpenTestSystem.Otx.Runtime2.Api.DotNet.Sample.Properties.Resources.StartWebServer;
3520 isStartWebSever = 0;
3524 private void buttonStartStopWebServer_Click(
object sender, EventArgs e)
3526 if (this.InvokeRequired)
3528 this.Invoke(
new Action(() => buttonStartStopWebServer_Click(sender, e)));
3532 if (customScreenImplementation ==
null)
3537 if (!DefaultCustomScreenImplementation.IsStartedHtmlWebserver())
3539 customScreenImplementation.StartHtmlWebServer();
3543 customScreenImplementation.StopHtmlWebServer();
3547 private void buttonLicense_Click(
object sender, EventArgs e)
3549 LicenseForm licenseForm =
new LicenseForm(
this);
3550 licenseForm.ShowDialog(
this);
3553 public void ReloadRuntimeManager()
3557 String licenseKeyFromOTForOTPLicense =
OpenTestSystem.Common.LicensingV5.Util.CreateLicenseKeyFromOTForOTPLicense();
3558 if (!String.IsNullOrEmpty(licenseKeyFromOTForOTPLicense) && LicensingUtil.CheckLicenseKeyFormat(licenseKeyFromOTForOTPLicense))
3560 LicenseManager.SetLicenseKey(licenseKeyFromOTForOTPLicense);
3563 this.globalRuntimeManager = CreateRuntimeManager();
3567 catch (System.Exception ex)
3570 PrintText(
"No RuntimeManager created");
Namespace containing all interfaces for custom implementations
Definition: IBasicScreenImplementation.cs:7
Namespace which contains all supported data types
Definition: BlackBox.cs:5
Namespace containing exceptions
Definition: ConnectionStateException.cs:7
Namespace containing all objects related to licensing
Definition: IpcLicenseCheckerBase.cs:10
Namespace for browsing at OTX data structure.
Definition: IContextVariable.cs:5
Namespace containing main entries: IProject and IPlayerProject.
Definition: IPlayerProject.cs:5
Namespace containing the programming interface for browsing and execution of OTX procedures in own ap...
Definition: ApiConstants.cs:5
ExecutionStateChangeReason
Reason, why a procedure execution state was changed, e.g. Paused or Running
Definition: ExecutionStateChangeReason.cs:13
ClampState
Contains the state of a clamp
Definition: ClampState.cs:13
ExecutionState
Contains the state of the runtime context.
Definition: ExecutionState.cs:7
ExpectedState
Contains the expected state of the diagnostic connection
Definition: ExpectedState.cs:13
Namespace containing all objects for browsing and execution of OTX procedures
Definition: ApiConstants.cs:5
Namespace containing all objects which are standardized according to ISO 13209 (OTX)
Namespace containing all objects related to testing inside automotive industry