public static void SendInfo(uint mask, int speed) { XLDefine.XL_Status txStatus; xl_event_collection xlEventCollection = new xl_event_collection(4); xlEventCollection.xlEvent[0].tagData.can_Msg.id = 30; xlEventCollection.xlEvent[0].tagData.can_Msg.dlc = 1; xlEventCollection.xlEvent[0].tagData.can_Msg.data[0] = (byte)mask; xlEventCollection.xlEvent[0].tag = XL_EventTags.XL_TRANSMIT_MSG; xlEventCollection.xlEvent[1].tagData.can_Msg.id = 10; xlEventCollection.xlEvent[1].tagData.can_Msg.dlc = 1; xlEventCollection.xlEvent[1].tagData.can_Msg.data[0] = (byte)speed; xlEventCollection.xlEvent[1].tag = XL_EventTags.XL_TRANSMIT_MSG; xlEventCollection.xlEvent[2].tagData.can_Msg.id = 20; xlEventCollection.xlEvent[2].tagData.can_Msg.dlc = 1; xlEventCollection.xlEvent[2].tagData.can_Msg.data[0] = (byte)horn; xlEventCollection.xlEvent[2].tag = XL_EventTags.XL_TRANSMIT_MSG; xlEventCollection.xlEvent[3].tagData.can_Msg.id = 40; xlEventCollection.xlEvent[3].tagData.can_Msg.dlc = 2; xlEventCollection.xlEvent[3].tagData.can_Msg.data[0] = (byte)curr_time_hours; xlEventCollection.xlEvent[3].tagData.can_Msg.data[1] = (byte)curr_time_minutes; xlEventCollection.xlEvent[3].tag = XL_EventTags.XL_TRANSMIT_MSG; txStatus = CANDriver.XL_CanTransmit(portHandle, txMask, xlEventCollection); }
// ----------------------------------------------------------------------------------------------- /// <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); }
////////////////// END OF RXHANDLER ////////////////////////// ////////////////// START OF TXHANDLER //////////////////////// public void ChangeSession(int SESSION, int SUB_FN) { switch (SUB_FN) { case 0X01: TXBuffFill(REQ_ID, 8, 0X02, 0X10, 0X01, FILLER, FILLER, FILLER, FILLER, FILLER); txStatus = UDSDemo.XL_CanTransmit(portHandle, txMask, xlEventCollection); TRACER(1, 0); break; case 0X02: TXBuffFill(REQ_ID, 8, 0X02, 0X10, 0X02, FILLER, FILLER, FILLER, FILLER, FILLER); txStatus = UDSDemo.XL_CanTransmit(portHandle, txMask, xlEventCollection); TRACER(1, 0); break; case 0X03: TXBuffFill(REQ_ID, 8, 0X02, 0X10, 0X03, FILLER, FILLER, FILLER, FILLER, FILLER); txStatus = UDSDemo.XL_CanTransmit(portHandle, txMask, xlEventCollection); TRACER(1, 0); break; } }
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); }
////////////////// END OF RXHANDLER ////////////////////////// ////////////////// START OF TXHANDLER //////////////////////// public void TXHANDLER(int SUB_FN) { switch (SUB_FN) { case 0X10: //string nula_deset; //Console.WriteLine("Unesite sub funkciju (0,1,2): "); //nula_deset = Console.ReadLine(); TXBuffFill(REQ_ID, 8, 0X02, 0X10, 0X01, FILLER, FILLER, FILLER, FILLER, FILLER); txStatus = UDSDemo.XL_CanTransmit(portHandle, txMask, xlEventCollection); TRACER(1, 0); // DID = Int32.Parse(textBox5.Text, System.Globalization.NumberStyles.HexNumber); /*if (Int32.Parse(nula_deset, System.Globalization.NumberStyles.HexNumber) == 0) * { * * //P2TIMER.Interval = P2; //(type,direction) ==> type 1 - positive event, type 2 - negative event, direction 0 - tx, direction 1 - rx * //P2TIMER.Start(); * } * else if (Int32.Parse(nula_deset, System.Globalization.NumberStyles.HexNumber) == 1) * { * TXBuffFill(REQ_ID, 8, 0X02, 0X10, 0X02, FILLER, FILLER, FILLER, FILLER, FILLER); * txStatus = UDSDemo.XL_CanTransmit(portHandle, txMask, xlEventCollection); * TRACER(1, 0); * //P2TIMER.Interval = P2; //(type,direction) ==> type 1 - positive event, type 2 - negative event, direction 0 - tx, direction 1 - rx * //P2TIMER.Start(); * } * else if (Int32.Parse(nula_deset, System.Globalization.NumberStyles.HexNumber) == 2) * { * TXBuffFill(REQ_ID, 8, 0X02, 0X10, 0X03, FILLER, FILLER, FILLER, FILLER, FILLER); * txStatus = UDSDemo.XL_CanTransmit(portHandle, txMask, xlEventCollection); * TRACER(1, 0); * //P2TIMER.Interval = P2; //(type,direction) ==> type 1 - positive event, type 2 - negative event, direction 0 - tx, direction 1 - rx * //P2TIMER.Start(); * }*/ break; case 0X11: TXBuffFill(REQ_ID, 8, 0X02, 0X11, 0X02, FILLER, FILLER, FILLER, FILLER, FILLER); txStatus = UDSDemo.XL_CanTransmit(portHandle, txMask, xlEventCollection); TRACER(1, 0); /*string nula_jedanaest; * Console.WriteLine("Unesite sub funkciju (0,1,2): "); * nula_jedanaest = Console.ReadLine(); * * if (Int32.Parse(nula_jedanaest, System.Globalization.NumberStyles.HexNumber) == 0) * { * TXBuffFill(REQ_ID, 8, 0X02, 0X11, 0X01, FILLER, FILLER, FILLER, FILLER, FILLER); * txStatus = UDSDemo.XL_CanTransmit(portHandle, txMask, xlEventCollection); * TRACER(1, 0); * //P2TIMER.Interval = P2; //(type,direction) ==> type 1 - positive event, type 2 - negative event, direction 0 - tx, direction 1 - rx * //P2TIMER.Start(); * } * else if (Int32.Parse(nula_jedanaest, System.Globalization.NumberStyles.HexNumber) == 1) * { * * // P2TIMER.Interval = P2; //(type,direction) ==> type 1 - positive event, type 2 - negative event, direction 0 - tx, direction 1 - rx * //P2TIMER.Start(); * } * else if (Int32.Parse(nula_jedanaest, System.Globalization.NumberStyles.HexNumber) == 2) * { * TXBuffFill(REQ_ID, 8, 0X02, 0X11, 0X03, FILLER, FILLER, FILLER, FILLER, FILLER); * txStatus = UDSDemo.XL_CanTransmit(portHandle, txMask, xlEventCollection); * TRACER(1, 0); * // P2TIMER.Interval =P2; //(type,direction) ==> type 1 - positive event, type 2 - negative event, direction 0 - tx, direction 1 - rx * // P2TIMER.Start(); * } * break; * case 0X3E: * * * TXBuffFill(REQ_ID, 8, 0X02, 0X3E, 0x00, FILLER, FILLER, FILLER, FILLER, FILLER); * txStatus = UDSDemo.XL_CanTransmit(portHandle, txMask, xlEventCollection); * TRACER(1, 0); * // P2TIMER.Interval = P2; //(type,direction) ==> type 1 - positive event, type 2 - negative event, direction 0 - tx, direction 1 - rx * // P2TIMER.Start(); */ break; case 0X22: string nula_22; Console.WriteLine("Unesite DID: "); nula_22 = Console.ReadLine(); if (String.IsNullOrEmpty(nula_22)) { Console.WriteLine("DID Cannot be empty!"); } else { int DID; //DID = byte.Parse(textBox5.Text); DID = Int32.Parse(nula_22, System.Globalization.NumberStyles.HexNumber); if ((DID <= 0xFFFF) && (DID > 0X0000)) { DIDHIGH = (byte)((DID >> 8) & 0XFF); DIDLOW = (byte)(DID & 0XFF); TXBuffFill(REQ_ID, 8, 0X03, 0X22, DIDHIGH, DIDLOW, FILLER, FILLER, FILLER, FILLER); txStatus = UDSDemo.XL_CanTransmit(portHandle, txMask, xlEventCollection); TRACER(1, 0); // P2TIMER.Interval = P2; //(type,direction) ==> type 1 - positive event, type 2 - negative event, direction 0 - tx, direction 1 - rx // P2TIMER.Start(); } else { Console.WriteLine("DID is not valid!", "DID Error"); } } break; case 0X14: TXBuffFill(REQ_ID, 8, 0X01, 0X14, FILLER, FILLER, FILLER, FILLER, FILLER, FILLER); txStatus = UDSDemo.XL_CanTransmit(portHandle, txMask, xlEventCollection); TRACER(1, 0); //P2TIMER.Interval = P2; //(type,direction) ==> type 1 - positive event, type 2 - negative event, direction 0 - tx, direction 1 - rx // P2TIMER.Start(); break; case 0X19: string mask; Console.WriteLine("\n Unesite Masku za dati servis: "); mask = Console.ReadLine(); int Mask = Int32.Parse(mask, System.Globalization.NumberStyles.HexNumber); if ((Mask > 0XFF) || (Mask < 0X00)) { Console.WriteLine("Mask Value not valid!", "Warning"); } TXBuffFill(REQ_ID, 8, 0X03, 0X19, 0X01, Mask, FILLER, FILLER, FILLER, FILLER); txStatus = UDSDemo.XL_CanTransmit(portHandle, txMask, xlEventCollection); TRACER(1, 0); //P2TIMER.Interval = P2; //(type,direction) ==> type 1 - positive event, type 2 - negative event, direction 0 - tx, direction 1 - rx // P2TIMER.Start(); break; } }
/// <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); }
public void SendMessage(int type) { XLDefine.XL_Status txStatus; XLClass.xl_event driverEvent = new XLClass.xl_event(); if (type == FULL_THROTTLE_ON) { Console.WriteLine("Full Throttle On"); // FULL THROTTLE ON driverEvent.tagData.can_Msg.id = 0x103; driverEvent.tagData.can_Msg.dlc = 2; driverEvent.tagData.can_Msg.data[0] = 19; driverEvent.tagData.can_Msg.data[1] = 136; driverEvent.tag = XLDefine.XL_EventTags.XL_TRANSMIT_MSG; } if (type == FULL_THROTTLE_OFF) { Console.WriteLine("Full Throttle Off"); // FULL THROTTLE OFF driverEvent.tagData.can_Msg.id = 0x103; driverEvent.tagData.can_Msg.dlc = 2; driverEvent.tagData.can_Msg.data[0] = 0; driverEvent.tagData.can_Msg.data[1] = 0; driverEvent.tag = XLDefine.XL_EventTags.XL_TRANSMIT_MSG; } if (type == FULL_BRAKE_ON) { Console.WriteLine("Full Brake On"); // FULL BRAKE ON driverEvent.tagData.can_Msg.id = 0x5; driverEvent.tagData.can_Msg.dlc = 8; driverEvent.tagData.can_Msg.data[0] = 0; driverEvent.tagData.can_Msg.data[1] = 100; driverEvent.tagData.can_Msg.data[2] = 0; driverEvent.tagData.can_Msg.data[3] = 0; driverEvent.tagData.can_Msg.data[4] = 0; driverEvent.tagData.can_Msg.data[5] = 0; driverEvent.tagData.can_Msg.data[6] = 0; driverEvent.tagData.can_Msg.data[7] = 0; driverEvent.tag = XLDefine.XL_EventTags.XL_TRANSMIT_MSG; } if (type == FULL_BRAKE_OFF) { Console.WriteLine("Full Brake Off"); // FULL BRAKE OFF driverEvent.tagData.can_Msg.id = 0x100; driverEvent.tagData.can_Msg.dlc = 8; driverEvent.tagData.can_Msg.data[0] = 0; driverEvent.tagData.can_Msg.data[1] = 0; driverEvent.tagData.can_Msg.data[2] = 0; driverEvent.tagData.can_Msg.data[3] = 0; driverEvent.tagData.can_Msg.data[4] = 0; driverEvent.tagData.can_Msg.data[5] = 0; driverEvent.tagData.can_Msg.data[6] = 0; driverEvent.tagData.can_Msg.data[7] = 0; driverEvent.tag = XLDefine.XL_EventTags.XL_TRANSMIT_MSG; } // Transmit events txStatus = driver.XL_CanTransmit(portHandle, txMask, driverEvent); //Console.WriteLine(txStatus); }