Ejemplo n.º 1
0
        private void ReceiveThreadHandler()
        {
            TPCANMsg       msg;
            TPCANTimestamp timestamp;
            TPCANStatus    result;

            try
            {
                while (m_open)
                {
                    var status = PCANBasic.GetStatus(m_handle);
                    if ((status & TPCANStatus.PCAN_ERROR_QRCVEMPTY) == 0) // If NOT empty
                    {
                        result = PCANBasic.Read(m_handle, out msg, out timestamp);
                        if (this.UpdateStatusFromOperation(result) == TPCANStatus.PCAN_ERROR_OK)
                        {
                            System.Diagnostics.Debug.WriteLine("CAN In: " + msg.ID.ToString());
                            this.PutReceivedInQueue(new PCANMessage(msg, timestamp));
                        }
                    }
                    else
                    {
                        Thread.Sleep(5);
                    }
                }
            }
            finally
            {
                m_receiverThread = null;
            }
        }
Ejemplo n.º 2
0
Archivo: PCAN.cs Proyecto: fbstj/lib.cs
        private void _read()
        {               // threaded recieve listener
            AutoResetEvent m_ReceiveEvent = new AutoResetEvent(false);
            UInt32         iBuffer;
            TPCANStatus    stsResult;

            iBuffer = Convert.ToUInt32(m_ReceiveEvent.SafeWaitHandle.DangerousGetHandle().ToInt32());
            // Sets the handle of the Receive-Event.
            stsResult = PCANBasic.SetValue((byte)iface, TPCANParameter.PCAN_RECEIVE_EVENT, ref iBuffer, sizeof(UInt32));

            if (stsResult != TPCANStatus.PCAN_ERROR_OK)
            {
                throw new Exception(GetFormatedError(stsResult));
            }

            while (true)
            {
                if (m_ReceiveEvent.WaitOne(50))
                {                       // wait or sleep
                    TPCANMsg m; TPCANTimestamp ts;
                    do
                    {                           // read all messages from queue, and 'receive' them
                        stsResult = PCANBasic.Read((byte)iface, out m, out ts);

                        if (stsResult == TPCANStatus.PCAN_ERROR_OK)
                        {
                            Receive.Invoke(Frame(m));
                            TimedReceive.Invoke(Time(ts), Frame(m));
                        }
                    } while ((!Convert.ToBoolean(stsResult & TPCANStatus.PCAN_ERROR_QRCVEMPTY)));
                }
            }
        }
Ejemplo n.º 3
0
        private void ReadRawFrame()
        {
            AutoResetEvent can_event = new AutoResetEvent(false);

            uint        numeric_buffer = Convert.ToUInt32(can_event.SafeWaitHandle.DangerousGetHandle().ToInt32());
            TPCANStatus status         = PCANBasic.SetValue(m_sock, TPCANParameter.PCAN_RECEIVE_EVENT, ref numeric_buffer, sizeof(UInt32));

            if (status != TPCANStatus.PCAN_ERROR_OK)
            {
                throw new Exception(GetFormatedError(status));
            }

            TPCANMsg raw_frame;

            while (!m_thread_stop)
            {
                if (can_event.WaitOne(50))
                {
                    do
                    {
                        if ((status = PCANBasic.Read(m_sock, out raw_frame)) == TPCANStatus.PCAN_ERROR_OK)
                        {
                            m_queue_rx.Add(raw_frame);
                        }
                    } while (!Convert.ToBoolean(status & TPCANStatus.PCAN_ERROR_QRCVEMPTY));
                }
            }
        }
Ejemplo n.º 4
0
        private void ReadMessages()
        {
            TPCANMsg       CANMsg;
            TPCANTimestamp CANTimeStamp;
            TPCANStatus    stsResult;

            // We read at least one time the queue looking for messages.
            // If a message is found, we look again trying to find more.
            // If the queue is empty or an error occurr, we get out from
            // the dowhile statement.

            do
            {
                // We execute the "Read" function of the PCANBasic
                //
                stsResult = PCANBasic.Read(m_PcanHandle, out CANMsg, out CANTimeStamp);

                // A message was received
                // We process the message(s)
                //
                if (stsResult == TPCANStatus.PCAN_ERROR_OK)
                {
                    ProcessMessage(CANMsg, CANTimeStamp);
                }
            } while ((!Convert.ToBoolean(stsResult & TPCANStatus.PCAN_ERROR_QRCVEMPTY)));
        }
