コード例 #1
0
        public void RXThread()
        {
            XLClass.XLcanRxEvent receivedEvent = new XLClass.XLcanRxEvent();
            XLDefine.XL_Status   xlStatus      = XLDefine.XL_Status.XL_SUCCESS;
            XLDefine.WaitResults waitResult    = new XLDefine.WaitResults();

            while (true)
            {
                waitResult = (XLDefine.WaitResults)WaitForSingleObject(eventHandle, 1000);

                // If event occurred...
                if (waitResult != XLDefine.WaitResults.WAIT_TIMEOUT)
                {
                    // ...init xlStatus first
                    xlStatus = XLDefine.XL_Status.XL_SUCCESS;

                    // afterwards: while hw queue is not empty...
                    while (xlStatus != XLDefine.XL_Status.XL_ERR_QUEUE_IS_EMPTY)
                    {
                        // ...block RX thread to generate RX-Queue overflows
                        while (blockRxThread)
                        {
                            Thread.Sleep(1000);
                        }

                        // ...receive data from hardware.
                        xlStatus = CANDriver.XL_CanReceive(portHandle, ref receivedEvent);

                        //  If receiving succeed....
                        if (xlStatus == XLDefine.XL_Status.XL_SUCCESS)
                        {
                            rawRxString = CANDriver.XL_CanGetEventString(receivedEvent);
                        }
                    }
                }
                // No event occurred
            }
        }