/// <summary> /// Event handler associated with the timer <c>Tick</c> event. Get the time and date from the VCU and update the corresponding form labels. /// </summary> /// <param name="sender">Reference to the object that raised the event.</param> /// <param name="e">Parameter passed from the object that raised the event.</param> private void DisplayUpdate(object sender, EventArgs e) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } DateTime dateTime = DateTime.Now; try { CommunicationInterface.GetTimeDate(Parameter.Use4DigitYearCode, out dateTime); } catch (CommunicationException) { m_TimerDisplayUpdate.Stop(); MainWindow.WriteStatusMessage(Resources.EMCommunicationsLoss, Color.Red, Color.Black); CommunicationInterface.CloseCommunication(CommunicationInterface.CommunicationSetting.Protocol); // This resets the main screen so that the user has to reconnect to target hardware MainWindow.SetMode(Mode.Configuration); MainWindow.CommunicationInterface = null; } MainWindow.BlinkUpdateIcon(); m_LabelDate.Text = dateTime.ToShortDateString(); m_LabelTime.Text = dateTime.ToString(FormatStringTime); m_DateTime = dateTime; }
/// <summary> /// The background worker task. Download the data stream corresponding to the event record specified in the constructor and update the DataSteamCurrent property /// of the FormViewEventLog class. /// </summary> /// <param name="sender">Reference to the object that raised the event.</param> /// <param name="e">Parameter passed from the object that raised the event.</param> private void m_BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } DataStream_t dataStream; try { dataStream = CommunicationInterface.GetStream(m_EventRecord); } catch (Exception) { DialogResult = DialogResult.Abort; return; } // Get the reference to the calling form. FormViewEventLog calledFromAsFormViewEventLog = CalledFrom as FormViewEventLog; if (calledFromAsFormViewEventLog != null) { // Update the DataStreamCurrent property of the form. calledFromAsFormViewEventLog.DataStreamCurrent = dataStream; } }
/// <summary> /// Event handler for the Apply button <c>Click</c> event. Update the date and time on the VCU according to which radio button option has been /// selected. /// </summary> /// <param name="sender">Reference to the object that raised the event.</param> /// <param name="e">Parameter passed from the object that raised the event.</param> private void m_ButtonApply_Click(object sender, EventArgs e) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } DateTime newDateTime; if (m_RadioButtonAuto.Checked == true) { // Update the target hardware using the PC time. newDateTime = DateTime.Now; } else { newDateTime = new DateTime(m_DateTimePickerDate.Value.Year, m_DateTimePickerDate.Value.Month, m_DateTimePickerDate.Value.Day, m_DateTimePickerTime.Value.Hour, m_DateTimePickerTime.Value.Minute, m_DateTimePickerTime.Value.Second); } try { CommunicationInterface.SetTimeDate(Parameter.Use4DigitYearCode, newDateTime); } catch (CommunicationException) { m_TimerDisplayUpdate.Stop(); MessageBox.Show(Resources.MBTDateTimeSetFailed, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } m_ButtonApply.Enabled = false; DialogResult = DialogResult.Yes; }
/// <summary> /// Event handler associated with the timer <c>Tick</c> event. Get the time and date from the VCU and update the corresponding form labels. /// </summary> /// <param name="sender">Reference to the object that raised the event.</param> /// <param name="e">Parameter passed from the object that raised the event.</param> private void DisplayUpdate(object sender, EventArgs e) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } DateTime dateTime = DateTime.Now; try { CommunicationInterface.GetTimeDate(Parameter.Use4DigitYearCode, out dateTime); } catch (CommunicationException) { m_TimerDisplayUpdate.Stop(); MessageBox.Show(Resources.MBTDateTimeGetFailed, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); MainWindow.WriteStatusMessage(string.Empty); Close(); return; } MainWindow.BlinkUpdateIcon(); m_LabelDate.Text = dateTime.ToShortDateString(); m_LabelTime.Text = dateTime.ToString(FormatStringTime); m_DateTime = dateTime; if (m_RadioButtonAuto.Checked == true) { // Reset the DateTime picker to the PC Time and Date properties. m_DateTimePickerDate.Value = DateTime.Now; m_DateTimePickerTime.Value = DateTime.Now; } }
public Device(CommunicationInterface communicationInterface, RequestInterface requestInterface) { CommunicationInterface = communicationInterface; RequestInterface = requestInterface; EventManager = new DeviceEventManager(this); RequestManager = new DeviceRequestManager(this); ResponseManager = new DeviceResponseManager(this); }
public ServerDevice(CommunicationInterface communicationInterface) : base(communicationInterface, new ServerRequestInterface()) { Guid = Guid.NewGuid(); while (DeviceFactory.Instance.ContainsDeviceGuid(Guid)) { Guid = Guid.NewGuid(); } }
public EndPoint(CommunicationInterface communicationInterface, OperationInterface operationInterface) { CommunicationInterface = communicationInterface; OperationInterface = operationInterface; EventManager = new EndPointEventManager(this); OperationManager = new EndPointOperationManager(this); ResponseManager = new EndPointResponseManager(this); }
public ServerEndPoint(CommunicationInterface communicationInterface) : base(communicationInterface, new ServerOperationInterface()) { Guid = Guid.NewGuid(); while (EndPointFactory.Instance.ContainsEndPointGuid(Guid)) { Guid = Guid.NewGuid(); } WaitingPlayerCounter.OnWaitingPlayerCountUpdated += EventManager.SyncDataBroker.SyncWaitingPlayerCount; }
public Programmer(CommunicationInterface com, ChipDef chip, Frequency OscFreq) { this.com = com; this.chipDef = chip; this.oscFreq = (uint)OscFreq; WRITE_TO_RAM_STRING_BYTES = Encoding.UTF8.GetBytes(WRITE_TO_RAM_STRING); PREPARE_SECTORS_BYTES = Encoding.UTF8.GetBytes("P 0 " + (chipDef.sectorCount - 1) + "\r\n"); COPY_TO_RAM_STRING = " " + FIRST_PROGRAMMABLE_RAM_ADDRESS.ToString() + " " + PROGRAMMBLE_SIZE.ToString() + "\r\n"; VERIFY_STRING = " " + PROGRAMMBLE_SIZE.ToString() + "\r\n"; }
/// <summary> /// The background worker task. Download the event history associated with the current event log and update the EventStatusList property of the /// FormShowEventHistory class. /// </summary> /// <param name="sender">Reference to the object that raised the event.</param> /// <param name="e">Parameter passed from the object that raised the event.</param> private void m_BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } // --------------------------------------------------------------- // Get the history information associated with the current log. // --------------------------------------------------------------- int eventCount = (short)m_EventRecordList.Count; int maxEventCount = m_Log.MaxEventsPerTask * m_Log.MaxTasks; // Initialize the validFlags array to define which of the events are used in the current log. short[] validFlags = new short[maxEventCount]; int eventIndex; for (int index = 0; index < m_EventRecordList.Count; index++) { eventIndex = m_EventRecordList[index].TaskIdentifier * m_Log.MaxEventsPerTask + m_EventRecordList[index].EventIdentifier; validFlags[eventIndex] = CommonConstants.True; } short[] cumulativeHistoryCounts = new short[eventCount]; short[] recentHistoryCounts = new short[eventCount]; CommunicationInterface.GetFltHistInfo(validFlags, ref cumulativeHistoryCounts, ref recentHistoryCounts, m_Log.MaxTasks, m_Log.MaxEventsPerTask); // --------------------------------- // Initialise the event status list. // --------------------------------- List <EventStatus_t> eventStatusList = new List <EventStatus_t>(eventCount); EventStatus_t eventStatus; for (int eventStatusIndex = 0; eventStatusIndex < eventCount; eventStatusIndex++) { eventStatus = new EventStatus_t(); eventStatus.Index = eventStatusIndex; eventStatus.Identifier = m_EventRecordList[eventStatusIndex].Identifier; eventStatus.CumulativeHistoryCount = cumulativeHistoryCounts[eventStatusIndex]; eventStatus.RecentHistoryCount = recentHistoryCounts[eventStatusIndex]; eventStatusList.Add(eventStatus); } // Get the reference to the calling form. FormShowEventHistory calledFromAsFormShowEventHistory = CalledFrom as FormShowEventHistory; Debug.Assert(calledFromAsFormShowEventHistory != null, "FormGetFltHistInfo.m_BackgroundWorker_DoWork() - [calledFromAsFormShowEventHistory != null]"); // Update the EventStatusList property of the form. calledFromAsFormShowEventHistory.EventStatusList = eventStatusList; }
/// <summary> /// Event handler for the <c>Shown</c> event. Get the target configuration from the VCU and update the appropriate form labels. /// </summary> /// <param name="sender">Reference to the object that raised the event.</param> /// <param name="e">Parameter passed from the object that raised the event.</param> private void FormShowSystemInformation_Shown(object sender, EventArgs e) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } Update(); // Ensure that an exception isn't thrown when a child form is opened in the Visual Studio development environment. if (MainWindow == null) { return; } // ------------------------------------------------------------------------------------------------------------------------------------ // Do not initiate any communication requests until the communication associated with any Mdi child forms that are open have been suspended. // ------------------------------------------------------------------------------------------------------------------------------------ Debug.Assert(CommunicationInterface != null); PauseCommunication <ICommunicationApplication>(CommunicationInterface, true); TargetConfiguration_t targetConfiguration = new TargetConfiguration_t(); try { CommunicationInterface.GetEmbeddedInformation(out targetConfiguration); } catch (CommunicationException) { MainWindow.WriteStatusMessage(Resources.EMCommunicationsLoss, Color.Red, Color.Black); CommunicationInterface.CloseCommunication(CommunicationInterface.CommunicationSetting.Protocol); // This resets the main screen so that the user has to reconnect to target hardware MainWindow.SetMode(Mode.Configuration); MainWindow.CommunicationInterface = null; return; } m_LabelLogicType.Text = targetConfiguration.SubSystemName; m_LabelSoftwareVersion.Text = targetConfiguration.Version; m_LabelCarNumber.Text = targetConfiguration.CarIdentifier; DisplayUpdate(this, new EventArgs()); // The DisplayUpdate() method has the potential to close the form, therefore to avoid a NullReferenceException, ensure that the timer is still // instantiated before attempting to start it. if (m_TimerDisplayUpdate != null) { m_TimerDisplayUpdate.Start(); } }
/// <summary> /// Download the specified workset to the VCU. /// </summary> /// <param name="workset">The workset that is to be downloaded to the VCU.</param> /// <returns>A flag that indicates whether the workset was successfully downloaded to the VCU. True, if the VCU update was successful; otherwise, false.</returns> protected override bool DownloadWorkset(Workset_t workset) { // A flag that indicates whether the chart recorder update was successful. bool updateSuccess; try { CommunicationInterface.DownloadChartRecorderWorkset(workset); updateSuccess = true; } catch (Exception) { updateSuccess = false; } return(updateSuccess); }
/// <summary> /// Download the specified fault log workset to the VCU. /// </summary> /// <param name="workset">The workset that is to be downloaded to the VCU.</param> /// <returns>A flag that indicates whether the workset was successfully downloaded to the VCU. True, if the VCU update was successful; otherwise, false.</returns> protected override bool DownloadWorkset(Workset_t workset) { // A flag that indicates whether the chart recorder update was successful. bool updateSuccess; try { CommunicationInterface.SetDefaultStreamInformation(workset.SampleMultiple, workset.Column[0].OldIdentifierList); updateSuccess = true; } catch (Exception) { updateSuccess = false; } return(updateSuccess); }
public void SelectCom(CommunicationInterface com) { this.com = com; }
/// <summary> /// Initializes an new instance of the form. Defines the communication interface and then downloads the current default data stream parameters and displays these /// on the form. /// </summary> /// <param name="communicationInterface">Reference to the communication interface that is to be used to communicate with the VCU.</param> /// <param name="worksetCollection">The workset collection that is to be managed.</param> /// <param name="log">The selected event log.</param> public FormConfigureFaultLogParameters(ICommunicationParent communicationInterface, WorksetCollection worksetCollection, Log log) : base(worksetCollection) { InitializeComponent(); // Only one column is required for this workset so delete the tab pages associated with columns 2 and 3. m_TabControlColumn.TabPages.Remove(m_TabPageColumn2); m_TabControlColumn.TabPages.Remove(m_TabPageColumn3); // Move the position of the Cancel buttons. m_ButtonCancel.Location = m_ButtonApply.Location; // Check the mode of the PTU. if (communicationInterface == null) { CommunicationInterface = null; } else if (communicationInterface is CommunicationParent) { // The PTU is in online mode. CommunicationInterface = new CommunicationEvent(communicationInterface); } else { // The PTU is in simulation mode (originally referred to as offline mode). CommunicationInterface = new CommunicationEventOffline(communicationInterface); } // Don't allow the user to edit the workset until the security level of the workset has been established. ModifyEnabled = false; m_NumericUpDownSampleMultiple.Enabled = ModifyEnabled; #region - [ToolTipText] - m_ToolStrip.Items[CommonConstants.KeyToolStripButtonUpload].ToolTipText = Resources.FunctionKeyToolTipDataStreamUpload; m_ToolStrip.Items[CommonConstants.KeyToolStripButtonSave].ToolTipText = Resources.FunctionKeyToolTipDataStreamSave; m_ToolStrip.Items[CommonConstants.KeyToolStripButtonEdit].ToolTipText = Resources.FunctionKeyToolTipDataStreamConfigure; m_ToolStrip.Items[CommonConstants.KeyToolStripButtonNew].ToolTipText = Resources.FunctionKeyToolTipDataStreamCreate; m_ToolStrip.Items[CommonConstants.KeyToolStripButtonCopy].ToolTipText = Resources.FunctionKeyToolTipDataStreamCopy; m_ToolStrip.Items[CommonConstants.KeyToolStripButtonRename].ToolTipText = Resources.FunctionKeyToolTipDataStreamRename; m_ToolStrip.Items[CommonConstants.KeyToolStripButtonDelete].ToolTipText = Resources.FunctionKeyToolTipDataStreamDelete; m_ToolStrip.Items[CommonConstants.KeyToolStripButtonSetAsDefault].ToolTipText = Resources.FunctionKeyToolTipDataStreamSetAsDefault; m_ToolStrip.Items[CommonConstants.KeyToolStripButtonOverrideSecurity].ToolTipText = Resources.FunctionKeyToolTipDataStreamOverrideSecurity; #endregion - [ToolTipText] - #region - [Get the Current Data Stream from the VCU] - // This only applies if the PTU is online. Workset_t workset; if (CommunicationInterface != null) { short variableCount, pointCount, sampleMultiple; short[] watchIdentifiers, dataTypes; try { CommunicationInterface.GetDefaultStreamInformation(out variableCount, out pointCount, out sampleMultiple, out watchIdentifiers, out dataTypes); } catch (Exception) { MessageBox.Show(Resources.MBTGetDefaultStreamParametersFailed, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Convert the parameters to a workset. workset = CommunicationInterface.ConvertToWorkset("GetDefaultStreamInformation()", watchIdentifiers, sampleMultiple); // Search the list of worksets for a match. m_WorksetFromVCU = workset; m_WorksetToCompare = workset; Workset_t matchedWorkset = Workset.FaultLog.Worksets.Find(CompareWorkset); // Check whether a match was found. if (matchedWorkset.WatchItems == null) { // No - Create a new workset. workset.Name = DefaultNewWorksetName; // Set the flag to indicate that the workset does not exist and that any changes will be saved as a new workset. m_CreateMode = true; m_ComboBoxWorkset.DropDownStyle = ComboBoxStyle.DropDown; // Ensure that the TextChanged event is not triggered as a result of specifying the Text property of the TextBox control. m_TextBoxName.TextChanged -= new EventHandler(m_TextBoxName_TextChanged); m_TextBoxName.Text = workset.Name; m_TextBoxName.TextChanged += new EventHandler(m_TextBoxName_TextChanged); m_TextBoxName.Enabled = true; } else { // Yes - Update the name and security level of the workset. workset = matchedWorkset; // Set the flag to indicate that the form already exists and any changes will result in the existing workset being modified. m_CreateMode = false; m_ComboBoxWorkset.DropDownStyle = ComboBoxStyle.DropDownList; // Ensure that the TextChanged event is not triggered as a result of specifying the Text property of the TextBox control. m_TextBoxName.TextChanged -= new EventHandler(m_TextBoxName_TextChanged); m_TextBoxName.Text = workset.Name; m_TextBoxName.TextChanged += new EventHandler(m_TextBoxName_TextChanged); m_TextBoxName.Enabled = false; } } else { // Load the default workset. workset = worksetCollection.Worksets[worksetCollection.DefaultIndex]; // Set the flag to indicate that the form already exists and any changes will result in the existing workset being modified. m_CreateMode = false; m_ComboBoxWorkset.DropDownStyle = ComboBoxStyle.DropDownList; // Ensure that the TextChanged event is not triggered as a result of specifying the Text property of the TextBox control. m_TextBoxName.TextChanged -= new EventHandler(m_TextBoxName_TextChanged); m_TextBoxName.Text = workset.Name; m_TextBoxName.TextChanged += new EventHandler(m_TextBoxName_TextChanged); m_TextBoxName.Enabled = false; } #endregion - [Get the Current Data Stream from the VCU] - // Keep a record of the selected workset. This must be set up before the call to SetEnabledToolStripButtons(). m_SelectedWorkset = workset; SetEnabledToolStripButtons(true); // Update the 'Default' Image that identifies whether the selected workset is the default workset or not. m_PictureBoxDefault.Visible = (m_SelectedWorkset.Name.Equals(m_WorksetCollection.DefaultName)) ? true : false; // Display the name of the workset on the ComboBox control. // Ensure that the SelectionChanged event is not triggered as a result of specifying the Text property of the ComboBox control. m_ComboBoxWorkset.SelectedIndexChanged -= new EventHandler(m_ComboBoxWorkset_SelectedIndexChanged); m_ComboBoxWorkset.Text = workset.Name; m_ComboBoxWorkset.SelectedIndexChanged += new EventHandler(m_ComboBoxWorkset_SelectedIndexChanged); LoadWorkset(m_SelectedWorkset); // If an event log was specified, update the EntryCountMax property to reflect the actual number of watch variables associated with the current event log. if (log != null) { m_EntryCountMax = log.DataStreamTypeParameters.WatchVariablesMax; } UpdateCount(); // Check whether the 'Row Header' ListBox can be used to display the channel numbers. This is only possible if // the project doesn't support multiple data stream types and the number of parameters supported by the data // stream can be displayed on the TabPage without the need for scroll bars i.e. <= WatchSizeFaultLogMax. if ((Parameter.SupportsMultipleDataStreamTypes == false) && (Parameter.WatchSizeFaultLog <= WatchSizeFaultLogMax)) { AddRowHeader(); } else { NoRowHeader(); } // Disable all options other than save if the downloaded workset doesn't exist. if (m_CreateMode == true) { SetEnabledToolStripButtons(false); } // Allow the user to save the workset if it doesn't already exist. m_TSBSave.Enabled = (m_CreateMode == true) ? true : false; }
/// <summary> /// Initializes an new instance of the form. Defines the communication interface and then downloads the current default data stream parameters and displays these /// on the form. /// </summary> /// <param name="communicationInterface">Reference to the communication interface that is to be used to communicate with the VCU.</param> /// <param name="worksetCollection">The workset collection that is to be managed.</param> /// <param name="log">The selected event log.</param> public FormConfigureFaultLogParameters(ICommunicationParent communicationInterface, WorksetCollection worksetCollection, Log log) : base(worksetCollection) { InitializeComponent(); // Move the position of the Cancel buttons. m_ButtonCancel.Location = m_ButtonApply.Location; // Initialize the communication interface. if (communicationInterface is CommunicationParent) { CommunicationInterface = new CommunicationEvent(communicationInterface); } else { CommunicationInterface = new CommunicationEventOffline(communicationInterface); } Debug.Assert(CommunicationInterface != null); // Don't allow the user to edit the workset until the security level of the workset has been established. ModifyEnabled = false; m_NumericUpDownSampleMultiple.Enabled = ModifyEnabled; // ---------------------------------------------------- // Get the current data stream parameters from the VCU. // ---------------------------------------------------- short variableCount, pointCount, sampleMultiple; short[] watchIdentifiers, dataTypes; try { CommunicationInterface.GetDefaultStreamInformation(out variableCount, out pointCount, out sampleMultiple, out watchIdentifiers, out dataTypes); } catch (Exception) { MessageBox.Show(Resources.MBTGetDefaultStreamParametersFailed, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Convert the parameters to a workset. Workset_t workset = CommunicationInterface.ConvertToWorkset("GetDefaultStreamInformation()", watchIdentifiers, sampleMultiple); // Search the list of worksets for a match. m_WorksetFromVCU = workset; m_WorksetToCompare = workset; Workset_t matchedWorkset = Workset.FaultLog.Worksets.Find(CompareWorkset); // Check whether a match was found. if (matchedWorkset.WatchItems == null) { // No - Create a new workset. workset.Name = DefaultNewWorksetName; // Set the flag to indicate that the workset does not exist and that any changes will be saved as a new workset. m_CreateMode = true; m_ComboBoxWorkset.DropDownStyle = ComboBoxStyle.DropDown; // Ensure that the TextChanged event is not triggered as a result of specifying the Text property of the TextBox control. m_TextBoxName.TextChanged -= new EventHandler(m_TextBoxName_TextChanged); m_TextBoxName.Text = workset.Name; m_TextBoxName.TextChanged += new EventHandler(m_TextBoxName_TextChanged); m_TextBoxName.Enabled = true; } else { // Yes - Update the name and security level of the workset. workset = matchedWorkset; // Set the flag to indicate that the form already exists and any changes will result in the existing workset being modified. m_CreateMode = false; m_ComboBoxWorkset.DropDownStyle = ComboBoxStyle.DropDownList; // Ensure that the TextChanged event is not triggered as a result of specifying the Text property of the TextBox control. m_TextBoxName.TextChanged -= new EventHandler(m_TextBoxName_TextChanged); m_TextBoxName.Text = workset.Name; m_TextBoxName.TextChanged += new EventHandler(m_TextBoxName_TextChanged); m_TextBoxName.Enabled = false; } // Keep a record of the selected workset. This must be set up before the call to SetEnabledEditNewCopyRename(). m_SelectedWorkset = workset; SetEnabledEditNewCopyRename(true); // Display the name of the default workset on the ComboBox control. // Ensure that the SelectionChanged event is not triggered as a result of specifying the Text property of the ComboBox control. m_ComboBoxWorkset.SelectedIndexChanged -= new EventHandler(m_ComboBoxWorkset_SelectedIndexChanged); m_ComboBoxWorkset.Text = workset.Name; m_ComboBoxWorkset.SelectedIndexChanged += new EventHandler(m_ComboBoxWorkset_SelectedIndexChanged); LoadWorkset(workset); // Update the EntryCountMax property to reflect the actual number of watch variables associated with the current event log. m_EntryCountMax = log.DataStreamTypeParameters.WatchVariablesMax; UpdateCount(); // Check whether the 'Row Header' ListBox can be used to display the channel numbers. This is only possible if // the project doesn't support multiple data stream types and the number of parameters supported by the data // stream can be displayed on the TabPage without the need for scroll bars i.e. <= WatchSizeFaultLogMax. if ((Parameter.SupportsMultipleDataStreamTypes == false) && (Parameter.WatchSizeFaultLog <= WatchSizeFaultLogMax)) { AddRowHeader(); } else { NoRowHeader(); } // Disable all options other than save if the downloaded workset doesn't exist. if (m_CreateMode == true) { SetEnabledEditNewCopyRename(false); } // Allow the user to save the workset if it doesn't already exist. m_TSBSave.Enabled = (m_CreateMode == true) ? true : false; }
/// <summary> /// Poll the target hardware for new events. /// </summary> /// <remarks>Runs on a separate thread.</remarks> public override void Run() { try { m_CommunicationFault = false; short currentEventCount; uint newEventIndex; uint newEventsLogged; while (StopThread == false) { if (Pause == false) { PauseFeedback = false; m_PollScheduler.Wait(IntervalMsEventUpdate); currentEventCount = 0; if (Pause == true) { m_Watchdog++; continue; } // Check for new events. currentEventCount = m_FormViewEventLog.EventCount; newEventIndex = m_FormViewEventLog.NewEventIndex; newEventsLogged = 0; try { m_Watchdog++; CommunicationInterface.CheckFaultLogger(ref currentEventCount, ref newEventIndex, ref newEventsLogged); m_ReadTimeoutCountdown = ReadTimeoutCountdown; } catch (CommunicationException) { // Don't assert the communication fault flag until the countdown has elapsed. if (m_ReadTimeoutCountdown <= 0) { // Assert the CommunicationFault property. m_CommunicationFault = true; // Close the communication Port. m_CommunicationInterface.CloseCommunication(m_CommunicationInterface.CommunicationSetting.Protocol); // Keep the watchdog ticking over so that the client can determine whether the port has locked. do { m_Watchdog++; Thread.Sleep(SleepMsRefreshWatchdog); }while (m_CommunicationFault == true); } else { m_ReadTimeoutCountdown--; continue; } } m_CommunicationFault = false; // Keep a count of the number of packets received. Used as a thread-safe way of blinking the packet received icon on the main window. This value // is read by the display update method on the main thread and provided it has incremented since the timeout last expired it will blink the icon. m_PacketCount++; // Skip if the Pause property has been asserted. if (Pause == true) { continue; } #if SimulateNewEvent // ------------------------------------------------------------------ // Simulate NewEventsPerPass events being triggered per pass. // ------------------------------------------------------------------ // Check that there are enough existing records to allow the new events to be simulated. if (m_FormViewEventLog.EventCount >= NewEventsPerPass) { // Retrieve the simulated new events. newEventCount = (short)(m_FormViewEventLog.EventCount + NewEventsPerPass); List <EventRecord> eventRecordList = new List <EventRecord>(); EventRecord eventRecord; // Get the oldest 'NewEventsPerPass' events from the VCU. for (short eventIndex = 0; eventIndex < NewEventsPerPass; eventIndex++) { try { CommunicationInterface.GetEventRecord(m_FormViewEventLog.Log, eventIndex, out eventRecord); eventRecord.CarIdentifier = FileHeader.HeaderCurrent.TargetConfiguration.CarIdentifier; eventRecord.EventIndex = (short)(m_FormViewEventLog.EventCount + eventIndex); eventRecord.DateTime = DateTime.Now; } catch (CommunicationException) { continue; } // Store the record retrieved from the VCU. eventRecordList.Add(eventRecord); m_FormViewEventLog.EventRecordList.Add(eventRecord); } m_FormViewEventLog.EventCount = newEventCount; m_FormViewEventLog.EventIndex += NewEventsPerPass; // Update the DataGridView control in a thread safe way. m_FormViewEventLog.Invoke(new AddListDelegate(m_FormViewEventLog.AddList), new object[] { eventRecordList }); Console.WriteLine("New Event(s) Added. EventCount: {0}, EventIndex: {1}", newEventCount, newEventIndex); } #else // Check whether any new events have been triggered. if (newEventsLogged > 0) { short eventCountDiff = (short)(currentEventCount - m_FormViewEventLog.EventCount); short newIndexDiff = (short)(newEventIndex - m_FormViewEventLog.NewEventIndex); // Check for events that have just been logged into an empty fault log if (m_FormViewEventLog.NewEventIndex == uint.MaxValue) { newIndexDiff--; } short evIndex = 0; uint eventsToFlush = 0; // if these calculations are equal, that means at least 1 new event was logged and that // the event log buffer hasn't started flushing old events if (eventCountDiff == newIndexDiff) { evIndex = (short)(m_FormViewEventLog.EventCount); } else { // Log was full and is now flushing out old events evIndex = (short)(currentEventCount - newIndexDiff); if (eventCountDiff != 0) { eventsToFlush = (uint)(newIndexDiff - eventCountDiff); } else { eventsToFlush = (uint)(newIndexDiff); } } // No wraparound of the uint index value, process normally. // Download the new events and add them to the DataGridView control. List <EventRecord> eventRecordList = new List <EventRecord>(); // Load the retrieved event records into the list. EventRecord eventRecord; uint flushLocal = eventsToFlush; for (short eventIndex = evIndex; eventIndex < currentEventCount; eventIndex++) { try { CommunicationInterface.GetEventRecord(m_FormViewEventLog.Log, eventIndex, out eventRecord); // If the event record cannot be found, continue. if (eventRecord == null) { continue; } eventRecord.CarIdentifier = FileHeader.HeaderCurrent.TargetConfiguration.CarIdentifier; } catch (CommunicationException) { continue; } if (flushLocal != 0) { m_FormViewEventLog.EventRecordList.RemoveAt(0); flushLocal--; } // Store the record retrieved from the VCU. eventRecordList.Add(eventRecord); m_FormViewEventLog.EventRecordList.Add(eventRecord); } m_FormViewEventLog.EventCount = currentEventCount; m_FormViewEventLog.NewEventIndex = newEventIndex; // Update the DataGridView control in a thread safe way. m_FormViewEventLog.Invoke(new AddListDelegate(m_FormViewEventLog.AddList), new object[] { eventRecordList, eventsToFlush }); // Hold the thread until the invoked method has completed. m_FormViewEventLog.m_MutexDataGridView.WaitOne(DefaultMutexWaitDurationMs, false); m_FormViewEventLog.m_MutexDataGridView.ReleaseMutex(); } #endif } else { PauseFeedback = true; m_Watchdog++; Thread.Sleep(SleepMsCheckPause); } } } finally { base.Run(); } }
public MainPage() { this.InitializeComponent(); Interface = new CommunicationInterface(); }
/// <summary> /// Initializes a new instance of the class. /// </summary> /// <param name="communicationInterface">The communication interface that is to be used to communicate with the VCU.</param> /// <param name="log">The current event log.</param> public FormConfigureEventFlags(ICommunicationParent communicationInterface, Log log) { InitializeComponent(); // Initialize the communication interface. if (communicationInterface is CommunicationParent) { CommunicationInterface = new CommunicationEvent(communicationInterface); } else { CommunicationInterface = new CommunicationEventOffline(communicationInterface); } Debug.Assert(CommunicationInterface != null); #region - [Size] - // Get the combined width of all visible DataGridView columns. int dataGridViewWidth = 0; DataGridViewColumn dataGridViewColumn; for (int columnIndex = 0; columnIndex < m_DataGridViewEventStatus.Columns.Count; columnIndex++) { dataGridViewColumn = m_DataGridViewEventStatus.Columns[columnIndex]; if (dataGridViewColumn.Visible == true) { dataGridViewWidth += dataGridViewColumn.Width; } } m_PanelDataGridViewEventStatus.Width = dataGridViewWidth + MarginRightDataGridViewControl; Width = m_PanelDataGridViewEventStatus.Width + MarginRightPanelControl; #endregion - [Size] - // ------------------------------------------------------------------ // Get the list of events associated with the current event log. // ------------------------------------------------------------------ List <EventRecord> foundEventRecordList; foundEventRecordList = Lookup.EventTable.RecordList.FindAll(delegate(EventRecord eventRecord) { // Include a try/catch block in case an event record has not been defined. try { // The LOGID field of the EVENTS table actually uses the log index value which is equal to the log identifier - 1. return(eventRecord.LogIdentifier == log.Identifier - 1); } catch (Exception) { return(false); } }); foundEventRecordList.Sort(CompareByTaskIDByEventIDAscending); // --------------------------------------------------------------- // Get the event flag information associated with the current log. // --------------------------------------------------------------- int eventCount = (short)foundEventRecordList.Count; int maxEventCount = log.MaxEventsPerTask * log.MaxTasks; // Initialize the validFlags array to define which of the events are used in the current log. short[] validFlags = new short[maxEventCount]; int eventIndex; for (int index = 0; index < foundEventRecordList.Count; index++) { eventIndex = foundEventRecordList[index].TaskIdentifier * log.MaxEventsPerTask + foundEventRecordList[index].EventIdentifier; validFlags[eventIndex] = CommonConstants.True; } short[] enabledFlags = new short[eventCount]; short[] streamTriggeredFlags = new short[eventCount]; try { CommunicationInterface.GetFltFlagInfo(validFlags, ref enabledFlags, ref streamTriggeredFlags, (short)maxEventCount); } catch (Exception) { throw new CommunicationException(Resources.EMGetFltFlagInfoFailed); } // --------------------------------- // Initialise the event status list. // --------------------------------- m_EventStatusList = new List <EventStatus_t>(eventCount); EventStatus_t eventStatus; for (int eventStatusIndex = 0; eventStatusIndex < eventCount; eventStatusIndex++) { eventStatus = new EventStatus_t(); eventStatus.Index = eventStatusIndex; eventStatus.Identifier = foundEventRecordList[eventStatusIndex].Identifier; if (enabledFlags[eventStatusIndex] == CommonConstants.True) { eventStatus.Enabled = true; } if (streamTriggeredFlags[eventStatusIndex] == CommonConstants.True) { eventStatus.StreamTriggered = true; } m_EventStatusList.Add(eventStatus); } AddList(m_EventStatusList); }
/// <summary> /// Event handler for the OK button <c>Click</c> event. /// </summary> /// <param name="sender">Reference to the object that raised the event.</param> /// <param name="e">Parameter passed from the object that raised the event.</param> protected void m_ButtonOK_Click(object sender, EventArgs e) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } Cursor = Cursors.WaitCursor; List <EventStatus_t> modifiedEventFlagList = new List <EventStatus_t>(); // Check which of the event status structure elements have been modified. modifiedEventFlagList = EventStatusList.FindAll(delegate(EventStatus_t eventStatus) { return(eventStatus.Modified == true); }); if (modifiedEventFlagList.Count >= 1) { DialogResult dialogResult = MessageBox.Show(Resources.MBTEventFlagsChanged, Resources.MBCaptionInformation, MessageBoxButtons.YesNo, MessageBoxIcon.Information); Update(); if (dialogResult == DialogResult.Yes) { // Update the VCU with the latest modifications. for (int index = 0; index < modifiedEventFlagList.Count; index++) { EventRecord eventRecord; try { eventRecord = Lookup.EventTable.RecordList[modifiedEventFlagList[index].Identifier]; if (eventRecord == null) { continue; } } catch (Exception) { continue; } // Update the VCU. short enabledFlag; if (modifiedEventFlagList[index].Enabled == true) { enabledFlag = CommonConstants.True; } else { enabledFlag = 0; } short streamTriggeredFlag; if (modifiedEventFlagList[index].StreamTriggered == true) { streamTriggeredFlag = CommonConstants.True; } else { streamTriggeredFlag = 0; } try { CommunicationInterface.SetFaultFlags((short)eventRecord.TaskIdentifier, (short)eventRecord.EventIdentifier, enabledFlag, streamTriggeredFlag); } catch (Exception) { MessageBox.Show(string.Format(Resources.MBTSetFaultFlagsFailed, eventRecord.Description), Resources.MBCaptionWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } Cursor = Cursors.Default; }
void ConnectionStatusChangedEvent(CommunicationInterface commInterface, CommunicationInterface.ConnectionStatusType status, bool willReconnect) { }