当前位置: 首页>>代码示例>>C#>>正文


C# CANMessage.setFlags方法代码示例

本文整理汇总了C#中TrionicCANLib.CAN.CANMessage.setFlags方法的典型用法代码示例。如果您正苦于以下问题:C# CANMessage.setFlags方法的具体用法?C# CANMessage.setFlags怎么用?C# CANMessage.setFlags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TrionicCANLib.CAN.CANMessage的用法示例。


在下文中一共展示了CANMessage.setFlags方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: readMessages

 /// <summary>
 /// readMessages is the "run" method of this class. It reads all incomming messages
 /// and publishes them to registered ICANListeners.
 /// </summary>
 public void readMessages()
 {
     int readResult = 0;
     Lawicel.CANUSB.CANMsg r_canMsg = new Lawicel.CANUSB.CANMsg();
     CANMessage canMessage = new CANMessage();
     Console.WriteLine("readMessages started");
     while (true)
     {
         lock (m_synchObject)
         {
             if (m_endThread)
             {
                 Console.WriteLine("readMessages ended");
                 return;
             }
         }
         readResult = Lawicel.CANUSB.canusb_Read(m_deviceHandle, out r_canMsg);
         if (readResult == Lawicel.CANUSB.ERROR_CANUSB_OK)
         {
             if (acceptMessageId(r_canMsg.id))
             {
                 canMessage.setID(r_canMsg.id);
                 canMessage.setLength(r_canMsg.len);
                 canMessage.setTimeStamp(r_canMsg.timestamp);
                 canMessage.setFlags(r_canMsg.flags);
                 canMessage.setData(r_canMsg.data);
                 lock (m_listeners)
                 {
                     AddToCanTrace(string.Format("RX: {0} {1}", canMessage.getID().ToString("X3"), canMessage.getData().ToString("X16")));
                     foreach (ICANListener listener in m_listeners)
                     {
                         listener.handleMessage(canMessage);
                     }
                 }
             }
         }
         else if (readResult == Lawicel.CANUSB.ERROR_CANUSB_NO_MESSAGE)
         {
             Thread.Sleep(1);
         }
     }
 }
开发者ID:josla972,项目名称:Trionic,代码行数:46,代码来源:CANUSBDevice.cs

示例2: readMessages

        /// <summary>
        /// readMessages is the "run" method of this class. It reads all incomming messages
        /// and publishes them to registered ICANListeners.
        /// </summary>
        public void readMessages()
        {
            int readResult = 0;
            Lawicel.CANUSB.CANMsg r_canMsg = new Lawicel.CANUSB.CANMsg();
            CANMessage canMessage = new CANMessage();
            logger.Debug("readMessages started");
            while (true)
            {
                lock (m_synchObject)
                {
                    if (m_endThread)
                    {
                        logger.Debug("readMessages thread ended");
                        return;
                    }
                }
                readResult = Lawicel.CANUSB.canusb_Read(m_deviceHandle, out r_canMsg);
                if (readResult == Lawicel.CANUSB.ERROR_CANUSB_OK)
                {
                    if (acceptMessageId(r_canMsg.id))
                    {
                        canMessage.setID(r_canMsg.id);
                        canMessage.setLength(r_canMsg.len);
                        canMessage.setTimeStamp(r_canMsg.timestamp);
                        canMessage.setFlags(r_canMsg.flags);
                        canMessage.setData(r_canMsg.data);

                        receivedMessage(canMessage);
                    }
                }
                else if (readResult == Lawicel.CANUSB.ERROR_CANUSB_NO_MESSAGE)
                {
                    Thread.Sleep(1);
                }
            }
        }
开发者ID:ChrisPea,项目名称:Trionic,代码行数:40,代码来源:CANUSBDevice.cs

示例3: readMessages

        // int thrdcnt = 0;
        /// <summary>
        /// readMessages is the "run" method of this class. It reads all incomming messages
        /// and publishes them to registered ICANListeners.
        /// </summary>
        public void readMessages()
        {
            while (true)
            {
                lock (m_synchObject)
                {
                    if (m_endThread)
                    {
                        m_endThread = false;
                        return;
                    }
                }
                if (m_serialPort.IsOpen)
                {
                    // read the status?

                    string line = string.Empty;

                    try
                    {
                        line = m_serialPort.ReadLine();
                        if (line.Length > 0)
                        {
                            if (line.Length == 25)
                            {
                                Lawicel.CANUSB.CANMsg r_canMsg = new Lawicel.CANUSB.CANMsg();
                                canMessage = new CANMessage();
                                // three bytes identifier
                                r_canMsg.id = (uint)Convert.ToInt32(line.Substring(1, 3), 16);
                                r_canMsg.len = (byte)Convert.ToInt32(line.Substring(4, 1), 16);
                                ulong data = 0;
                                // add all the bytes
                                data |= (ulong)(byte)Convert.ToInt32(line.Substring(5, 2), 16);
                                data |= (ulong)(byte)Convert.ToInt32(line.Substring(7, 2), 16) << 1 * 8;
                                data |= (ulong)(byte)Convert.ToInt32(line.Substring(9, 2), 16) << 2 * 8;
                                data |= (ulong)(byte)Convert.ToInt32(line.Substring(11, 2), 16) << 3 * 8;
                                data |= (ulong)(byte)Convert.ToInt32(line.Substring(13, 2), 16) << 4 * 8;
                                data |= (ulong)(byte)Convert.ToInt32(line.Substring(15, 2), 16) << 5 * 8;
                                data |= (ulong)(byte)Convert.ToInt32(line.Substring(17, 2), 16) << 6 * 8;
                                data |= (ulong)(byte)Convert.ToInt32(line.Substring(19, 2), 16) << 7 * 8;
                                r_canMsg.data = data;
                                canMessage.setID(r_canMsg.id);
                                canMessage.setLength(r_canMsg.len);
                                canMessage.setFlags(r_canMsg.flags);
                                canMessage.setData(r_canMsg.data);

                                lock (m_listeners)
                                {
                                    AddToCanTrace(string.Format("RX: {0} {1} {2}", canMessage.getID().ToString("X3"), line.Substring(5, 16), line));
                                    foreach (ICANListener listener in m_listeners)
                                    {
                                        listener.handleMessage(canMessage);
                                    }
                                }
                            }
                            else if(line.Contains("z"))
                            {
                                interfaceBusy = false;
                                //Console.WriteLine("clear");
                            }
                            else if (line.Length == 2 && Convert.ToInt32(line.Substring(1, 2), 16) != 0x07)
                            {
                                //Console.WriteLine("Send error");
                            }
                            else
                            {
                                //Console.WriteLine("Unknown message: " + line);
                            }
                        }
                    }
                    catch (Exception E)
                    {
                        Console.WriteLine("Failed to read frames from CANbus: " + E.Message);
                    }
                }
                //Thread.Sleep(2);
                Thread.Sleep(delayTimespan); // give others some air
            }
        }
