//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("正常"); } }
/// <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); }
/// <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); }