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 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-3
HORIZONTAL: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 AMPLITUDE
MEASUREMENT:MEAS1:SOURCE CH1
//读取信息
MEASUREMENT:MEAS1:RESUlts:CURRentacq:MEAN?
//删除测试信息
MEASUREMENT:DELETE "MEAS1"
//截屏
SAVE:IMAGE "C:/Dut12–tests.png"
//可测参数列表
MEASUrement:MEAS: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测试用例
//设置垂直刻度为300mv
CH1:SCAle 300E-3
//位置为-3div
CH1:POSition -3.0
//耦合为DC
CH1:COUPLING DC
//设置水平刻度为20ms
HORIZONTAL:MODE:SCALE 20e-3
//打开采集
ACQUIRE:STATE ON
//测量最大电压
MEASUREMENT:MEAS1:TYPE MAXIMUM
MEASUREMENT:MEAS1:SOURCE CH1
//测量最小电压
MEASUREMENT:MEAS2:TYPE MINIMUM
MEASUREMENT:MEAS2:SOURCE CH1
//测量高值
MEASUREMENT:MEAS3:TYPE TOP
MEASUREMENT:MEAS3:SOURCE CH1
//测量低值
MEASUREMENT:MEAS4:TYPE BASE
MEASUREMENT: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