Ejemplo n.º 5
0
        public TPCANStatus ReadFrame(TPCANHandle CanHandle)
        {
            //CREATE MESSAGE STRUCTURE
            TPCANMsg       CANMsg;
            TPCANTimestamp CANTimeStamp;
            TPCANStatus    stsResult;

            //READ RETURN DATA
            stsResult = PCANBasic.Read(CanHandle, out CANMsg, out CANTimeStamp);

            //IF READ SUCCESS CHANGE PROPERTY, ELSE IF RETURN ERROR
            if (stsResult == TPCANStatus.PCAN_ERROR_OK)
            {
                this.ReturnData.Time   = DateTime.Now.TimeOfDay.ToString();
                this.ReturnData.ID     = Convert.ToString(CANMsg.ID, 16);
                this.ReturnData.Length = CANMsg.DATA.Length.ToString();
                this.ReturnData.Data   = BitConverter.ToString(CANMsg.DATA).Replace("-", " ");

                if (CANMsg.DATA[0] == 3 || CANMsg.DATA[1] == 127)
                {
                    stsResult = TPCANStatus.PCAN_ERROR_RESPONSE;
                }
            }
            return(stsResult);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Function for reading CAN messages on normal CAN devices
        /// </summary>
        /// <returns>A TPCANStatus error code</returns>
        private TPCANStatus ReadMessage()
        {
            TPCANMsg    CANMsg;
            TPCANStatus stsResult;

            // We execute the "Read" function of the PCANBasic
            stsResult = PCANBasic.Read(m_PcanHandle, out CANMsg);
            if (stsResult == TPCANStatus.PCAN_ERROR_OK)
            {
                postMessage(CANMsg);
            }

            return(stsResult);
        }
Ejemplo n.º 7
0
        public Frame ReceiveFrame(bool blocking = true)
        {
            TPCANStatus ret;

            do
            {
                ret = PCANBasic.Read(Channel, out TPCANMsg msg, out TPCANTimestamp time);
                if (ret == TPCANStatus.PCAN_ERROR_OK)
                {
                    var frame = new Frame()
                    {
                        Data = msg.DATA,
                        Id   = (int)msg.ID,
                    };

                    if (msg.MSGTYPE == TPCANMessageType.PCAN_MESSAGE_STANDARD)
                    {
                        frame.Type = FrameType.Standard;
                    }
                    else if (msg.MSGTYPE == TPCANMessageType.PCAN_MESSAGE_EXTENDED)
                    {
                        frame.Type = FrameType.Extended;
                    }
                    else if (msg.MSGTYPE == TPCANMessageType.PCAN_MESSAGE_EXTENDED)
                    {
                        frame.Type = FrameType.Error;
                    }
                    else
                    {
                        return(null);
                    }

                    return(frame);
                }
                else if (ret == TPCANStatus.PCAN_ERROR_QRCVEMPTY)
                {
                    if (!blocking)
                    {
                        return(null);
                    }
                }
                else
                {
                    CheckError(ret);
                }
                Thread.Sleep(1);
            } while (blocking && ret == TPCANStatus.PCAN_ERROR_QRCVEMPTY);
            return(null);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Function for reading CAN messages on normal CAN devices
        /// </summary>
        /// <returns>A TPCANStatus error code</returns>
        private TPCANStatus ReadMessage()
        {
            TPCANMsg    CANMsg;
            TPCANStatus stsResult;

            // We execute the "Read" function of the PCANBasic
            stsResult = PCANBasic.Read(m_PcanHandle, out CANMsg);
            if (stsResult == TPCANStatus.PCAN_ERROR_OK)
            {
                postMessage(CANMsg);
                Logger.Instance.logPacket(CANMsg.DATA, false, (int)CANMsg.ID);
            }

            return(stsResult);
        }
Ejemplo n.º 9
0
        private byte[] SSPC_Ctrl(byte[] msg, bool msginProg)
        {
            TPCANStatus stsResult;

            CANMsgWrite                    = new TPCANMsg();
            CANMsgWrite.LEN                = 8;
            CANMsgWrite.DATA               = new byte[8];
            CANMsgWrite.MSGTYPE            = TPCANMessageType.PCAN_MESSAGE_EXTENDED;
            CANMsgWrite.ID                 = ID1;
            CANMsgWrite.DATA               = msg;
            TPCANTimestamp.micros          = 185;
            TPCANTimestamp.millis          = 158903185;
            TPCANTimestamp.millis_overflow = 0;

            byte[] inComingData = new byte[8];

            stsResult = PCANBasic.GetStatus(m_PcanHandle);


            stsResult = PCANBasic.Write(m_PcanHandle, ref CANMsgWrite);

            if (stsResult != TPCANStatus.PCAN_ERROR_OK)
            {
                MessageBox.Show(Convert.ToString(stsResult));
            }
            else
            {
                System.Threading.Thread.Sleep(10);
                stsResult = PCANBasic.Read(m_PcanHandle, out CANMsgRead, out TPCANTimestamp);
                if (stsResult != TPCANStatus.PCAN_ERROR_OK)
                {
                    MessageBox.Show(Convert.ToString(stsResult));
                }
                else
                {
                    stsResult = PCANBasic.Read(m_PcanHandle, out CANMsgRead, out TPCANTimestamp);

                    for (int i = 0; i < CANMsgRead.LEN; i++)
                    {
                        inComingData[i] = CANMsgRead.DATA[i];
                    }
                }
            }
            return(inComingData);
        }
Ejemplo n.º 10
0
        private void Read(Object source, ElapsedEventArgs e)
        {
            TPCANMsg       CANMsg;
            TPCANTimestamp CANTimeStamp;
            TPCANStatus    stsResult;

            // We read at least one time the queue looking for messages.
            // If a message is found, we look again trying to find more.
            // If the queue is empty or an error occurr, we get out from
            // the dowhile statement.
            //
            do
            {
                // We execute the "Read" function of the PCANBasic
                //
                stsResult = PCANBasic.Read(mChannel, out CANMsg, out CANTimeStamp);
                // A message was received
                if (stsResult == TPCANStatus.PCAN_ERROR_OK)
                {
                    Console.WriteLine("COBID: 0x{0:X}\t LEN: {1}\t DATA: {2}", CANMsg.ID, CANMsg.LEN, BitConverter.ToString(CANMsg.DATA));
                    MessageStatus msg = DecodeMessage(CANMsg, CANTimeStamp);
                }
            } while (mReadingTimer.Enabled && (!Convert.ToBoolean(stsResult & TPCANStatus.PCAN_ERROR_QRCVEMPTY)));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// get can bus response data
        /// </summary>
        /// <param name="destID"></param>
        /// <param name="source"></param>
        /// <param name="command"></param>
        /// <param name="waitTime"></param>
        /// <param name="receiveDataLen"></param>
        /// <returns></returns>
        public CanbusMessage getCanBusResponseData(int destID, int source, int command, double waitTime)
        {
            TPCANMsg CANMsg;
            // While this mode is selected
            TPCANTimestamp CANTimeStamp;
            TPCANStatus    stsResult;
            DateTime       now      = DateTime.Now;
            DateTime       end      = now.AddSeconds(waitTime);
            int            flag_num = 0;

            lock (this.lockObjForPowerOnThreadAndMessageReq)
            {
                while (this.isRunning)
                {
                    now = DateTime.Now;
                    if (now > end)    // if waiting time is over 1.5s, we think it has no response
                    {
                        return(null); //
                    }
                    // Waiting for Receive-Event
                    //if (m_ReceiveEvent.WaitOne(50))
                    {
                        do
                        {
                            stsResult = PCANBasic.Read(this._canChannel, out CANMsg, out CANTimeStamp);
                            if (stsResult == TPCANStatus.PCAN_ERROR_OK)
                            {
                                if (destID != -1 && CANMsg.ID != destID)
                                {
                                    continue;                                       // it was not from specify node
                                }
                                if (CANMsg.LEN < 1)
                                {
                                    continue;
                                }

                                if (source != -1 && CANMsg.DATA[1] != source)
                                {
                                    continue;
                                }
                                if (command != -1 && CANMsg.DATA[0] != command)
                                {
                                    continue;
                                }

                                //receiveDataLen = CANMsg.LEN;
                                CanbusMessage message = new CanbusMessage(DateTime.Now, (int)CANMsg.ID, CANMsg.LEN, CANMsg.DATA);
                                return(message);
                            }
                            flag_num++;
                            if (flag_num >= 1000)
                            {
                                flag_num = 0;
                                now      = DateTime.Now;
                                if (now > end)    // if waiting over time, we think it has no response
                                {
                                    return(null); //
                                }
                            }
                        } while (this.isRunning && (!Convert.ToBoolean(stsResult & TPCANStatus.PCAN_ERROR_QRCVEMPTY)));
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Receives the board information.
        /// </summary>
        /// <param name="destId">The dest id.</param>
        /// <param name="sourceId">The source id.</param>
        /// <param name="responseCommand">The response command.</param>
        /// <returns>board info bytes</returns>
        public List <byte> receiveBoardInformation(int destId, int sourceId, int responseCommand)
        {
            /* test code
             * List<byte> bytes = new List<byte>();
             * for ( int i = 0; i < 24; i++ )
             * {
             *  bytes.Add( (byte)i );
             * }
             * return bytes;
             * //*/
            double   waitTime = 0.5;
            TPCANMsg CANMsg;
            // While this mode is selected
            TPCANTimestamp CANTimeStamp;
            TPCANStatus    stsResult;
            DateTime       now = DateTime.Now;
            DateTime       end = now.AddSeconds(waitTime);

            List <byte> boardInfoBytes = new List <byte>();
            int         receiveIndex   = 1;
            bool        isBreak        = false;
            int         cycle          = 0;

            while (this.isRunning)
            {
                if (isBreak)
                {
                    break;
                }
                now = DateTime.Now;
                if (now > end)// if waiting time is over setting, we think it has no response
                {
                    break;
                }
                // Waiting for Receive-Event
                //if (m_ReceiveEvent.WaitOne(50))
                {
                    do
                    {
                        cycle++;
                        stsResult = PCANBasic.Read(this._canChannel, out CANMsg, out CANTimeStamp);
                        if (stsResult == TPCANStatus.PCAN_ERROR_OK)
                        {
                            if (CANMsg.LEN < 8)
                            {
                                continue;
                            }
                            if (CANMsg.ID != destId)
                            {
                                continue;
                            }
                            if (CANMsg.DATA[0] != responseCommand)
                            {
                                continue;
                            }
                            if (CANMsg.DATA[1] != sourceId)
                            {
                                continue;
                            }
                            if (CANMsg.DATA[3] == receiveIndex)
                            {
                                for (int j = 4; j <= 7; j++)
                                {
                                    boardInfoBytes.Add(CANMsg.DATA[j]);
                                }
                                receiveIndex++;
                                if (receiveIndex == 7)// receive 6 fill packages,.
                                {
                                    isBreak = true;
                                    break;
                                }
                            }
                            else
                            {
                                if (receiveIndex == 1)
                                {
                                    continue;
                                }
                                else
                                {
                                    isBreak = true;
                                    break;
                                }
                            }
                        }
                        if (cycle >= 1000)
                        {
                            now = DateTime.Now;
                            if (now > end)// if waiting time is over setting, we think it has no response
                            {
                                isBreak = true;
                                break;
                            }
                            cycle = 0;
                        }
                    } while (this.isRunning && (!Convert.ToBoolean(stsResult & TPCANStatus.PCAN_ERROR_QRCVEMPTY)));
                }
            }
            return(boardInfoBytes);
        }
Ejemplo n.º 13
0
        public __CanMsg ReadCan(short Ch, bool FDFlag = false)
        {
            __CanMsg    Msg = new __CanMsg();
            TPCANStatus stsResult;

            // We execute the "Read" function of the PCANBasic
            //
            Msg.DATA   = new byte[8];
            Msg.ID     = -1;
            Msg.Length = 0;

#if PROGRAM_RUNNING
            try
            {
                try
                {
                    for (int i = 0; i < 8; i++)
                    {
                        Msg.DATA[i] = 0x00;
                    }


                    if (FDFlag == false)
                    {
                        TPCANMsg       CANMsg;
                        TPCANTimestamp CANTimeStamp;

                        stsResult = PCANBasic.Read(m_PcanHandle[Ch], out CANMsg, out CANTimeStamp);
                        if (stsResult == TPCANStatus.PCAN_ERROR_OK)
                        {
                            Msg.ID     = (int)CANMsg.ID;
                            Msg.Length = CANMsg.LEN;

                            for (int i = 0; i < CANMsg.LEN; i++)
                            {
                                Msg.DATA[i] = CANMsg.DATA[i];
                            }

                            if (NgCountCheckFlag == true)
                            {
                                if (OkCount < 100)
                                {
                                    OkCount++;
                                }
                            }
                        }

                        if (mControl.PublicFunction != null)
                        {
                            Last = mControl.PublicFunction.timeGetTimems();
                            if (1000 <= (Last - First))
                            {
                                CanReceiveReset(Ch);
                                First = mControl.PublicFunction.timeGetTimems();
                            }
                        }
                    }
                    else
                    {
                        TPCANMsgFD       CANMsg;
                        TPCANTimestampFD CANTimeStamp;


                        // We execute the "Read" function of the PCANBasic
                        //
                        stsResult = PCANBasic.ReadFD(m_PcanHandle[Ch], out CANMsg, out CANTimeStamp);
                        if (stsResult == TPCANStatus.PCAN_ERROR_OK)
                        {
                            Msg.ID     = (int)CANMsg.ID;
                            Msg.Length = CANMsg.DLC;

                            for (int i = 0; i < CANMsg.DLC; i++)
                            {
                                Msg.DATA[i] = CANMsg.DATA[i];
                            }

                            if (NgCountCheckFlag == true)
                            {
                                if (OkCount < 100)
                                {
                                    OkCount++;
                                }
                            }
                        }
                    }
                }
                catch (Exception fMsg)
                {
                    //MessageBox.Show(fMsg.Message + "\n" + fMsg.StackTrace);
                    uMessageBox.Show(title: "경고", promptText: fMsg.Message + "\n" + fMsg.StackTrace); //MessageBox.Show(GetFormatedError(stsResult));
                }
            }
            finally
            {
            }
#endif
            return(Msg);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Receives the board information.
        /// </summary>
        /// <param name="destId">The dest id.</param>
        /// <param name="sourceId">The source id.</param>
        /// <param name="responseCommand">The response command.</param>
        /// <returns>board info bytes</returns>
        public List <byte> receiveDirctionModuleInformation(int canbusID, int sourceId, int responseCommand)
        {
            double   waitTime = 0.6;
            TPCANMsg CANMsg;
            // While this mode is selected
            TPCANTimestamp CANTimeStamp;
            TPCANStatus    stsResult;
            DateTime       now          = DateTime.Now;
            DateTime       end          = now.AddSeconds(waitTime);
            List <byte[]>  receivedData = new List <byte[]>();
            bool           isBreak      = false;
            int            cycle        = 0;

            while (this.isRunning)
            {
                if (isBreak)
                {
                    break;
                }
                now = DateTime.Now;
                if (now > end)  // if waiting time is over setting, we think it has no response
                {
                    break;
                }
                // Waiting for Receive-Event
                //if (m_ReceiveEvent.WaitOne(50))
                {
                    do
                    {
                        cycle++;
                        stsResult = PCANBasic.Read(this._canChannel, out CANMsg, out CANTimeStamp);
                        if (stsResult == TPCANStatus.PCAN_ERROR_OK)
                        {
                            if (CANMsg.LEN <= 4)
                            {
                                continue;
                            }
                            if (CANMsg.ID != canbusID)
                            {
                                continue;
                            }
                            if (CANMsg.DATA[0] != responseCommand)
                            {
                                continue;
                            }
                            if (CANMsg.DATA[1] != sourceId)
                            {
                                continue;
                            }

                            receivedData.Add((byte[])CANMsg.DATA.Clone());
                        }
                        if (cycle >= 1000)
                        {
                            now = DateTime.Now;
                            if (now > end)  // if waiting time is over setting, we think it has no response
                            {
                                isBreak = true;
                                break;
                            }
                            cycle = 0;
                        }
                    } while (this.isRunning && (!Convert.ToBoolean(stsResult & TPCANStatus.PCAN_ERROR_QRCVEMPTY)));
                }
            }

            /*
             * receivedData.Clear();
             *
             * receivedData.Add( new byte[] { 0xC6, 0x95, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00 } );
             * receivedData.Add( new byte[] { 0xC6, 0x95, 0x01, 0x00, 0x41, 0x50, 0x53, 0x20 } );
             * receivedData.Add( new byte[] { 0xC6, 0x95, 0x02, 0x00, 0x20, 0x45, 0x44, 0x30 } );
             * receivedData.Add( new byte[] { 0xC6, 0x95, 0x03, 0x00, 0x31, 0x30, 0x35, 0x48 } );
             * receivedData.Add( new byte[] { 0xC6, 0x95, 0x04, 0x00, 0x4E, 0x20, 0x56, 0x65 } );
             * receivedData.Add( new byte[] { 0xC6, 0x95, 0x05, 0x00, 0x72, 0x3A, 0x34, 0x2E } );
             * receivedData.Add( new byte[] { 0xC6, 0x95, 0x06, 0x00, 0x31, 0x4E, 0x65, 0x74 } );
             * receivedData.Add( new byte[] { 0xC6, 0x95, 0x07, 0x00, 0x75, 0x43, 0x45, 0x78 } );
             * receivedData.Add( new byte[] { 0xC6, 0x95, 0x08, 0x00, 0x0D, 0x0D, 0x0A, 0x04 } );
             */

            List <byte> informationBytes = new List <byte>();

            if (receivedData.Count > 0)
            {
                int  dataLen  = 0;
                bool isFinish = false;
                for (int i = 0; i < receivedData.Count; i++)
                {
                    byte[] nextData = null;
                    for (int j = 0; j < receivedData.Count; j++)
                    {
                        byte[] onePackage = receivedData[j];
                        if ((onePackage[2] + (onePackage[3] << 8)) == i)
                        {
                            nextData = onePackage;
                            //receivedData.RemoveAt( j );
                            break;
                        }
                    }
                    if (nextData == null)
                    {
                        isFinish = true;
                    }
                    else
                    {
                        if (i == 0)
                        {
                            if (nextData.Length < 6)
                            {
                                isFinish = true;
                            }
                            else
                            {
                                dataLen = nextData[4] + (nextData[5] << 8);
                                if (dataLen <= 0)
                                {
                                    isFinish = true;
                                }
                            }
                        }
                        else
                        {
                            if (nextData.Length < 4)
                            {
                                isFinish = true;
                            }
                            else
                            {
                                int pDataLen   = nextData.Length - 4;
                                int needNumber = dataLen - informationBytes.Count;
                                if (pDataLen < needNumber)
                                {
                                    needNumber = pDataLen;
                                }
                                else
                                {
                                    isFinish = true;
                                }
                                for (int di = 4; di < 4 + needNumber; di++)
                                {
                                    informationBytes.Add(nextData[di]);
                                }
                            }
                        }
                    }
                    if (isFinish)
                    {
                        break;
                    }
                }
            }
            return(informationBytes);
        }
Ejemplo n.º 15
0
        private void boardVoltage_thread(Object source, ElapsedEventArgs e)
        {
            TPCANStatus stsResult;

            CANMsgWrite         = new TPCANMsg();
            CANMsgWrite.LEN     = 8;
            CANMsgWrite.DATA    = new byte[8];
            CANMsgWrite.MSGTYPE = TPCANMessageType.PCAN_MESSAGE_EXTENDED;
            CANMsgWrite.ID      = ID1;
            CANMsgWrite.DATA    = new byte[8];

            CANMsgRead.ID                  = 0;
            CANMsgRead.LEN                 = 8;
            TPCANTimestamp.micros          = 185;
            TPCANTimestamp.millis          = 158903185;
            TPCANTimestamp.millis_overflow = 0;
            byte counTer = 0;

            byte[] writeMSG     = new byte[8];
            byte[] dataRead     = new byte[8];
            byte[] dataReadchnl = new byte[8];
            byte   chnlCount    = 0;
            byte   groupCount   = 0;
            bool   skipProcess  = false;

            int[] dataInPUT = new int[15];

            try
            {
                CANMsgWrite.ID      = 418377632;
                CANMsgWrite.DATA[0] = 0x3D;
                CANMsgWrite.DATA[1] = 0x00;
                CANMsgWrite.DATA[2] = 0x00;
                CANMsgWrite.DATA[3] = 0x00;
                CANMsgWrite.DATA[4] = 0x00;
                CANMsgWrite.DATA[5] = 0x00;
                CANMsgWrite.DATA[6] = 0x00;
                CANMsgWrite.DATA[7] = 0x00;
            }
            catch (System.NullReferenceException)
            {
            }

            stsResult = PCANBasic.Write(m_PcanHandle, ref CANMsgWrite);

            if (stsResult != TPCANStatus.PCAN_ERROR_OK)
            {
                //     MessageBox.Show(Convert.ToString(stsResult));
            }
            System.Threading.Thread.Sleep(5);
            while (CANMsgRead.ID != 418357487)
            {
                if (counTer > 5)
                {
                    counTer     = 0;
                    skipProcess = true;
                    break;
                }
                stsResult = PCANBasic.Read(m_PcanHandle, out CANMsgRead, out TPCANTimestamp);
                counTer++;
            }

            if ((skipProcess == false) && (CANMsgRead.DATA[0] == 0x3E))
            {
                for (int i = 0; i < CANMsgRead.LEN; i++)
                {
                    dataInPUT[i] = CANMsgRead.DATA[i];
                }
                inComingBrdData[0] = (dataInPUT[2] + dataInPUT[3] * 256) / 10;
            }


            skipProcess = false;
            counTer     = 0;


            CANMsgWrite.ID      = 418377633;
            CANMsgWrite.DATA[0] = 0xA3;
            CANMsgWrite.DATA[1] = 0x00;
            CANMsgWrite.DATA[2] = 0x00;
            CANMsgWrite.DATA[3] = 0x00;
            CANMsgWrite.DATA[4] = 0x00;
            CANMsgWrite.DATA[5] = 0x00;
            CANMsgWrite.DATA[6] = 0x00;
            CANMsgWrite.DATA[7] = 0x00;

            stsResult = PCANBasic.Write(m_PcanHandle, ref CANMsgWrite);
            if (stsResult != TPCANStatus.PCAN_ERROR_OK)
            {
            }

            System.Threading.Thread.Sleep(5);
            stsResult = PCANBasic.Read(m_PcanHandle, out CANMsgRead, out TPCANTimestamp);
            if ((CANMsgRead.DATA[0] == 0xA4) && (CANMsgRead.DATA[4] + CANMsgRead.DATA[5] < 255))
            {
                for (int i = 0; i < CANMsgRead.LEN; i++)
                {
                    dataInPUT[i] = CANMsgRead.DATA[i];
                }
                inComingBrdData[1] = ((dataInPUT[4] + (dataInPUT[5] * 256) + (dataInPUT[6] * 65536) + (dataInPUT[7] * 16777216)) / 100);
            }

            CANMsgWrite.ID      = 418377635;
            CANMsgWrite.DATA[0] = 0x05;
            CANMsgWrite.DATA[1] = 0x00;
            CANMsgWrite.DATA[2] = 0x00;
            CANMsgWrite.DATA[3] = 0x00;
            CANMsgWrite.DATA[4] = 0x00;
            CANMsgWrite.DATA[5] = 0x00;
            CANMsgWrite.DATA[6] = 0x00;
            CANMsgWrite.DATA[7] = 0x00;

            stsResult = PCANBasic.Write(m_PcanHandle, ref CANMsgWrite);
            if (stsResult != TPCANStatus.PCAN_ERROR_OK)
            {
            }

            System.Threading.Thread.Sleep(5);
            stsResult = PCANBasic.Read(m_PcanHandle, out CANMsgRead, out TPCANTimestamp);
            if (CANMsgRead.DATA[0] == 06)
            {
                for (int i = 0; i < CANMsgRead.LEN; i++)
                {
                    dataInPUT[i] = CANMsgRead.DATA[i];
                }
                inComingChnlData[0, 3] = dataInPUT[2] & 0x01;
                inComingChnlData[1, 3] = dataInPUT[2] & 0x02;
                inComingChnlData[2, 3] = dataInPUT[2] & 0x04;
                inComingChnlData[3, 3] = dataInPUT[2] & 0x08;
                inComingChnlData[4, 3] = dataInPUT[2] & 0x10;
                inComingChnlData[5, 3] = dataInPUT[2] & 0x20;
                inComingChnlData[6, 3] = dataInPUT[2] & 0x40;
                inComingChnlData[7, 3] = dataInPUT[2] & 0x80;
            }

            CANMsgWrite.DATA[0] = 0x0D;
            CANMsgWrite.DATA[1] = 0x00;
            CANMsgWrite.DATA[2] = 0x00;
            CANMsgWrite.DATA[3] = 0x00;
            CANMsgWrite.DATA[4] = 0x00;
            CANMsgWrite.DATA[5] = 0x00;
            CANMsgWrite.DATA[6] = 0x00;
            CANMsgWrite.DATA[7] = 0x00;
            stsResult           = PCANBasic.Write(m_PcanHandle, ref CANMsgWrite);
            if (stsResult != TPCANStatus.PCAN_ERROR_OK)
            {
            }

            System.Threading.Thread.Sleep(5);
            stsResult = PCANBasic.Read(m_PcanHandle, out CANMsgRead, out TPCANTimestamp);

            if (CANMsgRead.DATA[0] == 0x0E)
            {
                for (int i = 0; i < CANMsgRead.LEN; i++)
                {
                    dataInPUT[i] = CANMsgRead.DATA[i];
                }
                inComingChnlData[0, 4] = dataInPUT[2] & 0x01;
                inComingChnlData[1, 4] = dataInPUT[2] & 0x02;
                inComingChnlData[2, 4] = dataInPUT[2] & 0x04;
                inComingChnlData[3, 4] = dataInPUT[2] & 0x08;
                inComingChnlData[4, 4] = dataInPUT[2] & 0x10;
                inComingChnlData[5, 4] = dataInPUT[2] & 0x20;
                inComingChnlData[6, 4] = dataInPUT[2] & 0x40;
                inComingChnlData[7, 4] = dataInPUT[2] & 0x80;
            }

            CANMsgWrite.DATA[0] = 0x07;
            CANMsgWrite.DATA[1] = 0x00;
            CANMsgWrite.DATA[2] = 0x00;
            CANMsgWrite.DATA[3] = 0x00;
            CANMsgWrite.DATA[4] = 0x00;
            CANMsgWrite.DATA[5] = 0x00;
            CANMsgWrite.DATA[6] = 0x00;
            CANMsgWrite.DATA[7] = 0x00;

            stsResult = PCANBasic.Write(m_PcanHandle, ref CANMsgWrite);
            if (stsResult != TPCANStatus.PCAN_ERROR_OK)
            {
            }

            System.Threading.Thread.Sleep(5);
            stsResult = PCANBasic.Read(m_PcanHandle, out CANMsgRead, out TPCANTimestamp);

            if (CANMsgRead.DATA[0] == 0x08)
            {
                for (int i = 0; i < CANMsgRead.LEN; i++)
                {
                    dataInPUT[i] = CANMsgRead.DATA[i];
                }
                inComingChnlData[0, 5] = dataInPUT[2] & 0x01;
                inComingChnlData[1, 5] = dataInPUT[2] & 0x02;
                inComingChnlData[2, 5] = dataInPUT[2] & 0x04;
                inComingChnlData[3, 5] = dataInPUT[2] & 0x08;
                inComingChnlData[4, 5] = dataInPUT[2] & 0x10;
                inComingChnlData[5, 5] = dataInPUT[2] & 0x20;
                inComingChnlData[6, 5] = dataInPUT[2] & 0x40;
                inComingChnlData[7, 5] = dataInPUT[2] & 0x80;
            }

            CANMsgWrite.DATA[0] = 0x49;
            CANMsgWrite.DATA[1] = 0x00;
            CANMsgWrite.DATA[2] = 0x00;
            CANMsgWrite.DATA[3] = 0x00;
            CANMsgWrite.DATA[4] = 0x00;
            CANMsgWrite.DATA[5] = 0x00;
            CANMsgWrite.DATA[6] = 0x00;
            CANMsgWrite.DATA[7] = 0x00;

            stsResult = PCANBasic.Write(m_PcanHandle, ref CANMsgWrite);
            if (stsResult != TPCANStatus.PCAN_ERROR_OK)
            {
            }
            System.Threading.Thread.Sleep(5);
            stsResult = PCANBasic.Read(m_PcanHandle, out CANMsgRead, out TPCANTimestamp);

            if (CANMsgRead.DATA[0] == 0x4A)
            {
                for (int i = 0; i < CANMsgRead.LEN; i++)
                {
                    dataInPUT[i] = CANMsgRead.DATA[i];
                }

                inComingChnlData[0, 6] = dataInPUT[2] & 0x01;
                inComingChnlData[1, 6] = dataInPUT[2] & 0x02;
                inComingChnlData[2, 6] = dataInPUT[2] & 0x04;
                inComingChnlData[3, 6] = dataInPUT[2] & 0x08;
                inComingChnlData[4, 6] = dataInPUT[2] & 0x10;
                inComingChnlData[5, 6] = dataInPUT[2] & 0x20;
                inComingChnlData[6, 6] = dataInPUT[2] & 0x40;
                inComingChnlData[7, 6] = dataInPUT[2] & 0x80;
            }

            CANMsgWrite.DATA[0] = 0x43;
            CANMsgWrite.DATA[1] = 0x00;
            CANMsgWrite.DATA[2] = 0x00;
            CANMsgWrite.DATA[3] = 0x00;
            CANMsgWrite.DATA[4] = 0x00;
            CANMsgWrite.DATA[5] = 0x00;
            CANMsgWrite.DATA[6] = 0x00;
            CANMsgWrite.DATA[7] = 0x00;

            stsResult = PCANBasic.Write(m_PcanHandle, ref CANMsgWrite);
            if (stsResult != TPCANStatus.PCAN_ERROR_OK)
            {
            }
            System.Threading.Thread.Sleep(5);
            stsResult = PCANBasic.Read(m_PcanHandle, out CANMsgRead, out TPCANTimestamp);

            if (CANMsgRead.DATA[0] == 0x44)
            {
                for (int i = 0; i < CANMsgRead.LEN; i++)
                {
                    dataInPUT[i] = CANMsgRead.DATA[i];
                }
                inComingChnlData[0, 7] = dataInPUT[2] & 0x01;
                inComingChnlData[1, 7] = dataInPUT[2] & 0x02;
                inComingChnlData[2, 7] = dataInPUT[2] & 0x04;
                inComingChnlData[3, 7] = dataInPUT[2] & 0x08;
                inComingChnlData[4, 7] = dataInPUT[2] & 0x10;
                inComingChnlData[5, 7] = dataInPUT[2] & 0x20;
                inComingChnlData[6, 7] = dataInPUT[2] & 0x40;
                inComingChnlData[7, 7] = dataInPUT[2] & 0x80;
            }


            while (chnlCount < 0x08)
            {
                if (groupModeSwitch.IsOn == true)
                {
                    try
                    {
                        CANMsgWrite.ID      = 418377634;
                        CANMsgWrite.DATA[0] = 0x35;
                        CANMsgWrite.DATA[1] = groupArray[groupCount];
                        CANMsgWrite.DATA[2] = 0x00;
                        CANMsgWrite.DATA[3] = 0x00;
                        CANMsgWrite.DATA[4] = 0x00;
                        CANMsgWrite.DATA[5] = 0x00;
                        CANMsgWrite.DATA[6] = 0x00;
                        CANMsgWrite.DATA[7] = 0x00;
                    }
                    catch (System.NullReferenceException)
                    {
                    }
                }
                else
                {
                    try
                    {
                        CANMsgWrite.ID      = 418377634;
                        CANMsgWrite.DATA[0] = 0x35;
                        CANMsgWrite.DATA[1] = chnlArray[chnlCount];
                        CANMsgWrite.DATA[2] = 0x00;
                        CANMsgWrite.DATA[3] = 0x00;
                        CANMsgWrite.DATA[4] = 0x00;
                        CANMsgWrite.DATA[5] = 0x00;
                        CANMsgWrite.DATA[6] = 0x00;
                        CANMsgWrite.DATA[7] = 0x00;
                    }
                    catch (System.NullReferenceException)
                    {
                    }
                }
                stsResult = PCANBasic.Write(m_PcanHandle, ref CANMsgWrite);
                if (stsResult != TPCANStatus.PCAN_ERROR_OK)
                {
                }
                System.Threading.Thread.Sleep(20);
                stsResult = PCANBasic.Read(m_PcanHandle, out CANMsgRead, out TPCANTimestamp);

                if ((CANMsgRead.DATA[0] == 0x36) && ((CANMsgRead.DATA[1] == chnlArray[chnlCount]) || (CANMsgRead.DATA[1] == groupArray[groupCount])) && (CANMsgRead.DATA[2] + CANMsgRead.DATA[3] < 255))
                {
                    for (int i = 0; i < CANMsgRead.LEN; i++)
                    {
                        dataInPUT[i] = CANMsgRead.DATA[i];
                    }
                    inComingChnlData[chnlCount, 0] = chnlCount;
                    inComingChnlData[chnlCount, 1] = ((dataInPUT[2]) + ((dataInPUT[3]) * 256)) / 10;
                }

                if (groupModeSwitch.IsOn == true)
                {
                    try
                    {
                        CANMsgWrite.ID      = 418377636;
                        CANMsgWrite.DATA[0] = 0x0F;
                        CANMsgWrite.DATA[1] = groupArray[groupCount];
                        CANMsgWrite.DATA[2] = 0x00;
                        CANMsgWrite.DATA[3] = 0x00;
                        CANMsgWrite.DATA[4] = 0x00;
                        CANMsgWrite.DATA[5] = 0x00;
                        CANMsgWrite.DATA[6] = 0x00;
                        CANMsgWrite.DATA[7] = 0x00;
                    }
                    catch (System.NullReferenceException)
                    {
                    }
                }
                else
                {
                    try
                    {
                        CANMsgWrite.ID      = 418377636;
                        CANMsgWrite.DATA[0] = 0x0F;
                        CANMsgWrite.DATA[1] = chnlArray[chnlCount];
                        CANMsgWrite.DATA[2] = 0x00;
                        CANMsgWrite.DATA[3] = 0x00;
                        CANMsgWrite.DATA[4] = 0x00;
                        CANMsgWrite.DATA[5] = 0x00;
                        CANMsgWrite.DATA[6] = 0x00;
                        CANMsgWrite.DATA[7] = 0x00;
                    }
                    catch (System.NullReferenceException)
                    {
                    }
                }

                stsResult = PCANBasic.Write(m_PcanHandle, ref CANMsgWrite);
                if (stsResult != TPCANStatus.PCAN_ERROR_OK)
                {
                }

                System.Threading.Thread.Sleep(20);
                stsResult = PCANBasic.Read(m_PcanHandle, out CANMsgRead, out TPCANTimestamp);

                if ((CANMsgRead.DATA[0] == 0x10) && ((CANMsgRead.DATA[1] == chnlArray[chnlCount]) || (CANMsgRead.DATA[1] == groupArray[groupCount])) && (CANMsgRead.DATA[2] + CANMsgRead.DATA[3] < 250))
                {
                    for (int i = 0; i < CANMsgRead.LEN; i++)
                    {
                        dataInPUT[i] = CANMsgRead.DATA[i];
                    }
                    inComingChnlData[chnlCount, 0] = chnlCount;
                    inComingChnlData[chnlCount, 2] = (((dataInPUT[2]) + (dataInPUT[3])));
                }
                if (groupModeSwitch.IsOn == true)
                {
                    try
                    {
                        CANMsgWrite.ID      = 418377639;
                        CANMsgWrite.DATA[0] = 0x03;
                        CANMsgWrite.DATA[1] = groupArray[groupCount];
                        CANMsgWrite.DATA[2] = 0x00;
                        CANMsgWrite.DATA[3] = 0x00;
                        CANMsgWrite.DATA[4] = 0x00;
                        CANMsgWrite.DATA[5] = 0x00;
                        CANMsgWrite.DATA[6] = 0x00;
                        CANMsgWrite.DATA[7] = 0x00;
                    }
                    catch (System.NullReferenceException)
                    {
                    }
                }
                else
                {
                    try
                    {
                        CANMsgWrite.ID      = 418377639;
                        CANMsgWrite.DATA[0] = 0x03;
                        CANMsgWrite.DATA[1] = chnlArray[chnlCount];
                        CANMsgWrite.DATA[2] = 0x00;
                        CANMsgWrite.DATA[3] = 0x00;
                        CANMsgWrite.DATA[4] = 0x00;
                        CANMsgWrite.DATA[5] = 0x00;
                        CANMsgWrite.DATA[6] = 0x00;
                        CANMsgWrite.DATA[7] = 0x00;
                    }
                    catch (System.NullReferenceException)
                    {
                    }
                }

                stsResult = PCANBasic.Write(m_PcanHandle, ref CANMsgWrite);
                if (stsResult != TPCANStatus.PCAN_ERROR_OK)
                {
                }

                System.Threading.Thread.Sleep(10);
                stsResult = PCANBasic.Read(m_PcanHandle, out CANMsgRead, out TPCANTimestamp);
                if ((CANMsgRead.DATA[0] == 0x04) && (CANMsgRead.DATA[1] == chnlArray[chnlCount]))
                {
                    for (int i = 0; i < CANMsgRead.LEN; i++)
                    {
                        dataInPUT[i] = CANMsgRead.DATA[i];
                    }
                    inComingChnlData[chnlCount, 8] = ((dataInPUT[2] * (10 - 1) / 255) + 1);
                }
                if (groupModeSwitch.IsOn == true)
                {
                    groupCount++;
                    if (groupCount > 0x03)
                    {
                        groupCount = 0;
                    }
                }
                else
                {
                    chnlCount++;
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Function for reading PCAN-Basic messages
        /// </summary>
        public void ReadMessages()
        {
            TPCANStatus stsResult;

            // We read at least one time the queue looking for messages.
            // If a message is found, we look again trying to find more.
            // If the queue is empty or an error occurr, we get out from
            // the dowhile statement.
            //
            //do

            byte[] byRecvData = new byte[256];
            int    nRecvCount = 0;

            while (true)
            {
                TPCANMsg       CANMsg;
                TPCANTimestamp CANTimeStamp;
                string         idStr = string.Empty;
                //TPCANStatus stsResult;

                // We execute the "Read" function of the PCANBasic
                //
                stsResult = PCANBasic.Read(m_PcanHandle, out CANMsg, out CANTimeStamp);
                if (stsResult != TPCANStatus.PCAN_ERROR_QRCVEMPTY)
                {  // We process the received message
                    //
                    if ((CANMsg.ID & 0xFF) == 0x00 && RaiseRecvDataEvent != null)
                    {
                        byte[] byData = new byte[nRecvCount + CANMsg.LEN];
                        Buffer.BlockCopy(byRecvData, 0, byData, 0, nRecvCount);
                        Buffer.BlockCopy(CANMsg.DATA, 0, byData, nRecvCount, CANMsg.LEN);

                        OnRaiseRecvDataEvent(this, new CANEvent()
                        {
                            eventType = CANEventType.ReceEvent,
                            //ID = recvData.ID,
                            DataLen = byRecvData[2],

                            ID       = CANMsg.ID.ToString("X"),
                            listData = new List <byte>(byData)
                        });

                        nRecvCount = 0;
                        nTimes++;
                    }
                    else
                    {
                        Buffer.BlockCopy(CANMsg.DATA, 0, byRecvData, nRecvCount, CANMsg.LEN);
                        nRecvCount += CANMsg.LEN;
                    }
                }
                else
                {
                    Thread.Sleep(300);
                }
                //stsResult = ReadMessage();
                if (stsResult == TPCANStatus.PCAN_ERROR_ILLOPERATION)
                {
                    break;
                }
            }
            //while (MainWindow.m_statusBarInfo.IsOnline && (!Convert.ToBoolean(stsResult & TPCANStatus.PCAN_ERROR_QRCVEMPTY)));
        }
Ejemplo n.º 17
0
        unsafe private void receivingThread()
        {
            int i;
            int rx_index = 0;

            rxCANOBJLIST.Clear();
            TPCANStatus stsResult = 0;

            while (true)
            {
                //arrCANOBJ[33000] = new VCI_CAN_OBJ();
                do
                {
                    if (Form_SetCANParam.form_setcan.checkCANFDMode.Checked == false)//非FD
                    {
                        TPCANMsg       CANMsg;
                        TPCANTimestamp CANTimeStamp;
                        stsResult = PCANBasic.Read(PCAN_PARA1.PCANIndex, out CANMsg, out CANTimeStamp);
                        //if (stsResult == TPCANStatus.PCAN_ERROR_OK)
                        if (stsResult != TPCANStatus.PCAN_ERROR_QRCVEMPTY)
                        {
                            arrCANOBJ[rx_index].ID      = CANMsg.ID;
                            arrCANOBJ[rx_index].DataLen = CANMsg.LEN;

                            if (((byte)CANMsg.MSGTYPE & (byte)0x02) == 0x02)//是扩展帧
                            {
                                arrCANOBJ[rx_index].ExternFlag = 1;
                            }
                            else
                            {
                                arrCANOBJ[rx_index].ExternFlag = 0;
                            }

                            if (((byte)CANMsg.MSGTYPE & (byte)0x01) == 0x01)//是请求帧
                            {
                                arrCANOBJ[rx_index].RemoteFlag = 1;
                            }
                            else
                            {
                                arrCANOBJ[rx_index].RemoteFlag = 0;
                            }

                            arrCANOBJ[rx_index].TimeStamp = Convert.ToUInt64(CANTimeStamp.micros + 1000 * CANTimeStamp.millis + 0x100000000 * 1000 * CANTimeStamp.millis_overflow);

                            for (i = 0; i < CANMsg.LEN; i++)//原来用8固定长度
                            {
                                arrCANOBJ[rx_index].Data[i] = CANMsg.DATA[i];
                            }
                            rx_pkg_counts++;
                            rx_index++;
                            if (rx_index > 32768)
                            {
                                rx_index = 32767;
                            }
                            //Form_BasicFunction.form_basic.RXCountsLabel.Text = "Rx:" + rx_pkgcounts;//耗时2ms

                            /* if (ProcessingFrame == null)
                             * {
                             *   if (rxCANOBJLIST.Count >= 100000)
                             *   {
                             *       MessageBox.Show("设备" + (PCAN_PARA1.PCANIndex - 0x51) + "接收缓冲区已满,已自动清空");
                             *       rxCANOBJLIST.Clear();
                             *   }
                             *   rxCANOBJLIST.Add(arrCANOBJ[0]);
                             * }
                             * else
                             * {
                             *   ProcessingFrame(ref arrCANOBJ[0]);
                             * }*/
                        }
                        if (stsResult == TPCANStatus.PCAN_ERROR_ILLOPERATION)
                        {
                            break;
                        }
                        //else
                    }
                    else
                    {
                        TPCANMsgFD       CANMsg;
                        TPCANTimestampFD CANTimeStamp;
                        stsResult = PCANBasic.ReadFD(PCAN_PARA1.PCANIndex, out CANMsg, out CANTimeStamp);
                        if (stsResult == TPCANStatus.PCAN_ERROR_ILLOPERATION)
                        {
                            break;
                        }
                        //if (stsResult == TPCANStatus.PCAN_ERROR_OK)
                        if (stsResult != TPCANStatus.PCAN_ERROR_QRCVEMPTY)
                        {
                            arrCANOBJ[rx_index].ID      = CANMsg.ID;
                            arrCANOBJ[rx_index].DataLen = CANMsg.DLC;

                            if (((byte)CANMsg.MSGTYPE & (byte)0x02) == 0x02)//是扩展帧
                            {
                                arrCANOBJ[rx_index].ExternFlag = 1;
                            }
                            else
                            {
                                arrCANOBJ[rx_index].ExternFlag = 0;
                            }

                            if (((byte)CANMsg.MSGTYPE & (byte)0x01) == 0x01)//是请求帧
                            {
                                arrCANOBJ[rx_index].RemoteFlag = 1;
                            }
                            else
                            {
                                arrCANOBJ[rx_index].RemoteFlag = 0;
                            }

                            if (((byte)CANMsg.MSGTYPE & (byte)0x04) == 0x04)//是FD帧
                            {
                                arrCANOBJ[rx_index].FDflag = 1;
                            }
                            else
                            {
                                arrCANOBJ[rx_index].FDflag = 0;
                            }

                            if (((byte)CANMsg.MSGTYPE & (byte)0x08) == 0x08)//是FD-BRS
                            {
                                arrCANOBJ[rx_index].FDflag = 1;
                            }
                            else
                            {
                                arrCANOBJ[rx_index].FDflag = 0;
                            }

                            if (((byte)CANMsg.MSGTYPE & (byte)0x10) == 0x10)//是FD-ESI error status indicator
                            {
                                arrCANOBJ[rx_index].FDEsi = 1;
                            }
                            else
                            {
                                arrCANOBJ[rx_index].FDEsi = 0;
                            }

                            if (((byte)CANMsg.MSGTYPE & (byte)0x40) == 0x40)//是error frame
                            {
                                arrCANOBJ[rx_index].ErrorFrame = 1;
                            }
                            else
                            {
                                arrCANOBJ[rx_index].ErrorFrame = 0;
                            }

                            arrCANOBJ[rx_index].TimeStamp = CANTimeStamp;
                            for (i = 0; i < CANMsg.DLC; i++)//原来用8固定长度
                            {
                                arrCANOBJ[0].Data[i] = CANMsg.DATA[i];
                            }
                            rx_pkg_counts++;
                            rx_index++;
                            if (rx_index > 32768)
                            {
                                rx_index = 32767;
                            }
                            // for (i = 0; i < len; i++)
                            //ProcessingFrame(ref arrCANOBJ[0]);

                            /*if (ProcessingFrame == null)
                             * {
                             *  if (rxCANOBJLIST.Count >= 100000)
                             *  {
                             *      MessageBox.Show("设备" + (PCAN_PARA1.PCANIndex - 0x51) + "接收缓冲区已满,已自动清空");
                             *      rxCANOBJLIST.Clear();
                             *  }
                             *  rxCANOBJLIST.Add(arrCANOBJ[0]);
                             * }
                             * else
                             * {
                             *  ProcessingFrame(ref arrCANOBJ[0]);
                             * }*/
                        }
                        //else
                    }
                } while (!Convert.ToBoolean(stsResult & TPCANStatus.PCAN_ERROR_QRCVEMPTY));
                if (rx_index > 0)
                {
                    for (i = 0; i < rx_index; i++)
                    {
                        ProcessingFrame(ref arrCANOBJ[i]);
                        Thread.Sleep(1);
                    }
                    rx_index = 0;
                }
                Thread.Sleep(2);
            }
        }