示例#1
0
        /// <summary>
        /// 基本功能测试发送数据
        /// </summary>
        /// <param name="chipNum">芯片</param>
        /// <param name="pathNum">通道</param>
        /// <param name="typeName">类型</param>
        public static void BaseTestSendData(int chipNum, string basePath, int sendNum)
        {
            byte[] cmdByte = new byte[10] {
                0xAA, 0, 0, 0, 0, 0, 0, 0, 0, 0xBB
            };
            cmdByte[1] = (byte)4;
            cmdByte[2] = (byte)chipNum;
            cmdByte[4] = (byte)sendNum;
            if (basePath == "通道1")
            {
                cmdByte[3] = (byte)0;
            }
            else if (basePath == "通道2")
            {
                cmdByte[3] = (byte)1;
            }
            else if (basePath == "通道3")
            {
                cmdByte[3] = (byte)2;
            }
            else if (basePath == "通道4")
            {
                cmdByte[3] = (byte)3;
            }

            int error = CGloabal.WriteToCom(CGloabal.g_serialPorForUUT, cmdByte, 10);

            if (error < 0)
            {
                MessageBox.Show("芯片" + chipNum + "" + basePath + "发送失败");
                return;
            }
        }
示例#2
0
        //DMA测试并返回值
        //FIFO正确性测试并返回值
        public static string DMATestAndFIFOTest(string testFlag)
        {
            byte[] cmdByte = new byte[10] {
                0xAA, 0, 0, 0, 0, 0, 0, 0, 0, 0xBB
            };
            string reVal = "";
            int    error;

            if (testFlag == "DMA")
            {
                cmdByte[3] = 1;//代表DMA
            }
            else if (testFlag == "FIFO")
            {
                cmdByte[3] = 2;//代表FIFO
            }
            error = CGloabal.WriteToCom(CGloabal.g_serialPorForUUT, cmdByte, 10);
            if (error < 0)
            {
                MessageBox.Show("命令发送失败");
            }

            Thread.Sleep(1000);

            List <byte> buffer = new List <byte>(4096);
            int         length;

            byte[] ReceiveBytes = new byte[24];

            CGloabal.g_bIsComRecvedDataFlag = true;  //串口是否收到数据
            length = CGloabal.g_serialPorForUUT.BytesToRead;
            byte[] Receivebuf = new byte[24];
            CGloabal.ReadCom(CGloabal.g_serialPorForUUT, Receivebuf, 24);
            //1、缓存数据
            buffer.AddRange(Receivebuf);
            //2、完整性判断
            while (buffer.Count >= 24)
            {
                if (buffer[0] == 0xAA)
                {
                    //得到完整的数据,复制到ReceiveBytes中进行校验
                    buffer.CopyTo(0, ReceiveBytes, 0, 24);
                    buffer.RemoveRange(0, 24);
                }
                else //帧头不正确时,记得清除
                {
                    buffer.RemoveAt(0);
                }
            }

            if (ReceiveBytes[5] == 0)
            {
                return("不正常");
            }
            else
            {
                return("正常");
            }
        }
示例#3
0
        /// <summary>
        /// 寄存器测试读取数据
        /// </summary>
        /// <param name="chipNum">芯片</param>
        /// <param name="pathNum">通道</param>
        /// <param name="typeName">类型</param>
        public static byte[] regReadData(int chipNum, int channel, int addr)
        {
            byte[] cmdByte = new byte[10] {
                0xAA, 0, 0, 0, 0, 0, 0, 0, 0, 0xBB
            };
            cmdByte[1] = (byte)6;
            cmdByte[2] = (byte)chipNum;
            cmdByte[4] = (byte)addr;


            int error = 0;

            error = CGloabal.WriteToCom(CGloabal.g_serialPorForUUT, cmdByte, 10);

            if (error < 0)
            {
                MessageBox.Show("芯片" + chipNum + "" + "读取失败");
            }

            Thread.Sleep(300);

            List <byte> buffer = new List <byte>(4096);
            int         length;

            byte[] ReceiveBytes = new byte[24];

            CGloabal.g_bIsComRecvedDataFlag = true;  //串口是否收到数据
            length = CGloabal.g_serialPorForUUT.BytesToRead;
            byte[] Receivebuf = new byte[24];
            CGloabal.ReadCom(CGloabal.g_serialPorForUUT, Receivebuf, 24);
            //1、缓存数据
            buffer.AddRange(Receivebuf);
            //2、完整性判断
            while (buffer.Count >= 24)
            {
                if (buffer[0] == 0xAA)
                {
                    //得到完整的数据,复制到ReceiveBytes中进行校验
                    buffer.CopyTo(0, ReceiveBytes, 0, 24);
                    buffer.RemoveRange(0, 24);
                    return(ReceiveBytes);
                }
                else //帧头不正确时,记得清除
                {
                    buffer.RemoveAt(0);
                }
            }

            return(ReceiveBytes);
        }
示例#4
0
        /// <summary>
        /// 基本功能测试发送数据
        /// </summary>
        /// <param name="chipNum">芯片</param>
        /// <param name="channel">通道</param>
        /// <param name="typeName">类型</param>
        public static void RegWriteData(int chipNum, int channel, int addr, int sendNum)
        {
            int error = 0;

            Byte[] cmdByte = new Byte[10] {
                0XAA, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0XBB
            };

            cmdByte[1] = 0x08;              //命令字
            cmdByte[4] = (byte)addr;        //address
            cmdByte[5] = (byte)sendNum;     //data
            error      = CGloabal.WriteToCom(CGloabal.g_serialPorForUUT, cmdByte, 10);

            Thread.Sleep(800);
        }
