创建以太网/IP 类实例时遇到问题 -Powershell

问题描述 投票:0回答:1

它一直告诉我程序集未加载(即使我已将它们设置在顶部)

    # Load the EEIP.dll
    Add-Type -Path C:\myDlls\EIP\EEIP.dll
    Add-Type Sres.Net.EEIP
    # Define PLC connection parameters
    $IPAddress = "192.168.1.190"
    $Timeout = 2000  # Timeout value in milliseconds
    try {
        # Create an instance of the Ethernet/IP communication class
        $plc = New-Object EthernetIP.EEIPClient
    }
    catch {
         Write-Host "Error communicating with PLC:" $_.Exception.Message
    }

在 VS 中似乎工作正常(VS 也指向 PS 脚本中指定的相同 dll 位置)

    using Sres.Net.EEIP;
    class Program
    {
        static void Main(string[] args)
        {
            EEIPClient eeipClient = new EEIPClient();
            eeipClient.RegisterSession("192.168.1.190");
            eeipClient.UnRegisterSession();
        }
    }

我尝试加载一个我知道可以工作的 dll。然后我用不起作用的 dll 进行了尝试,并且我收到的输出不太有希望

try
{
   Add-Type -Path "C:\myDlls\EIP\EEIP.dll"
   #Add-Type -Path "C:\OPC\OpcComRcw.dll"
}
catch [System.Reflection.ReflectionTypeLoadException]
{
   Write-Host "Message: $($_.Exception.Message)"
   Write-Host "StackTrace: $($_.Exception.StackTrace)"
   Write-Host "LoaderExceptions: $($_.Exception.LoaderExceptions)"
}

Add-Type:无法加载文件或程序集“file:///C:\myDlls\EIP\EEIP.dll”或其依赖项之一。不支持操作。 (HRESULT 异常:0x80131515)

powershell
1个回答
0
投票

必须右键单击 dll、属性,然后选中取消阻止框。重新启动 powershell,现在它可以工作了:) link 此解决方案

© www.soinside.com 2019 - 2024. All rights reserved.