用无限循环测试,我的应用程序超时了吗?(c#使用PLC硬件输入)



所以我在这里测试这个脚本,以确定哪些输入正在被读入我的c#应用程序。我正在做下面正在工作的时刻

1:设置每个if语句的断点

2:使用24V线手动将PLC上的每个输入端调高

3:查看消息框并确保它正在读取正确的输入

然而,当我删除断点并只是保持程序无限期运行时,并手动尝试打开其中一个输入以测试....没有出现任何消息框,是我的应用程序超时,还是我错过了什么?我对编程并不陌生,但绝对不在我的环境中使用c#工作,所以任何帮助都会很感激。

while (true)
            {
                for (byte i = 0; i < 6; i++)
                {
                    SomeGlobalVariables.inputs = master.ReadInputs(1, 0, 6);
                    if (SomeGlobalVariables.inputs[0] == true)
                    {
                        MessageBox.Show("port 1");
                    }
                    if (SomeGlobalVariables.inputs[1] == true)
                    {
                        MessageBox.Show("port 2");
                    }
                    if (SomeGlobalVariables.inputs[2] == true)
                    {
                        MessageBox.Show("port 3");
                    }
                    if (SomeGlobalVariables.inputs[3] == true)
                    {
                        MessageBox.Show("port 4");
                    }
                    if (SomeGlobalVariables.inputs[4] == true)
                    {
                        MessageBox.Show("port 5");
                    }
            }

for循环中的i变量没有使用,您不妨删除for循环。然后在:

处设置断点
    if (SomeGlobalVariables.inputs[0] == true)

并检查SomeGlobalVariables。输入包含。同样,i从0到5,这是6个值,但是你只检查了5个值。也许你可以将括号中的索引替换为i:

    if (SomeGlobalVariables.inputs[i] == true)
        MessageBox.Show("port " + i);

并将read函数放在for循环之外。

最新更新