예제 #1
0
        public void checkMsg()
        {
            while (bufLength >= 11)
            {
                if (bufLength < 11)//buf中的数据小于11.等待下一帧数据
                {
                    return;
                }
                int headLocation = findtheHead(msgBuf);
                if (headLocation != -1)                //找到数据头
                {
                    if (bufLength - headLocation < 11) //找到头,单数数据不完整。将buf中的数据全部放到buf的头中
                    {
                        bufMove(headLocation);
                        return;
                    }
                    else
                    {
                        byte[] msg = getOneMsg(headLocation);
                        HY_crc crc = new HY_crc();
                        if (crc.cmdCkeck(msg))
                        {
                            bufMove(headLocation + 11);
                            //printMsg("[OKMsg]", msg);
                            //recv_count++;


                            addMsgToQueue(msg);
                            Console.WriteLine("port = " + port);
                            if (port == 5010)         //hzb
                            {
                                sendDataAfter20(msg); //收到20后发送数据
                            }
                            else if (port == 5009)    //ccl
                            {
                                sendDataAfter0C(msg);
                            }
                            //recv_count++;
                        }
                        else
                        {
                            bufMove(headLocation + 2);
                        }
                    }
                }
                else
                {
                    bufMove(headLocation + bufLength);
                }
            }
            return;
        }
예제 #2
0
        public void checkMsg()
        {
            while (bufLength >= 11)
            {
                if (bufLength < 11)//buf中的数据小于11.等待下一帧数据
                {
                    return;
                }
                int headLocation = findtheHead(msgBuf);
                if (headLocation != -1)                //找到数据头
                {
                    if (bufLength - headLocation < 11) //找到头,单数数据不完整。将buf中的数据全部放到buf的头中
                    {
                        bufMove(headLocation);
                        return;
                    }
                    else
                    {
                        byte[] msg = getOneMsg(headLocation);
                        HY_crc crc = new HY_crc();
                        if (crc.cmdCkeck(msg))
                        {
                            bufMove(headLocation + 11);
                            printMsg("[OKMsg]", msg);
                            //printMsg(msg);
                            if (serialPort.PortName == "COM5")
                            {
                                sendDataAfter20(msg);//收到20后发送数据
                            }
                            else if (serialPort.PortName == "COM4")
                            {
                                sendDataAfter0C(msg);
                            }
                            //recv_count++;


                            addMsgToQueue(msg);
                        }
                        else
                        {
                            bufMove(headLocation + 2);
                        }
                    }
                }
                else
                {
                    bufMove(headLocation + bufLength);
                }
            }
            return;
        }