C#中使用visa网口与LCR通信
1.在Keysight官网上下载IO Libraries suite并安装,将
C:\Program Files\IVI Foundation\VISA\Win64\ktvisa\include\visa32.cs
C:\Program Files\IVI Foundation\VISA\Win64\agvisa\agbin\visa32.dll
拷贝到自己工程中,此dll为非托管,属性设置资源始终复制。
2.初始化仪表
var viError = visa32.viOpenDefaultRM(out var viDefultRM); if (viError != visa32.VI_SUCCESS) { return false; } string resourceName = "TCPIP0::192.168.1.1::5025::SOCKET"; viError = visa32.viOpen(viDefultRM, resourceName, visa32.VI_NO_LOCK, visa32.VI_TMO_IMMEDIATE, out var session); if (viError == visa32.VI_SUCCESS) { isConnected = true; }
3.读取数据,读出2个测量值,注意格式:"%,2f"
float[] fValue = new float[2]; viError = visa32.viPrintf(_session, "FETCh?\n"); viError = visa32.viScanf(_session, "%,2f", fValue);
这时执行到visa32.viScanf(_session, "%,2f", fValue);
出错代号:VI_ERROR_TMO,-1073807339
出错原因:在使用前要设置终结符,及超时特性
切记,切记,切记
viError = visa32.viSetAttribute(session, visa32.VI_ATTR_TMO_VALUE, 2000); viError = visa32.viSetAttribute(session, visa32.VI_ATTR_TERMCHAR_EN, visa32.VI_TRUE); viError = visa32.viSetAttribute(session, visa32.VI_ATTR_TERMCHAR, 0x0A);
4.当第二执行第3项获取数据时,报错代码:VI_ERROR_INV_FMT,-1073807297
没搞清楚问题在哪里,换个方式读数据。
string rV; viError = visa32.viRead(_session, out rV, 64); string[] sValues = rV.Split(','); fValue[0] = float.Parse(sValues[0]); fValue[1] = float.Parse(sValues[1]); if (viError < visa32.VI_SUCCESS) { return new float[2]; }
标签:session,KEYSIGHT,VI,float,viError,visa,visa32,LCR,fValue From: https://www.cnblogs.com/duju/p/17933566.html