示例#1
0
        /// <summary>
        ///  Отправка CAN сообщения
        /// </summary>
        public void TransmitData(CanMsg msg)
        {
            CanMessage canMsg = new CanMessage();

            // ExtendedFrameFormat - тип идентификатора - 11 или 22 бит


            canMsg.TimeStamp = 0;
            //canMsg.Identifier = 0x100;
            canMsg.Identifier = msg.Id;
            canMsg.FrameType  = CanMsgFrameType.Data;
            canMsg.DataLength = msg.Size;
            if (msg.Size == 0)
            {
                canMsg.RemoteTransmissionRequest = true;
            }
            canMsg.SelfReceptionRequest = true;  // Отображение сообщения в консоле

            for (Byte i = 0; i < canMsg.DataLength; i++)
            {
                canMsg[i] = msg.Size;
            }

            // Запись сообщения в FIFO(буфер can-адаптера?)
            mWriter.SendMessage(canMsg);
        }
示例#2
0
 public bool SendMessage(ICanMessage2 message)
 {
     if (message.Identifier == 0)
     {
         return(false);
     }
     if (_writer == null)
     {
         return(false);
     }
     return(_writer.SendMessage(message));
 }
示例#3
0
        /// <summary>
        ///   Transmits a CAN message with ID 0x100.
        /// </summary>
        static void TransmitData()
        {
            CanMessage canMsg = new CanMessage();

            canMsg.TimeStamp            = 0;
            canMsg.Identifier           = 0x100;
            canMsg.FrameType            = CanMsgFrameType.Data;
            canMsg.DataLength           = 8;
            canMsg.SelfReceptionRequest = true; // show this message in the console window

            for (Byte i = 0; i < canMsg.DataLength; i++)
            {
                canMsg[i] = i;
            }

            // Write the CAN message into the transmit FIFO
            mWriter.SendMessage(canMsg);
        }
示例#4
0
文件: Can.cs 项目: Wufus/NewWaveSanya
        static public bool TransmitData8(uint id, byte[] data)
        {
            IMessageFactory factory = VciServer.Instance().MsgFactory;
            ICanMessage     canMsg  = (ICanMessage)factory.CreateMsg(typeof(ICanMessage));

            canMsg.TimeStamp            = 0;
            canMsg.Identifier           = id;
            canMsg.FrameType            = CanMsgFrameType.Data;
            canMsg.DataLength           = 8;
            canMsg.SelfReceptionRequest = true;  // show this message in the console window

            for (Byte i = 0; i < data.Length; i++)
            {
                canMsg[i] = data[i];
            }

            // Write the CAN message into the transmit FIFO
            return(mWriter.SendMessage(canMsg));
        }
示例#5
0
        // trasmit the values on button click
        private void transmitBtn_Click(object sender, EventArgs e)
        {
            IMessageFactory fac    = VciServer.Instance().MsgFactory;
            ICanMessage     canMsg = (ICanMessage)fac.CreateMsg(typeof(ICanMessage));

            canMsg.TimeStamp  = 0;
            canMsg.Identifier = uint.Parse(txtID.Text, System.Globalization.NumberStyles.HexNumber);
            canMsg.FrameType  = CanMsgFrameType.Data;
            canMsg.DataLength = 8;

            //  message will be consist of an 8 bytes long value
            canMsg[0] = Byte.Parse(D1txt.Text, System.Globalization.NumberStyles.HexNumber);
            canMsg[1] = Byte.Parse(D2txt.Text, System.Globalization.NumberStyles.HexNumber);
            canMsg[2] = Byte.Parse(D3txt.Text, System.Globalization.NumberStyles.HexNumber);
            canMsg[3] = Byte.Parse(D4txt.Text, System.Globalization.NumberStyles.HexNumber);
            canMsg[4] = Byte.Parse(D5txt.Text, System.Globalization.NumberStyles.HexNumber);
            canMsg[5] = Byte.Parse(D6txt.Text, System.Globalization.NumberStyles.HexNumber);
            canMsg[6] = Byte.Parse(D7txt.Text, System.Globalization.NumberStyles.HexNumber);
            canMsg[7] = Byte.Parse(D8txt.Text, System.Globalization.NumberStyles.HexNumber);

            // check the remote transmission option
            if (RFcheckbox.Checked)
            {
                canMsg.RemoteTransmissionRequest = true;
            }
            else
            {
                canMsg.RemoteTransmissionRequest = false;
            }

            mWriter.SendMessage(canMsg);

            MessageBox.Show("Data is succesfully transmitted as: \n" + canMsg.ToString(),
                            "Transmission Succeeded", MessageBoxButtons.OK, MessageBoxIcon.Information);

            // bit checking
            switch (canMsg.FrameType)
            {
            case CanMsgFrameType.Error:
            {
                switch ((CanMsgError)canMsg[0])
                {
                case CanMsgError.Stuff:
                    MessageBox.Show("Stuff Error Detected!", "ERROR!",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                case CanMsgError.Form:
                    MessageBox.Show("Form Error Detected!", "ERROR!",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;

                case CanMsgError.Dlc:
                    MessageBox.Show("Data Length Error Detected!", "ERROR!",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
            }
            break;
            }
        }