开发者ID:josla972,项目名称:Trionic,代码行数:84,代码来源:CANUSBDirectDevice.cs

示例4: waitAnyMessage

        /// <summary>
        /// waitAnyMessage waits for any message to be received.
        /// </summary>
        /// <param name="timeout">Listen timeout</param>
        /// <param name="r_canMsg">The CAN message that was first received</param>
        /// <returns>The CAN id for the message received, otherwise 0.</returns>
        private uint waitAnyMessage(uint timeout, out Lawicel.CANUSB.CANMsg r_canMsg)
        {
            CANMessage canMessage = new CANMessage();

            string line = string.Empty;

            int readResult = 0;
            int nrOfWait = 0;
            while (nrOfWait < timeout)
            {
                m_serialPort.Write("\r");
                m_serialPort.Write("P\r");
                bool endofFrames = false;
                while (!endofFrames)
                {
                    Console.WriteLine("reading line");
                    line = m_serialPort.ReadLine();
                    Console.WriteLine("line: " + line + " len: " + line.Length.ToString());
                    if (line[0] == '\x07' || line[0] == '\r' || line[0] == 'A')
                    {
                        endofFrames = true;
                    }
                    else
                    {

                        if (line.Length == 14)
                        {
                            // three bytes identifier
                            r_canMsg = new Lawicel.CANUSB.CANMsg();
                            r_canMsg.id = (uint)Convert.ToInt32(line.Substring(1, 3), 16);
                            r_canMsg.len = (byte)Convert.ToInt32(line.Substring(4, 1), 16);
                            ulong data = 0;
                            // add all the bytes
                            data |= (ulong)(byte)Convert.ToInt32(line.Substring(5, 2), 16) << 7 * 8;
                            data |= (ulong)(byte)Convert.ToInt32(line.Substring(7, 2), 16) << 6 * 8;
                            data |= (ulong)(byte)Convert.ToInt32(line.Substring(9, 2), 16) << 5 * 8;
                            data |= (ulong)(byte)Convert.ToInt32(line.Substring(11, 2), 16) << 4 * 8;
                            data |= (ulong)(byte)Convert.ToInt32(line.Substring(13, 2), 16) << 3 * 8;
                            data |= (ulong)(byte)Convert.ToInt32(line.Substring(15, 2), 16) << 2 * 8;
                            data |= (ulong)(byte)Convert.ToInt32(line.Substring(17, 2), 16) << 1 * 8;
                            data |= (ulong)(byte)Convert.ToInt32(line.Substring(19, 2), 16);
                            r_canMsg.data = data;
                            canMessage.setID(r_canMsg.id);
                            canMessage.setLength(r_canMsg.len);
                            canMessage.setFlags(0);
                            canMessage.setData(r_canMsg.data);

                            return (uint)r_canMsg.id;

                        }
                    }

                }
                //Thread.Sleep(0);
                nrOfWait++;
            }
            r_canMsg = new Lawicel.CANUSB.CANMsg();
            return 0;
        }
开发者ID:josla972,项目名称:Trionic,代码行数:65,代码来源:CANUSBDirectDevice.cs

示例5: readMessages

 /// <summary>
 /// readMessages is the "run" method of this class. It reads all incomming messages
 /// and publishes them to registered ICANListeners.
 /// </summary>
 public void readMessages()
 {
     int readResult = 0;
     EASYSYNC.CANMsg r_canMsg = new EASYSYNC.CANMsg();
     CANMessage canMessage = new CANMessage();
     while (true)
     {
         lock (m_synchObject)
         {
             if (m_endThread)
                 return;
         }
         readResult = EASYSYNC.canusb_Read(m_deviceHandle, out r_canMsg);
         if (readResult == EASYSYNC.ERROR_CANUSB_OK)
         {
             canMessage.setID(r_canMsg.id);
             canMessage.setLength(r_canMsg.len);
             canMessage.setTimeStamp(r_canMsg.timestamp);
             canMessage.setFlags(r_canMsg.flags);
             canMessage.setData(r_canMsg.data);
             lock (m_listeners)
             {
                 foreach (ICANListener listener in m_listeners)
                 {
                     listener.handleMessage(canMessage);
                 }
             }
         }
         else if (readResult == EASYSYNC.ERROR_CANUSB_NO_MESSAGE)
         {
             Thread.Sleep(1);
         }
     }
 }
开发者ID:josla972,项目名称:Trionic,代码行数:38,代码来源:EasySyncUSBDevice.cs


注:本文中的TrionicCANLib.CAN.CANMessage.setFlags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。