Example #1
0
        public bool RxBuffAdd(byte[] rx, int len)
        {
            int          i;
            bool         ret   = true;
            COMM_FRAME_T frame = new COMM_FRAME_T();

            if (len + rxCnt >= RX_BUFF_SIZE)
            {
                return(false);
            }

            //添加新收到的数据到末端
            for (i = 0; i < len; i++)
            {
                buffRX[i + rxCnt] = rx[i];
            }
            rxCnt += len;


            while (sBufGetFrame(ref frame))
            {
                queueRX.Enqueue(frame);
            }
            return(ret);
        }
Example #2
0
        void RecDeal(COMM_FRAME_T frm)
        {
            ANAL_T anal = new ANAL_T();

            anal = (ANAL_T)BytesToStruct(frm.data, Marshal.SizeOf(typeof(ANAL_T)), typeof(ANAL_T));
            REC_ITEM rec = new REC_ITEM();

            rec.img = anal.img;

            int i;

            for (i = 0; i < REC.PIX_NUM; i++)
            {
                if (rec.img[REC.LINE_SHADE1].pix[i] == 0)
                {
                    rec.img[REC.LINE_SHADE1].pix[i] = 255;
                }
                else
                {
                    rec.img[REC.LINE_SHADE1].pix[i] = 0;
                }
                if (rec.img[REC.LINE_SHADE2].pix[i] == 0)
                {
                    rec.img[REC.LINE_SHADE2].pix[i] = 255;
                }
                else
                {
                    rec.img[REC.LINE_SHADE2].pix[i] = 0;
                }
            }
            ShowRec(rec);
        }
Example #3
0
        public bool GetRxFrame(ref COMM_FRAME_T frame)
        {
            bool ret = false;

            if (queueRX.Count >= 1)
            {
                frame = queueRX.Dequeue();
                ret   = true;
            }
            return(ret);
        }
Example #4
0
        //解析串口数据帧,更新显示
        public void CfgFreameDeal(COMM_FRAME_T frame)
        {
            CFG_T cfg = new CFG_T();

            cfg = (CFG_T)BytesToStruct(frame.data, Marshal.SizeOf(typeof(CFG_T)), typeof(CFG_T));

            if (CfgCheck(ref cfg))
            {
                hParent.devCfg = cfg;
                UpdateShow(cfg);
            }
        }
Example #5
0
        public REC_ITEM RecFrameDeal(COMM_FRAME_T frm)
        {
            curRec = (REC_ITEM)BytesToStruct(frm.data, Marshal.SizeOf(typeof(REC_ITEM)), typeof(REC_ITEM));

            //IntPtr buff = (IntPtr)(new byte[Marshal.SizeOf(typeof(REC_ITEM))]);

            //check record data
            //curRec.valid = true;
            //if dataerror set curRec.valid to false

            return(curRec);
        }
Example #6
0
        public void SensorFrameDeal(COMM_FRAME_T frame)
        {
            UInt16[] line = new UInt16[REC.PIX_NUM];

            int i;

            //这里怎样通过内存拷贝实现以下功能??
            for (i = 0; i < REC.PIX_NUM; i++)
            {
                line[i]  = (UInt16)frame.data[2 * i];
                line[i] += (UInt16)((UInt16)frame.data[2 * i + 1] * (UInt16)256);
            }

            Graphics grfx      = pBoxSen.CreateGraphics();
            int      picWidth  = pBoxSen.Size.Width;
            int      picHeight = pBoxSen.Size.Height;

            const int SENSOR_RANGE = 1024;          //传感器输出最大值

            int X_SCALE = picWidth / REC.PIX_NUM;   // 3;
            int Y_SCALE = SENSOR_RANGE / picHeight; // 4;

            Pen pen = new Pen(Color.Blue, 1);

            Point[] pts = new Point[REC.PIX_NUM + 1];
            pts[0] = new Point(0, 0);
            for (i = 0; i < REC.PIX_NUM; i++)
            {
                pts[i + 1].X = (i + 1) * X_SCALE;
                pts[i + 1].Y = picHeight - line[i] / Y_SCALE;
            }
            grfx.Clear(Color.White);
            grfx.DrawLines(pen, pts);

            grfx.Dispose();


            //byte[] line = new byte[sizeof(UInt16 )* REC.PIX_NUM];
            ////line = (UInt16[])BytesToStruct(frame.data, sizeof(UInt16) * REC.PIX_NUM, typeof(UInt16 []));
            //Copy(frame.data, 0, line, sizeof(UInt16) * REC.PIX_NUM;
        }
Example #7
0
        /*********************************************************************************************************
         *      Function: Identify the first frame from buffer, copy the frame to _buf[] and delete the frame from _sBuf[]
         *      Return: If find frame, return the length of the frame, else return 0.
         */

        private bool sBufGetFrame(ref COMM_FRAME_T frame)
        {
            bool ret = false;
            int  i;
            int  start, end;
            int  len = 0;
            int  lng = 0;       //LNG in frame
            int  frmLen;

            //在buff中查找帧头
            for (i = 0; i < rxCnt; i++)
            {
                if (FRM_HEADER == buffRX[i])
                {
                    break;
                }
            }

            //删除帧头前的数据
            start = i;

            //trim char before header
            if (start != 0)
            {
                for (i = 0; i < rxCnt - start; i++)
                {
                    buffRX[i] = buffRX[i + start];
                }
            }
            rxCnt -= start;

            //Get LNG
            if (rxCnt >= DEF_FRM_LEN)
            {
                //lng = frame.len;// lng = *(u16*)(_sBuf[port] + 1);//lng = _sBuf[port][1] * 256 + _sBuf[port][2];
                lng = (int)buffRX[2] + (int)buffRX[3] * 256;
                if ((FRM_LEN_MAX < lng) || (lng == 0))  //如果接收到的长度信息不正确,删除缓冲区第一字节
                {
                    rxCnt--;
                    for (i = 0; i < rxCnt; i++)
                    {
                        buffRX[i] = buffRX[i + 1];
                    }
                    lng = 0;
                }
            }
            ////if lng err, delete frame head, search frame again
            //if (lng > FRM_LEN_MAX)
            //{
            //    for (i = 0; i < rxCnt - HEADER_LEN; i++)
            //        _sBuf[port][i] = _sBuf[port][i+HEADER_LEN];
            //    _sCnt[port] -= HEADER_LEN;
            //}
            if (lng != 0)
            {
                frmLen = lng;                                                                     //frmLen = lng + HEADER_LEN + TAIL_LEN;
                if (rxCnt >= frmLen)                                                              //接收数据结束
                {
                    if ((FRM_TAIL == buffRX[frmLen - 1]) && (DEF_CHECKSUM == buffRX[frmLen - 2])) //frame tail OK Checksum OK
                    {
                        end = frmLen;
                        byte[] buf = new byte[FRM_LEN_MAX];
                        for (i = 0; i < end; i++)
                        {
                            buf[i] = buffRX[i];
                        }
                        len = frmLen;
                        for (i = end; i < rxCnt; i++)
                        {
                            buffRX[i - end] = buffRX[i];
                        }
                        rxCnt      = rxCnt - end;
                        frame.data = new byte[frmLen - DEF_FRM_LEN];


                        frame = (COMM_FRAME_T)BytesToStruct(buf, frmLen, typeof(COMM_FRAME_T));
                        ret   = true;
                    }
                    else                //if frame tail err, delete frame head, search frame again
                    {
                        rxCnt--;
                        for (i = 0; i < rxCnt; i++)
                        {
                            buffRX[i] = buffRX[i + 1];
                        }
                    }
                }
            }

            return(ret);
        }