2020-06-23

[经验栈]C#与泰克示波器(Tektronix oscilloscope)MSO64通信操作

1、前言

此次需要用到工具操作示波器动态配置和检验数据,下面为此次开发的一些总结记录。按理说这里应该用泰克(tektronix)提供的示波器(oscilloscope)驱动和API,但是我没有找到泰克提供的.NET版本的API,我又不是特别熟悉C封装到C#的开发,所以干脆使用了NI-VISA .NET,可能是没有使用到特殊驱动部分,使用并没有出现异常。

2、安装环境

1、NI-VISA

3、C#代码

using System;using System.Collections.Generic;using Ivi.Visa;using NationalInstruments.Visa;namespace VisaInstruments{ public class NiVisaInstrumentsAPIs {  private MessageBasedSession mbSession;  private IVisaAsyncResult asyncHandle = null;  public void FindResources(string filter)  {   using (var rm = new ResourceManager())   {    try    {     IEnumerable<string> resources = rm.Find(filter);     foreach (string s in resources)     {      //可以根据ParseResult查询出硬件类型,如Custom,Gpib,Serial,Usb等      //ParseResult parseResult = rm.Parse(s);      //HardwareInterfaceType hardwareType = parseResult.InterfaceType;     }    }    catch (Exception ex)    {     //处理错误    }   }  }  public bool OpenInstrument(string address)  {   try   {    using (var rmSession = new ResourceManager())    {     mbSession = (MessageBasedSession)rmSession.Open(address);     //mbSession.SynchronizeCallbacks = true;使用异步方法需设SynchronizeCallbacks为true     return true;    }   }   catch (Exception exp)   {    return false;   }  }  public void Write(string s)  {   mbSession.RawIO.Write(ReplaceCommonEscapeSequences(s));  }   public string Read()  {   return InsertCommonEscapeSequences(mbSession.RawIO.ReadString());  }   public void WriteAsync(string s)  {   try   {    string textToWrite = ReplaceCommonEscapeSequences(s);    asyncHandle = mbSession.RawIO.BeginWrite(     textToWrite,     new VisaAsyncCallback(OnWriteComplete),     (object)textToWrite.Length);   }   catch (Exception exp)   {       }  }   private void OnWriteComplete(IVisaAsyncResult result)  {   try   {    mbSession.RawIO.EndWrite(result);    // "Success";   }   catch (Exception exp)   {       }  }   public void ReadAsync()  {   try   {    asyncHandle = mbSession.RawIO.BeginRead(     1024,     new VisaAsyncCallback(OnReadComplete),     null);   }   catch (Exception exp)   {       }  }  private void OnReadComplete(IVisaAsyncResult result)  {   try   {    string responseString = mbSession.RawIO.EndReadString(result);    string info = InsertCommonEscapeSequences(responseString);   }   catch (Exception exp)   {       }  }   public void AbortRW()  {   try   {    mbSession.RawIO.AbortAsyncOperation(asyncHandle);   }   catch (Exception exp)   {       }  }   private string ReplaceCommonEscapeSequences(string s)  {   return (s != null) ? s.Replace("\\n", "\n").Replace("\\r", "\r") : s;  }   private string InsertCommonEscapeSequences(string s)  {   return (s != null) ? s.Replace("\n", "\\n").Replace("\r", "\\r") : s;  }  }}

4、实体按钮对应指令

重新设置参数 --- *RST前面板Autoset按钮 ---- AUTOSet EXECute前面板通道1,2,3,4按钮 --- DISplay:GLObal:CH1:STATE on ACQUIRE:STOPAFTER RUNSTOP前面板Single/Seq按钮 --- ACQUIRE:STOPAFTER SEQuence前面板放大镜按钮 --- DISplay:WAVEView1:ZOOM:ZOOM1:STATe ON前面板Default setup按钮 --- FACtory需要先执行此条命令解锁命令操作旋钮 HORIZONTAL:DELAY:MODE ON前面板HORizontal区域position旋钮 -- HORizontal:DELay:TIME 0.3前面板HORizontal区域scale旋钮 HORIZONTAL:MODE:SCALE 0.5e-3HORIZONTAL:MODE:SCALE?前面板vertical区域scale旋钮 CH1:SCAle 100E-2前面板vertical区域position旋钮 CH2:POSition -2.0前面板touch off按钮 --- TOUCHSCReen:STATe OFF前面板trigger区域force按钮 --- TRIGGER FORCE前面板trigger区域mode按钮 --- TRIGger:A:MODe {AUTO|NORMal}前面板A,B旋钮 --- TRIGger:{A|B|B:RESET}

5、简单测量参数指令

//设定读取通道和参数MEASUREMENT:MEAS1:TYPE AMPLITUDEMEASUREMENT:MEAS1:SOURCE CH1//读取信息MEASUREMENT:MEAS1:RESUlts:CURRentacq:MEAN?//删除测试信息MEASUREMENT:DELETE "MEAS1"//截屏SAVE:IMAGE "C:/Dut12–tests.png"//可测参数列表MEASUrement:MEAS<x>:TYPe{ACCOMMONMODE|ACRMS|AMPlITUDE|AREA|BASE|BITAMPLITUDE|BITHIGH|BITLOW|BURSTWIDTH|COMMONMODE|DATARATE|DCD|DDJ|DDRAOS|DDRAOSPERTCK|DDRAOSPERUI|DDRAUS|DDRAUSPERTCK|DDRAUSPERUI|DDRHOLDDIFF|DDRSETUPDIFF|DDRTCHABS|DDRTCHAVERAGE|DDRTCKAVERAGE|DDRTCLABS|DDRTCLAVERAGE|DDRTERRMN|DDRTERRN|DDRTJITCC|DDRTJITDUTY|DDRTJITPER|DDRTPST|DDRTRPRE|DDRTWPRE|DDRVIXAC|DDRTDQSCK|DELAY|DJ|DJDIRAC|DPMOVERSHOOT|DPMUNDERSHOOT|DPMRIPPLE|DPMTURNOFFTIME|DPMTURNONTIME|EYEHIGH|EYELOW|FALLSLEWRATE|FAHIGH|HEIGHT|HEIGHTBER|HIGHTIME|HOLD|JITTERSUMMARY|J2|J9|LOW|LOWTIME|MAXIMUM|MEAN|MINIMUM|NDUtY|NPERIOD|NPJ|NOVERSHOOT|NWIDTH|PDUTTY|PERIOD|PHASE|PHASENOISE|PJ|PK2Pk|POVERSHOOT|PWIDTH|QFACTOR|RISESLEWRATE|RISETIME|RJ|RJDIRAC|RMS|SRJ|SSCFREQDEV|SSCMODRATE|SETUP|SKEW|TIE|TIMEOUTSIDELEVEL|TJBER|TNTRATIO|TOP|UNITINTERVAL|VDIFFXOVR|WIDTH|WIDTHBER|}

6、简单的GPIO测试用例

//设置垂直刻度为300mvCH1:SCAle 300E-3 //位置为-3divCH1:POSition -3.0 //耦合为DCCH1:COUPLING DC //设置水平刻度为20msHORIZONTAL:MODE:SCALE 20e-3//打开采集ACQUIRE:STATE ON//测量最大电压MEASUREMENT:MEAS1:TYPE MAXIMUMMEASUREMENT:MEAS1:SOURCE CH1//测量最小电压MEASUREMENT:MEAS2:TYPE MINIMUMMEASUREMENT:MEAS2:SOURCE CH1//测量高值MEASUREMENT:MEAS3:TYPE TOPMEASUREMENT:MEAS3:SOURCE CH1//测量低值MEASUREMENT:MEAS4:TYPE BASEMEASUREMENT:MEAS4:SOURCE CH1//停止采集ACQUIRE:STATE OFF//设置标签CH1:LABEL:NAME "GPIO1HIGH"//截屏SAVE:IMAGE "G:/GPIO1HIGH.png"

参考资料

4, 5, 6 Series MSO (MSO44, MSO46, MSO54, MSO56, MSO58, MSO58LP, MSO64, LPD64) Programmer Manual

TEKVISA Connectivity Software - V4.2.0

[经验栈]C#与泰克示波器(Tektronix oscilloscope)MSO64通信操作

No comments:

Post a Comment