Exemplo n.º 1
0
        // -----------------------------------------------------------------------------------------------

        public void CANMultipleTransmit(List <Message> list)
        {
            XLDefine.XL_Status txStatus;

            // Create an event collection with 1 messages (events)
            // XLClass.xl_event_collection(2) = 2 messages
            XLClass.xl_event_collection xlEventCollection = new XLClass.xl_event_collection((uint)list.Count);

            int count = 0;

            foreach (Message m in list)
            {
                // event 1
                // make copy of this and increment index of xlEvent to increase number of message
                xlEventCollection.xlEvent[count].tagData.can_Msg.id  = m.Id;
                xlEventCollection.xlEvent[count].tagData.can_Msg.dlc = (ushort)m.Dlc;
                for (int i = 0; i < m.Dlc; i++)
                {
                    //xlEventCollection.xlEvent[0].tagData.can_Msg.data[0] = 0;
                    xlEventCollection.xlEvent[count].tagData.can_Msg.data[i] = m.Array[i];
                }
                xlEventCollection.xlEvent[count].tag = XLDefine.XL_EventTags.XL_TRANSMIT_MSG;
                count++;
            }


            // Transmit events
            txStatus = CANDemo.XL_CanTransmit(portHandle, txMask, xlEventCollection);
        }
Exemplo n.º 2
0
        // -----------------------------------------------------------------------------------------------
        /// <summary>
        /// Sends some CAN messages.
        /// </summary>
        // -----------------------------------------------------------------------------------------------
        public void CANTransmit(uint id, uint dlc, byte[] array)
        {
            XLDefine.XL_Status txStatus;

            //Console.WriteLine("transmitting " + id + " : " + dlc + " ");

            // Create an event collection with 1 messages (events)
            // XLClass.xl_event_collection(2) = 2 messages
            XLClass.xl_event_collection xlEventCollection = new XLClass.xl_event_collection(1);

            // event 1
            // make copy of this and increment index of xlEvent to increase number of message
            xlEventCollection.xlEvent[0].tagData.can_Msg.id  = id;
            xlEventCollection.xlEvent[0].tagData.can_Msg.dlc = (ushort)dlc;
            for (int i = 0; i < dlc; i++)
            {
                //xlEventCollection.xlEvent[0].tagData.can_Msg.data[0] = 0;
                xlEventCollection.xlEvent[0].tagData.can_Msg.data[i] = array[i];
            }
            xlEventCollection.xlEvent[0].tag = XLDefine.XL_EventTags.XL_TRANSMIT_MSG;

            //Console.WriteLine("start transmitting...");

            // Transmit events
            txStatus = CANDemo.XL_CanTransmit(portHandle, txMask, xlEventCollection);
        }
Exemplo n.º 3
0
        public int CanTpSendData(byte[] data)
        {
            XLDefine.XL_Status txStatus;

            XLClass.xl_event_collection xlEventCollection = new XLClass.xl_event_collection(1);

            int dataLength = data.Length;

            if (dataLength <= 7)
            {
                CanTpSendSingleFrame(data);
                waitFrameType = 1;
            }
            else
            {
                CanTpSendFirstFrame(data);
                waitFrameType = 3;
                if (!waitforFlowControlEvent.WaitOne(1000))
                {
                    return(-1);
                }
                int sn = 1;
                //FF中已经发送了6字节 offset从6开始 CF每次发送7字节
                if (this.TxdiagBlockSize == 0)
                {
                    for (int i = 6; i < dataLength; i += 7)
                    {
                        CanTpSendConsecutiveFrame(data, i, sn);
                        sn++;
                    }
                }
                else
                {
                    //offset是已发送长度 下次索引直接从offset开始
                    int offset = 6;
                    while (offset < dataLength)
                    {
                        int count;
                        for (count = 0; count < this.TxdiagBlockSize; count++)
                        {
                            CanTpSendConsecutiveFrame(data, offset, sn);
                            if (count != this.TxdiagBlockSize - 1)
                            {
                                Thread.Sleep(this.TxdiagSTmin);
                            }
                            offset += 7;
                            sn++;
                        }
                        waitFrameType = 3;
                        if (!waitforFlowControlEvent.WaitOne(1000))
                        {
                            return(-1);
                        }
                    }
                }
            }
            return(0);
        }
Exemplo n.º 4
0
        private void CanTpSendFlowControlFrame()
        {
            XLDefine.XL_Status txStatus;

            XLClass.xl_event_collection xlEventCollection = new XLClass.xl_event_collection(1);

            xlEventCollection.xlEvent[0].tagData.can_Msg.id      = this.TxID;
            xlEventCollection.xlEvent[0].tagData.can_Msg.dlc     = 8;
            xlEventCollection.xlEvent[0].tagData.can_Msg.data[0] = 0x30;
            xlEventCollection.xlEvent[0].tagData.can_Msg.data[1] = this.RxBlockSize;
            for (int i = 0; i < 5; i++)
            {
                xlEventCollection.xlEvent[0].tagData.can_Msg.data[i + 2] = this.PaddingValue;
            }
            xlEventCollection.xlEvent[0].tag = XLDefine.XL_EventTags.XL_TRANSMIT_MSG;
            txStatus = CANTPDriver.XL_CanTransmit(portHandle, accessMask, xlEventCollection);
        }
