【问题标题】:Visual Studio 2015 has problems communicating using VISA LibrariesVisual Studio 2015 在使用 VISA 库进行通信时出现问题
【发布时间】:2015-08-20 14:26:47
【问题描述】:

我在使用 VISA-Com 库与 Keysight (N6700B) 电源进行通信时遇到问题。

我在 Visual Studio 2015 中编译了一些 C# 代码,但它不起作用。但是,如果我在 Visual Studio 2012 中编译相同的代码,那么它可以工作。

基本上我只是在与设备进行简单的通信:

using Ivi.Visa.Interop;
//...
string address = "USB0::2391::2311::MY54002380::0::INSTR";
ResourceManager rm = new ResourceManager();
FormattedIO488 myDmm = (IMessage)rm.Open(address , AccessMode.NO_LOCK, 2000, "");
myDmm.WriteString("*RST"); // reset the device
myDmm.WriteString("*IDN?"); // request the IDN string;
string IDN = myDmm.ReadString(); // This is where it fails, returning: "VI_ERROR_TMO: A timeout occurred"

另外,电源有一个错误状态:“Error -420, Query UNTERMINATED”

该代码不适用于 VS2015,但可以用于 VS2012。 (在 VS2012 中我完全没有错误。)

我已尝试从 KeySight 下载最新的驱动程序,但仍然无法正常工作 (www.keysight.com/find/iosuitedownload)。

有没有人知道为什么它会与 VS2015 中断但与 VS2012 一起使用?

我查找了“Quere Unterminated”,有人说它可能是缺少终止字符“\n”。我尝试将“\n”添加到两个 writeStrings 中,但仍然失败。


编辑:我现在也尝试使用(在不同的地方):

myDmm.IO.TerminationCharacterEnabled = true; // and = false 

myDmm.FlushWrite(); // also tried passing in "true" (default is 'false')

我也尝试添加:

myDmm.IO.TerminationCharacter

到 WriteStrings。

【问题讨论】:

  • 您使用的是哪个 .Net 版本?可能是当您进行解决方案转换时,它还将 .NET Framework 版本更改为最新版本。你应该看看这个项目并手动将版本更改为与 Visa 框架兼容的版本
  • 错误是在 Visual Studio 内部执行代码还是在 Visual Studio 外部运行编译后的可执行文件?
  • 您是否验证了生成的程序集的“位数”是否相同(x86、x64、ANY_CPU)?
  • 你输入 "/n" 时的意思是 "\n" 吗?一个生成控制字符,另一个不生成。
  • 我建议此时,查看程序集中生成的 IL。如果生成的 IL 完全相同,则问题可能出在程序集外部(可能是库引用问题)。如果 IL 不同,可能会为您提供有关如何修改代码以与两个版本的 VS 一起使用的指导。

标签: c# visual-studio-2012 visual-studio-2015 visa


【解决方案1】:

http://download.ni.com/support/softlib//visa/NI-VISA/15.0/Windows/readme.html

Microsoft Visual Studio 支持

下表列出了此版本的 NI-VISA 支持的编程语言和 Microsoft Visual Studio 版本。

早期版本的 NI-VISA 支持其他应用软件和语言版本。有关 Visual Studio 与 VISA 早期版本兼容性的更多信息,请访问 ni.com/info 并输入信息代码 NETlegacydrivers。要查找和下载较早版本的驱动程序,请访问 ni.com/downloads。

NI-VISA 支持的 Visual Studio 版本:

Visual C++ MFC1 -------------- 2008

Framework 3.5 语言(Visual C# 和 Visual Basic .NET)——2008 年

.NET Framework 4.0 语言(Visual C# 和 Visual Basic .NET)-- 2010

.NET Framework 4.5 语言(Visual C# 和 Visual Basic .NET)-- 2012

所以显然驱动程序不适用于 VS2015...(不确定新版本如何不起作用.. 但没关系)

编辑,找到答案

来自 NI-VISTA 的人告诉我只需添加“true”作为第二个参数:

myDmm.WriteString("*RST",true); // reset the device
myDmm.WriteString("*IDN?",true); // request the IDN string;
string IDN = myDmm.ReadString(); // now it works.

我不知道为什么 2012 年不需要“真实”,为什么 2015 年需要它......哦,好吧。

【讨论】:

    【解决方案2】:

    我确认:方法 WriteString()(但不仅如此)需要布尔参数 flushAndEND = true(默认值 = false)才能完成命令。没有它,仪器就无法解析指令。如果您发送多个命令,仪器将无法分离和识别它们。

    我建议您使用 Keysight IO 监视器来嗅探仪器和控制器(PC?)之间的通信。它是 IO Libraries Suite (v17.1) 的实用程序。

    详见附件IFormattedIO488接口定义,属于参考Ivi.Visa.Interop。

    
        using System.Runtime.InteropServices;
    
        namespace Ivi.Visa.Interop
        {
                [...]
          public interface IFormattedIO488
          {
            [DispId(1610678274)]
            bool InstrumentBigEndian { get; set; }
            [DispId(1610678272)]
            IMessage IO { get; set; }
    
            void FlushRead();
            void FlushWrite(bool sendEND = false);
            dynamic ReadIEEEBlock(IEEEBinaryType type, bool seekToBlock = false, bool flushToEND = false);
            dynamic ReadList(IEEEASCIIType type = IEEEASCIIType.ASCIIType_Any, string listSeperator = ",;");
            dynamic ReadNumber(IEEEASCIIType type = IEEEASCIIType.ASCIIType_Any, bool flushToEND = false);
            string ReadString();
            void SetBufferSize(BufferMask mask, int size);
            void WriteIEEEBlock(string Command, object data, bool flushAndEND = false);
            void WriteList(ref object data, IEEEASCIIType type = IEEEASCIIType.ASCIIType_Any, string listSeperator = ",", bool flushAndEND = false);
            void WriteNumber(object data, IEEEASCIIType type = IEEEASCIIType.ASCIIType_Any, bool flushAndEND = false);
            void WriteString(string data, bool flushAndEND = false);
          }
        } 
    

    【讨论】:

      【解决方案3】:

      您是否尝试过 ReadBytes 方法?此方法从设备中读取固定数量的字节。您遇到的错误很可能是因为签证驱动程序尝试读取数据,直到收到您从未明确设置的终止字符。

      尝试将 TerminationCharacter 属性设置为 \n 或 \r(取决于仪器),它应该可以工作。此外,您可能还想将它添加到您发送的命令中,这样仪器就不会再因为这个错误 (-420) 打扰您了。

      【讨论】:

        猜你喜欢
        • 2016-07-18
        • 1970-01-01
        • 1970-01-01
        • 2015-12-13
        • 1970-01-01
        • 2019-01-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多