示例#5
0
        /// <summary>
        /// 芯片设置
        /// </summary>
        /// <param name="CHIPMODEL"></param>
        /// <returns></returns>
        public static int ChipSet(ChipModel CHIPMODEL)
        {
            int error = 0;

            Byte[] cmdByte = new Byte[10] {
                0XAA, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0XBB
            };

            cmdByte[2] = (byte)CHIPMODEL.chipSelect;
            cmdByte[3] = (byte)CHIPMODEL.pathSelect;

            //设置DUT波特率
            cmdByte[1] = 0x03;
            cmdByte[4] = ValueReturn(CHIPMODEL.baudRate, "波特率");
            error      = CGloabal.WriteToCom(CGloabal.g_serialPorForUUT, cmdByte, 10);
            Thread.Sleep(100);


            cmdByte[1] = 0x08;
            //发送中断、接收中断、接收缓存中断
            cmdByte[4] = 01;
            cmdByte[5] = 0x00;

            cmdByte[5] += ValueReturn(CHIPMODEL.receiveInterrupt, "接收中断");
            cmdByte[5] += ValueReturn(CHIPMODEL.sendInterrupt, "发送中断");
            cmdByte[5] += ValueReturn(CHIPMODEL.receiveCache, "接收缓存中断");

            error = CGloabal.WriteToCom(CGloabal.g_serialPorForUUT, cmdByte, 10);
            if (error < 0)
            {
                return(-3);
            }
            Thread.Sleep(100);

            cmdByte[4] = 02;
            //FIFO使能,DMA模式,接收FIFO触发器,发送触发器
            cmdByte[5]  = 0x00;
            cmdByte[5] += ValueReturn(CHIPMODEL.FIFOSelect, "FIFO使能");
            cmdByte[5] += ValueReturn(CHIPMODEL.DMAPattern, "DMA模式");
            cmdByte[5] += ValueReturn(CHIPMODEL.receiveFIFO, "接收触发器");
            cmdByte[5] += ValueReturn(CHIPMODEL.sendTarget, "发送触发器");

            error = CGloabal.WriteToCom(CGloabal.g_serialPorForUUT, cmdByte, 10);
            if (error < 0)
            {
                return(-2);
            }

            //设置奇偶校验,停止位,字长
            cmdByte[4]  = 3;
            cmdByte[5]  = 0x00;
            cmdByte[5] += ValueReturn(CHIPMODEL.parityCheck, "奇偶校验");
            cmdByte[5] += ValueReturn(CHIPMODEL.stopBit, "停止位");
            cmdByte[5] += ValueReturn(CHIPMODEL.byteLength, "字长");
            error       = CGloabal.WriteToCom(CGloabal.g_serialPorForUUT, cmdByte, 10);
            if (error < 0)
            {
                return(-1);
            }
            Thread.Sleep(100);



            Thread.Sleep(100);



            return(error);
        }
示例#6
0
        /// <summary>
        /// 基本功能测试读取数据
        /// </summary>
        /// <param name="chipNum">芯片</param>
        /// <param name="pathNum">通道</param>
        /// <param name="typeName">类型</param>
        public static byte[] BaseTestReadData(int chipNum, string basePath, string typeName)
        {
            byte[] cmdByte = new byte[10] {
                0xAA, 0, 0, 0, 0, 0, 0, 0, 0, 0xBB
            };
            cmdByte[1] = (byte)6;
            cmdByte[2] = (byte)chipNum;

            if (basePath == "通道1")
            {
                cmdByte[3] = (byte)0;
            }
            else if (basePath == "通道2")
            {
                cmdByte[3] = (byte)1;
            }
            else if (basePath == "通道3")
            {
                cmdByte[3] = (byte)2;
            }
            else if (basePath == "通道4")
            {
                cmdByte[3] = (byte)3;
            }

            int error = 0;

            switch (typeName)
            {
            case "BASE":
                cmdByte[1] = (byte)5;
                error      = CGloabal.WriteToCom(CGloabal.g_serialPorForUUT, cmdByte, 10);
                break;

            case "LSR":
                cmdByte[4] = (byte)5;
                error      = CGloabal.WriteToCom(CGloabal.g_serialPorForUUT, cmdByte, 10);
                break;

            case "IIR":
                cmdByte[4] = (byte)2;
                error      = CGloabal.WriteToCom(CGloabal.g_serialPorForUUT, cmdByte, 10);
                break;

            case "ARM":
                cmdByte[1] = (byte)7;
                error      = CGloabal.WriteToCom(CGloabal.g_serialPorForUUT, cmdByte, 10);
                break;
            }
            if (error < 0)
            {
                MessageBox.Show("芯片" + chipNum + "" + basePath + "读取失败");
            }

            Thread.Sleep(500);

            List <byte> buffer = new List <byte>(4096);
            int         length;

            byte[] ReceiveBytes = new byte[24];

            CGloabal.g_bIsComRecvedDataFlag = true;  //串口是否收到数据
            length = CGloabal.g_serialPorForUUT.BytesToRead;
            byte[] Receivebuf = new byte[24];
            CGloabal.ReadCom(CGloabal.g_serialPorForUUT, Receivebuf, 24);
            //1、缓存数据
            buffer.AddRange(Receivebuf);
            //2、完整性判断
            while (buffer.Count >= 24)
            {
                if (buffer[0] == 0xAA)
                {
                    //得到完整的数据,复制到ReceiveBytes中进行校验
                    buffer.CopyTo(0, ReceiveBytes, 0, 24);
                    buffer.RemoveRange(0, 24);
                    return(ReceiveBytes);
                }
                else //帧头不正确时,记得清除
                {
                    buffer.RemoveAt(0);
                }
            }

            return(ReceiveBytes);
        }