Beispiel #1
0
 public void Dispose()
 {
     if (driver != null)
     {
         DriverAction("Close port", driver.XL_ClosePort(portHandle));
         DriverAction("Close driver", driver.XL_CloseDriver());
     }
 }
        /// <summary>
        /// The trigger command for the sequence, which is processed asynchronous
        /// </summary>
        void StartExecute()
        {
            CurrentSendetMessages.Clear();
            bwTx.WorkerReportsProgress      = true;
            bwTx.WorkerSupportsCancellation = true;
            bwTx.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                CSequenceViewModel sequence = (CSequenceViewModel)args.Argument;
                Dictionary <int, CSentMessageViewModel> dicCurrentSendetMessages = new Dictionary <int, CSentMessageViewModel>();
                XLClass.xl_can_message      xlMsg             = new XLClass.xl_can_message();
                XLClass.xl_event_collection xlEventCollection = new XLClass.xl_event_collection(0);
                XLClass.xl_event            xlEvent;
                int time;
                time = 0;
                xlStartCan(ref _iEventHandleTx, ref _iPortHandleTx, ref _ui64TransmitMaskTx);

                while (true)
                {
                    if (bwTx.CancellationPending)
                    {
                        _xlDriverTx.XL_ClosePort(_iPortHandleTx);
                        _xlDriverTx.XL_CloseDriver();
                        args.Cancel = true;
                        break;
                    }
                    else
                    {
                        foreach (CStepViewModel step in sequence.Steps)
                        {
                            if (time == step.StepTime)
                            {
                                switch (step.StepCommand)
                                {
                                case "Set":
                                {
                                    if (!dicCurrentSendetMessages.ContainsKey(step.StepMessage.MessageId))
                                    {
                                        dicCurrentSendetMessages.Add(step.StepMessage.MessageId, new CSentMessageViewModel(step));
                                    }
                                    dicCurrentSendetMessages[step.StepMessage.MessageId].Message.MessageData = getMessageValue(step.StepMessage.MessageData, step.StepValue, step.StepSignal.SignalStartBit, step.StepSignal.SignalLenght);
                                    dicCurrentSendetMessages[step.StepMessage.MessageId].StartTime           = Convert.ToInt32(time);
                                    dicCurrentSendetMessages[step.StepMessage.MessageId].StopTime            = Int32.MaxValue;
                                    break;
                                }

                                case "Set with ASR":
                                {
                                    break;
                                }

                                case "Step 500ms":
                                {
                                    if (!dicCurrentSendetMessages.ContainsKey(step.StepMessage.MessageId))
                                    {
                                        dicCurrentSendetMessages.Add(step.StepMessage.MessageId, new CSentMessageViewModel(step));
                                    }
                                    dicCurrentSendetMessages[step.StepMessage.MessageId].Message.MessageData = getMessageValue(step.StepMessage.MessageData, step.StepValue, step.StepSignal.SignalStartBit, step.StepSignal.SignalLenght);
                                    dicCurrentSendetMessages[step.StepMessage.MessageId].StartTime           = time;
                                    dicCurrentSendetMessages[step.StepMessage.MessageId].StopTime            = time + 500;
                                    break;
                                }

                                case "Timeout":
                                {
                                    if (dicCurrentSendetMessages.ContainsKey(step.StepMessage.MessageId))
                                    {
                                        dicCurrentSendetMessages.Remove(step.StepMessage.MessageId);
                                    }
                                    break;
                                }

                                case "Break":
                                {
                                    if (MessageBox.Show(string.Format("Breaked sequence {0}, do you want to continue?", this.SolutionCurrentSequence.SequenceName), "Break", MessageBoxButton.YesNo, MessageBoxImage.Hand) != MessageBoxResult.Yes)
                                    {
                                        return;
                                    }
                                    break;
                                }

                                case "Restart":
                                {
                                    //RestartExecute();
                                    break;
                                }

                                default:
                                {
                                    break;
                                }
                                }
                            }
                        }
                        foreach (KeyValuePair <int, CSentMessageViewModel> msg in dicCurrentSendetMessages)
                        {
                            if (msg.Value.StopTime == time)
                            {
                                msg.Value.Message.MessageData = getMessageValue(msg.Value.Message.MessageData, 0, msg.Value.Signal.SignalStartBit, msg.Value.Signal.SignalLenght);
                            }
                        }
                        xlEventCollection.xlEvent.Clear();
                        foreach (KeyValuePair <int, CSentMessageViewModel> msg in dicCurrentSendetMessages)
                        {
                            xlEvent = new XLClass.xl_event();
                            xlEvent.tagData.can_Msg.id   = (uint)msg.Value.Message.MessageId;
                            xlEvent.tagData.can_Msg.dlc  = (ushort)msg.Value.Message.MessageDlc;
                            xlEvent.tagData.can_Msg.data = msg.Value.Message.MessageData;
                            xlEvent.tag = (byte)XLClass.XLeventType.XL_TRANSMIT_MSG;
                            xlEventCollection.xlEvent.Add(xlEvent);
                        }
                        xlEventCollection.messageCount = (uint)xlEventCollection.xlEvent.Count;
                        if (xlEventCollection.messageCount > 0)
                        {
                            _xlDriverTx.XL_CanTransmit(_iPortHandleTx, _ui64TransmitMaskTx, xlEventCollection);
                        }
                    }
                    bwTx.ReportProgress(time++, dicCurrentSendetMessages);
                    Thread.Sleep(1);
                }
            };
            bwTx.ProgressChanged += bwTx_ProgressChanged;
            CurrentSendetMessages.Clear();
            bwTx.RunWorkerAsync(this._currentSequenceViewModel);
        }
Beispiel #3
0
        // -----------------------------------------------------------------------------------------------

        public void Shutdown()
        {
            Console.WriteLine("Close Port                     : " + CANDemo.XL_ClosePort(portHandle));
            Console.WriteLine("Close Driver                   : " + CANDemo.XL_CloseDriver());
        }