Exemplo n.º 5
0
        private void CanTpSendFirstFrame(byte[] data)
        {
            int dataLength;

            XLDefine.XL_Status txStatus;

            XLClass.xl_event_collection xlEventCollection = new XLClass.xl_event_collection(1);

            dataLength = data.Length;
            xlEventCollection.xlEvent[0].tagData.can_Msg.id      = this.TxID;
            xlEventCollection.xlEvent[0].tagData.can_Msg.dlc     = 8;
            xlEventCollection.xlEvent[0].tagData.can_Msg.data[0] = (byte)(0x10 + (dataLength >> 8));
            xlEventCollection.xlEvent[0].tagData.can_Msg.data[1] = (byte)(dataLength & 0xFF);
            for (int i = 0; i < 6; i++)
            {
                xlEventCollection.xlEvent[0].tagData.can_Msg.data[i + 2] = data[i];
            }
            xlEventCollection.xlEvent[0].tag = XLDefine.XL_EventTags.XL_TRANSMIT_MSG;
            txStatus = CANTPDriver.XL_CanTransmit(portHandle, accessMask, xlEventCollection);
        }
Exemplo n.º 6
0
        void SendMflMessageExecute(object IdDlcStartBitLengthValueInterval)
        {
            string[] parameters = ((String)IdDlcStartBitLengthValueInterval).Split('_');

            UInt16 id       = Convert.ToUInt16(parameters[0]);
            UInt16 dlc      = Convert.ToUInt16(parameters[1]);
            UInt16 length   = Convert.ToUInt16(parameters[2]);
            int    startBit = Convert.ToUInt16(parameters[3]);
            int    value    = Convert.ToInt32(parameters[4]);
            int    interval = Convert.ToInt32(parameters[5]);

            int    _iEventHandleLocal     = -1;
            int    _iPortHandleLocal      = -1;
            UInt64 _ui64TransmitMaskLocal = 0;

            xlStartCan(ref _iEventHandleLocal, ref _iPortHandleLocal, ref _ui64TransmitMaskLocal);
            //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;
            xlEventCollection.xlEvent.Clear();
            xlEvent = new XLClass.xl_event();
            xlEvent.tagData.can_Msg.id   = id;
            xlEvent.tagData.can_Msg.dlc  = dlc;
            xlEvent.tagData.can_Msg.data = getMessageValue(new byte[dlc], value, startBit, length);
            xlEvent.tag = (byte)XLClass.XLeventType.XL_TRANSMIT_MSG;
            xlEventCollection.xlEvent.Add(xlEvent);
            xlEventCollection.messageCount = (uint)xlEventCollection.xlEvent.Count;

            for (int idx = 0; idx < interval; idx++)
            {
                _xlDriverTx.XL_CanTransmit(_iPortHandleLocal, /* _ui64TransmitMaskLocal*/ 1, xlEventCollection);
                Thread.Sleep(1);
            }
            xlEventCollection.xlEvent.Clear();
            xlEvent.tagData.can_Msg.data = xlEvent.tagData.can_Msg.data = getMessageValue(new byte[dlc], 0, startBit, length);
            xlEventCollection.xlEvent.Add(xlEvent);
            _xlDriverTx.XL_CanTransmit(_iPortHandleLocal, /* _ui64TransmitMaskLocal*/ 1, xlEventCollection);

            _xlDriverTx.XL_ClosePort(_iPortHandleLocal);
            _xlDriverTx.XL_CloseDriver();
        }
Exemplo n.º 7
0
        private void CanTpSendSingleFrame(byte[] data)
        {
            XLDefine.XL_Status txStatus;

            XLClass.xl_event_collection xlEventCollection = new XLClass.xl_event_collection(1);

            xlEventCollection.xlEvent[0].tagData.can_Msg.id      = this.TxID;
            xlEventCollection.xlEvent[0].tagData.can_Msg.dlc     = 8;
            xlEventCollection.xlEvent[0].tagData.can_Msg.data[0] = (byte)data.Length;
            for (int i = 0; i < data.Length; i++)
            {
                xlEventCollection.xlEvent[0].tagData.can_Msg.data[i + 1] = data[i];
            }
            for (int i = data.Length; i < 7; i++)
            {
                xlEventCollection.xlEvent[0].tagData.can_Msg.data[i + 1] = this.PaddingValue;
            }
            xlEventCollection.xlEvent[0].tag = XLDefine.XL_EventTags.XL_TRANSMIT_MSG;
            txStatus      = CANTPDriver.XL_CanTransmit(portHandle, accessMask, xlEventCollection);
            waitFrameType = 1;
            Console.WriteLine("Transmit Message      : " + txStatus);
        }
Exemplo n.º 8
0
        private void CanTpSendConsecutiveFrame(byte[] data, int offset, int sequenceNum)
        {
            XLDefine.XL_Status txStatus;

            XLClass.xl_event_collection xlEventCollection = new XLClass.xl_event_collection(1);

            int dataLength;

            if (offset >= data.Length)
            {
                return;
            }
            else if (data.Length - offset >= 7)
            {
                dataLength = 7;
            }
            else
            {
                dataLength = data.Length - offset;
            }

            sequenceNum = sequenceNum % 16;
            xlEventCollection.xlEvent[0].tagData.can_Msg.id      = this.TxID;
            xlEventCollection.xlEvent[0].tagData.can_Msg.dlc     = 8;
            xlEventCollection.xlEvent[0].tagData.can_Msg.data[0] = (byte)(0x20 + sequenceNum);
            for (int i = 0; i < dataLength; i++)
            {
                xlEventCollection.xlEvent[0].tagData.can_Msg.data[i + 1] = data[offset + i];
            }
            for (int i = dataLength; i < 7; i++)
            {
                xlEventCollection.xlEvent[0].tagData.can_Msg.data[dataLength + 1] = this.PaddingValue;
            }
            xlEventCollection.xlEvent[0].tag = XLDefine.XL_EventTags.XL_TRANSMIT_MSG;
            txStatus = CANTPDriver.XL_CanTransmit(portHandle, accessMask, xlEventCollection);
        }
Exemplo n.º 9
0
        /// <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);
        }