【问题标题】:Console application hits break mode immediate控制台应用程序立即进入中断模式
【发布时间】:2018-01-11 13:25:12
【问题描述】:

我刚刚用 c# 下载了一个控制台应用程序。尝试调试以“中断模式屏幕”结束。 Visual Studio 说:“您的应用已进入中断状态,但当前没有执行所选调试引擎支持的代码(例如,仅执行本机运行时代码)。”

该应用程序是设置与 PLC 的连接的示例。

using System;
using ControlLogixNET;
using ControlLogixNET.LogixType;

namespace ArrayTags
{
    class Program
    {
        /*
         * HOW TO USE THIS SAMPLE 
         * 
         * 1. First change the hostNameOrIp to the IP address or host name of your PLC
         * 2. Then change the path to be the path to your PLC, see comments below
         * 3. Create a 1 dimensional DINT array on the processor called dintArray1[10]
         * 4. Create a 2 dimensional DINT array on the processor called dintArray2[10,10]
         * 5. Create a 3 dimensional DINT array on the processor called dintArray3[10,10,10]
         * 6. Run
         * 
        */

        static void Main(string[] args)
        {
            //First we create the processor object. Typically the path is the slot
            //number of the processor module in the backplane, but if your communications
            //card is not in the same chassis as your processor, this is the path through
            //the chassis to get to your processor. You will have to add a 1 for every
            //chassis you go through, for example:
            //Chassis 1: ENBT card in Slot 1 (slot is irrelavent), ControlNet Card in Slot 2
            //Chassis 2: L61 in Slot 4
            //Path would be: { 2, 1, 4 }
            //Basically it's the target slot, 1 for backplane, target slot, 1 for backplane...
            //until you get to the processor.
            string hostNameOrIp = "169.254.125.220";
            byte[] path = new byte[] { 3 };
            LogixProcessor processor = new LogixProcessor(hostNameOrIp, path);

            //The processor has to be connected before you add any tags or tag groups.
            if (!processor.Connect())
            {
                Console.WriteLine("Could not connect to the processor");
                Console.ReadKey(false);
                return;
            }

            //First create a group. Groups are much more efficient at reading and writing
            //large numbers of tags.
            LogixTagGroup myGroup = processor.CreateTagGroup("MyGroup");

            //Now let's create our first array. The number of elements is the TOTAL number
            //of elements to read, in all dimensions. 
            LogixDINT dintArray1 = new LogixDINT("dintArray1", processor, 10);

            //We don't need to set the number of dimensions on the tag here because it
            //assumes that it's a single dimension tag. All tags are set up to be arrays
            //by default, the .Value or similar member always returns the 0th element
            //of the array. With a tag that is not an array, that is where the value is.

            //Let's create the 2 dimensional array
            LogixDINT dintArray2 = new LogixDINT("dintArray2", processor, 100);

            //The number of elements are the subscripts multiplied by each other. In this
            //case, 10*10 = 100. If you put a lower value here you will only read that
            //much of the array. ControlLogix packs it's arrays in row major format, so
            //just keep that in mind if reading partial arrays.

            //If you want to set it up to read with a multidimensional accessor, we need
            //to tell the tag what the size of the dimensions are.
            dintArray2.SetMultipleDimensions(10, 10);

            //We can now access the tag by the tagName[row,column] format. If you didn't
            //set the size, you would get an exception when trying to access the tag
            //using that format.

            //Let's create the last tag
            LogixDINT dintArray3 = new LogixDINT("dintArray3", processor, 1000);

            //Set the dimensions
            dintArray3.SetMultipleDimensions(10, 10, 10);

            //Now let's add our tags to the tag group...
            myGroup.AddTag(dintArray1);
            myGroup.AddTag(dintArray2);
            myGroup.AddTag(dintArray3);

            Console.WriteLine("6D Systems LLC\n\n");
            Console.WriteLine("Tags created...");

            //Now let's pick out some random members and display them...
            Console.WriteLine("dintArray1[4]     = " + dintArray1[4].ToString());
            Console.WriteLine("dintArray2[5,2]   = " + dintArray2[5, 2].ToString());
            Console.WriteLine("dintArray3[4,7,3] = " + dintArray3[4, 7, 3].ToString());
            Console.WriteLine("\nPress any key to write a new value to each of the above tags");
            Console.ReadKey(false);

            //Now let's write some data to those tags...
            Random rnd = new Random();
            dintArray1[4] = rnd.Next(int.MinValue, int.MaxValue);
            dintArray2[5, 2] = rnd.Next(int.MinValue, int.MaxValue);
            dintArray3[4, 7, 3] = rnd.Next(int.MinValue, int.MaxValue);

            //Let's update the tag group
            processor.UpdateGroups();

            //Now print them back out for the user...
            Console.WriteLine("\nNew tag values...");
            Console.WriteLine("dintArray1[4]     = " + dintArray1[4].ToString());
            Console.WriteLine("dintArray2[5,2]   = " + dintArray2[5, 2].ToString());
            Console.WriteLine("dintArray3[4,7,3] = " + dintArray3[4, 7, 3].ToString());
            Console.WriteLine("\nPress any key to quit");
            Console.ReadKey(false);

            //Remember to disconnect from the processor
            processor.Disconnect();

        }
    }
}

这个项目中唯一特别的是处理与 PLC 的 TCP/IP 连接的定制库。这些库可在here 下载。

还很高兴知道输出窗口的值,它说:

未知模块中发生“System.IO.FileNotFoundException”类型的未处理异常。 无法加载文件或程序集“ControlLogixNET,版本=1.1.4597.20464,Culture=neutral,PublicKeyToken=null”或其依赖项之一。系统找不到指定的文件。


更新:

我将 ControlLogixNET.dll 文件放入“Dependency Walker”中,结果如下:

错误:发现具有不同 CPU 类型的模块。警告:至少 未找到一个延迟加载依赖模块。警告:至少一个 由于缺少导出功能,模块具有未解析的导入 延迟加载依赖模块。”

这会是个问题吗?

【问题讨论】:

  • 引用的代码出现错误,您没有并且可能是非托管代码。
  • 我强烈推荐 Snap7 项目 C# 类用于 PLC 通信(西门子),完全可调试。
  • 此测试项目适用于与 Rockwell PLC (Allen Bradley) 一起运行的应用程序
  • 您似乎需要另一个版本的 ControlLogixNET 库。您的项目使用哪种 CPU 类型?
  • 您了解您的解决方案平台,以及第三方库的解决方案平台吗?在我看来,您的项目可能具有 AnyCPU 配置,并且该库是特定的 Debug/Release 配置。

标签: c# visual-studio console-application breakpoints


【解决方案1】:

您是否还有 ControlLogixNET 所依赖的 EIPNET 代码或 dll?

【讨论】:

  • 不,我发现这个库与我的 UWP 应用程序不兼容。与此同时,我自己为 UWP 编写了一个库来让我的项目正常运行。
猜你喜欢
  • 2014-09-04
  • 2012-08-06
  • 1970-01-01
  • 2012-09-13
  • 1970-01-01
  • 2011-02-01
  • 2021-12-16
  • 2012-10-26
相关资源
最近更新 更多