u010384796
Rockyboys
采纳率0%
2016-07-05 01:45

求教安捷伦数据采集, c#采集数据

图片说明
求教红色部分的方法,现在只能采集到第一个窗体的 频率对应的波峰最大值,具体代码为 public static List getSWR(int channels, int part)
{
List rs = new List();
double maxPoint = 0, minPoint = 0;

        FormattedIO488 ioDmm = new FormattedIO488Class();
        ResourceManager grm = new ResourceManager();

        ioDmm.IO = (IMessage)grm.Open(visaAddress, AccessMode.NO_LOCK, 0, "");

        //set transfer mode to binary
        ioDmm.WriteString("*CLS");
        ioDmm.WriteString(":FORM:DATA REAL32", true);
        ioDmm.WriteString(":FORM:BORD SWAP", true);
        ioDmm.WriteString(":CALC" + Convert.ToString(channels) + ":PAR" + Convert.ToString(part) + ":SEL", true);
        //set timeout to 10 seconds
        ioDmm.IO.Timeout = 10000;
        //=== Read the trace data into the buffer.
        ioDmm.WriteString(":CALC" + Convert.ToString(channels) + ":DATA:FDAT?", true);



        byte[] pound = ioDmm.IO.Read(1);
        byte[] count = ioDmm.IO.Read(1);

        int numToRead = int.Parse(((char)count[0]).ToString());
        byte[] rawcount = ioDmm.IO.Read(numToRead);
        List<char> al = new List<char>(rawcount.Length);
        foreach (byte b in rawcount)
            al.Add((char)b);
        char[] chByteCount = (char[])al.ToArray();
        int numBytes = int.Parse(new string(chByteCount));
        byte[] rawTraceData = ioDmm.IO.Read(numBytes);
        byte[] trailingNL = ioDmm.IO.Read(1);
        int numPoints = numBytes / 4;
        float[] tracedata = new float[numPoints];
        int indx = 0;
        if (numPoints > 0)
        {
            maxPoint = BitConverter.ToSingle(rawTraceData, 0);
            minPoint = BitConverter.ToSingle(rawTraceData, 0);
        }
        for (int i = 0; i < numPoints; ++i)
        {
            tracedata[i] = BitConverter.ToSingle(rawTraceData, indx);
            indx += 4;


            //赋值最大值和最小值判断
            if (tracedata[i] == 0)
                continue;
            if (tracedata[i] > maxPoint)
                maxPoint = tracedata[i];
            if (tracedata[i] < minPoint)
                minPoint = tracedata[i];

        }
        ioDmm.IO.Close();

        rs.Add(Math.Round(minPoint, 3));
        rs.Add(Math.Round(maxPoint, 3));
        return rs;
    }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • wxh19880603 wxh19880603 6月前

    大神,可否提供以下demo

    点赞 评论 复制链接分享

相关推荐