Example #1
0
        /// <summary>
        /// 保存二进制形式s32p文件
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="portCount"></param>
        public void StorePure(string filename, int portCount = 32)
        {
            int    pointCount = 0;
            HecSnp hecsnp     = GetData(ref pointCount, portCount);

            DataConverter.SavePure(filename, hecsnp);
        }
Example #2
0
        /// <summary>
        /// 保存SNP文件
        /// </summary>
        /// <param name="filename">snp文件路径</param>
        /// <param name="portCount">端口数</param>
        public void StoreS2P(string filename, int portCount)
        {
            int    pointCount = 0;
            HecSnp hecsnp     = GetData(ref pointCount, portCount);

            DataConverter.SaveSnp(filename, hecsnp, portCount);
        }
Example #3
0
        public static HecSnp GetSnp(string hecFilePath)
        {
            string extensionName = (new FileInfo(hecFilePath)).Extension.ToUpper();

            if (extensionName != ".HEC")
            {
                throw new Exception("only support HEC file!");
            }
            byte[] allBytes    = File.ReadAllBytes(hecFilePath);
            int    headLength  = BitConverter.ToInt32(allBytes, 0);
            int    idnLength   = BitConverter.ToInt32(allBytes, 4);
            int    dateLength  = BitConverter.ToInt32(allBytes, 8);
            int    freLength   = BitConverter.ToInt32(allBytes, 12);
            int    valueLength = BitConverter.ToInt32(allBytes, 16);
            string _head       = System.Text.Encoding.Default.GetString(allBytes.Skip(20).Take(headLength).ToArray());

            if (_head != _headers)
            {
                throw new Exception("invalid HEC file!");
            }

            HecSnp ret = new HecSnp();

            ret.Idn   = Encoding.Default.GetString(allBytes.Skip(20 + headLength).Take(idnLength).ToArray());
            ret.Date  = Encoding.Default.GetString(allBytes.Skip(20 + headLength + idnLength).Take(dateLength).ToArray());
            ret.Fre   = allBytes.Skip(20 + headLength + idnLength + dateLength).Take(freLength).ToArray();
            ret.Value = allBytes.Skip(20 + headLength + idnLength + dateLength + freLength).Take(valueLength).ToArray();
            return(ret);
        }
Example #4
0
 /// <summary>
 /// HEC二进制格式保存
 /// 0-3 文件头长度,字符串
 /// 4-7 仪器信息长度,字符串
 /// 8-11 测试日期字符串长度,字符串
 /// 12-15 频率长度,double[]数组
 /// 16-19 实部虚部长度,float[]数组
 /// 20-结尾 按上面五部分长度划分
 /// </summary>
 /// <param name="saveFilePath"></param>
 /// <param name="hecSnp"></param>
 public static void SavePure(string saveFilePath, HecSnp hecSnp)
 {
     byte[] idn      = System.Text.Encoding.Default.GetBytes(hecSnp.Idn);
     byte[] date     = System.Text.Encoding.Default.GetBytes(hecSnp.Date);
     byte[] allBytes = JoinBytes(new[] { headBytes, idn, date, hecSnp.Fre, hecSnp.Value });
     using (FileStream writer = new FileStream(saveFilePath, FileMode.Create, FileAccess.ReadWrite))
     {
         using (BinaryWriter binWtr = new BinaryWriter(writer))
         {
             binWtr.Write(allBytes);
         }
     }
 }
Example #5
0
        private HecSnp GetData(ref int pointCount, int portCount)
        {
            //int pointCount = 0;
            HecSnp ret = new HecSnp();

            float[] value = SweepStore(ref pointCount, portCount);

            var tempBefore_Getfre = BeforeGetfre;

            if (tempBefore_Getfre != null)
            {
                tempBefore_Getfre();
            }
            gPNA.WriteString("FORM REAL,64", true);
            gPNA.WriteString("CALC:MEAS:X?", true);
            double[] fre = (double[])gPNA.ReadIEEEBlock(IEEEBinaryType.BinaryType_R8, false, true);
            gPNA.WriteString("FORM ASCii,0", true);
            var tempOn_Getfre = OnFreGet;

            if (tempOn_Getfre != null)
            {
                tempOn_Getfre(fre);
            }


            byte[] valueBytes = new byte[value.Length * sizeof(float)];
            Buffer.BlockCopy(value, 0, valueBytes, 0, valueBytes.Length);

            byte[] freBytes = new byte[fre.Length * sizeof(double)];
            Buffer.BlockCopy(fre, 0, freBytes, 0, freBytes.Length);

            ret.Idn   = IDNinfo;
            ret.Date  = DateTime.Now.ToString("F");
            ret.Fre   = freBytes;
            ret.Value = valueBytes;
            return(ret);
        }
Example #6
0
        public static void SaveSnp(string saveFilePath, HecSnp hecSnp, int portCount)
        {
            using (StreamWriter writer = File.CreateText(saveFilePath))
            {
                writer.WriteLine("!" + hecSnp.Idn);
                writer.WriteLine("!" + hecSnp.Date);
                writer.Write("!S" + portCount.ToString() + "P File: Measurements: <");
                for (int i = 1; i <= portCount; i++)
                {
                    writer.Write(ToSParameter(1, i));
                    if (i != portCount)
                    {
                        writer.Write(",");
                    }
                }
                writer.WriteLine(">,");
                for (int j = 2; j <= portCount; j++)
                {
                    writer.Write("!<");
                    for (int m = 1; m <= portCount; m++)
                    {
                        writer.Write(ToSParameter(j, m));
                        if (m != portCount)
                        {
                            writer.Write(",");
                        }
                    }
                    writer.Write(">");
                    if (j != portCount)
                    {
                        writer.WriteLine(",");
                    }
                    else
                    {
                        writer.WriteLine(":");
                    }
                }
                writer.WriteLine("# Hz S  RI   R 50");

                double[] freDoubles = new Double[hecSnp.Fre.Length / sizeof(double)];
                Buffer.BlockCopy(hecSnp.Fre, 0, freDoubles, 0, hecSnp.Fre.Length);

                float[] dbFloats = new float[hecSnp.Value.Length / sizeof(float)];
                Buffer.BlockCopy(hecSnp.Value, 0, dbFloats, 0, hecSnp.Value.Length);

                DataWrapper wrapper = new DataWrapper
                {
                    allData    = dbFloats,
                    pointCount = freDoubles.Length,
                    portCount  = portCount
                };
                for (int k = 0; k < freDoubles.Length; k++)
                {
                    writer.Write(freDoubles[k].ToString("G17") + " ");
                    for (int n = 1; n <= portCount; n++)
                    {
                        for (int num8 = 1; num8 <= portCount; num8++)
                        {
                            writer.Write(wrapper.Real(n, num8, k));
                            writer.Write(" ");
                            writer.Write(wrapper.Imag(n, num8, k));
                            writer.Write(" ");
                            if (((num8 % 4) == 0) && (num8 != portCount))
                            {
                                writer.WriteLine();
                            }
                        }
                        if (n != portCount)
                        {
                            writer.WriteLine();
                        }
                    }
                    writer.WriteLine();
                }
            }
        }