/// <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);
        }
        public static CanMsg CreateRemote(UInt32 id0, bool Extended0)
        {
            CanMsg CreateRemote = new CanMsg(id0, Extended0, 0);

            CreateRemote.Extended = Extended0;
            CreateRemote.Size     = 0;

            if (CreateRemote.Extended == false)
            {
                if (id0 <= 0x7FF)
                {
                    CreateRemote.Id = id0;
                }
                else
                {
                    throw new System.ArgumentException("Неправильный входной параметр аргумента", "original");
                }
            }
            if (CreateRemote.Extended == true)
            {
                if (id0 <= 0x1FFFFFFF)
                {
                    CreateRemote.Id = id0;
                }
                else
                {
                    throw new System.ArgumentException("Неправильный входной параметр аргумента", "original");
                }
            }

            return(CreateRemote);
        }
        /// <summary>
        ///  Поток проверки CAN-буфера
        /// </summary>
        public CanMsg ReceiveThreadFunc()
        {
            (new System.Threading.Thread(delegate() {
                string ReceiveThreadFunc = "";
                CanMessage canMessage;
                CanMsg cmsg = null;
                do
                {
                    // Принять кан сообщение из буфера адаптера
                    while (mReader.ReadMessage(out canMessage))
                    {
                        cmsg = new CanMsg(canMessage.Identifier, canMessage.ExtendedFrameFormat, canMessage.DataLength);
                        switch (canMessage.FrameType)
                        {
                        //
                        //  действия для каждого типа данных
                        //

                        case CanMsgFrameType.Data:
                            {
                                if (!canMessage.RemoteTransmissionRequest)
                                {
                                    ReceiveThreadFunc = "\nTime: " + canMessage.TimeStamp + "  ID: " + canMessage.Identifier + "  DLC: " + canMessage.DataLength + " Data: ";
                                    cmsg.comment = "\nTime: " + canMessage.TimeStamp + "  ID: " + canMessage.Identifier + "  DLC: " + canMessage.DataLength + " Data: ";

                                    for (int index = 0; index < canMessage.DataLength; index++)
                                    {
                                        ReceiveThreadFunc += canMessage[index] + " ";
                                        cmsg.comment += canMessage[index] + " ";
                                        cmsg[(byte)index] = Convert.ToByte(canMessage[index]);
                                    }
                                }
                                else
                                {
                                    ReceiveThreadFunc = "\nTime: " + canMessage.TimeStamp + "  ID: " + canMessage.Identifier + "  DLC: " + canMessage.DataLength + " Remote Frame ";
                                    cmsg.comment += "\nTime: " + canMessage.TimeStamp + "  ID: " + canMessage.Identifier + "  DLC: " + canMessage.DataLength + " Remote Frame ";
                                }
                                break;
                            }

                        //
                        // Информационные сообщения
                        //
                        case CanMsgFrameType.Info:
                            {
                                switch ((CanMsgInfoValue)canMessage[0])
                                {
                                case CanMsgInfoValue.Start:

                                    //   ReceiveThreadFunc = "\nCAN started...";
                                    cmsg.comment = "\nCAN started...";
                                    break;

                                case CanMsgInfoValue.Stop:
                                    //   cmsg.comment = "\nCAN stopped...";
                                    cmsg.comment = "\nCAN stopped...";
                                    break;

                                case CanMsgInfoValue.Reset:
                                    //    cmsg.comment = "\nCAN reseted...";
                                    cmsg.comment = "\nCAN reseted...";
                                    break;
                                }
                                break;
                            }

                        //
                        // show error frames
                        //
                        case CanMsgFrameType.Error:
                            {
                                switch ((CanMsgError)canMessage[0])
                                {
                                case CanMsgError.Stuff:
                                    cmsg.comment = "\nstuff error...";
                                    break;

                                case CanMsgError.Form:
                                    cmsg.comment = "\nform error...";
                                    break;

                                case CanMsgError.Acknowledge:
                                    cmsg.comment = "\nacknowledgment error...";
                                    break;

                                case CanMsgError.Bit:
                                    cmsg.comment = "\nbit error...";
                                    break;

                                case CanMsgError.Crc:
                                    cmsg.comment = "\nCRC error...";
                                    break;

                                case CanMsgError.Other:
                                    cmsg.comment = "\nother error...";
                                    break;
                                }
                                break;
                            }
                        }
                    }
                    CanMessageRecieved(cmsg);
                } while (0 == 0);
                // return cmsg;
            })).Start();
            return(null);
        }