1、前言 此次需要用到工具操作示波器動態配置和檢驗數據,下麵為此次開發的一些總結記錄。按理說這裡應該用泰克(tektronix)提供的示波器(oscilloscope)驅動和API,但是我沒有找到泰克提供的.NET版本的API,我又不是特別熟悉C封裝到C#的開發,所以乾脆使用了NI-VISA .NE ...
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-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<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測試用例
//設置垂直刻度為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
TEKVISA Connectivity Software - V4.2.0