仪表编程控制COMException错误

1. 错误现象或描述

采用仪表编程一直采用自己的驱动和DLL文件,在Visual Studio 2022版本采用自己的类库文件出现下面错误:

System.Runtime.InteropServices.COMException  HResult=0x80040011  Message=HRESULT = 80040011  Source=<无法计算异常源>  StackTrace:<无法计算异常堆栈跟踪>

2. 原因分析

网上搜索了很多ComException的相关误差,基本的原因就是Window10安全性增加需要对DLL类库文件进行注册。

具体的操作请参考:

模块已加载,但找不到入口点DLLRegisterServer_longHARDEN的博客-CSDN博客

但是,经过上面一番操作还是不行。总是出现DLLRegisterServer找不到入口,所以又对该问题一顿操作。可以参考下面:

How to Fix “DLLRegisterserver Was Not Found” Error on Windows 10

 经过上面所有操作后还是没有解决问题。重新对思路进行了梳理:利用了外部DLL文件——>Windows安全注册——>利用Windows自带的COM类重新创建DLL类库。问题解决。

3. 具体作法

在引用到搜索VISA COM库进行添加,直接using。要注意编译生成时所采用的.net架构,CPU设置必须统一。

 4. 最后测试结果

生成创建后的DLL类库引用测试结果:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MyDrive;

namespace MyDriveTest
{
    internal class Program
    {
        static InstrumentDriver instr = new InstrumentDriver();
        static string visaAddress = "TCPIP0::10.**.**.**::inst0::INSTR";
        static int timeOut = 10000;
        static void Main(string[] args)
        {
            instr.ConnectInstrument(visaAddress, timeOut);
            string idn = instr.GetIDN();

            Console.WriteLine("The instrument ID is '{0}'", idn);
            Console.ReadLine();
        }
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值