简体   繁体   English

价值不在预期范围内。 (运行时错误)

[英]Value Does not fall within the expected range. (Runtime Error)

I am converting a Windows Form from VB to C# and I ran in to an error when I attempted to do a synchronized read of my OPC tags. 我正在将Windows窗体从VB转换为C#,当我尝试对OPC标签进行同步读取时,我遇到了错误。

I have this code: 我有这个代码:

public partial class FrmPartialMain : Form
{   
    RsiOPCAuto.OPCServer oOpcServer;
    RsiOPCAuto.OPCGroup oOpcGroup;

    int ClHandle; //this is set to 1 in another part of the code.
    int SvHandle;


    int OpcDsCashe = 1;
    int OpcDsDevice = 2;
    private void cmdSyncRead_Click(object sender, EventArgs e)
    {
        int lNumItems = oOpcGroup.OPCItems.Count; // = 3
        int[] h = new int[lNumItems];
        Array arValues = new int[lNumItems];
        Array arHandles;
        Array arErrors;
        object Qualities;
        object Timestamps;


        h[ClHandle - 1] = oOpcGroup.OPCItems.Item(ClHandle).ServerHandle;  
        arHandles = (Array)h;
        //Error on the next line bellow.
        oOpcGroup.SyncRead((short)OpcDsDevice, lNumItems, ref arHandles, out arValues, out arErrors, out Qualities, out Timestamps);


        txtSubValue.Text = Convert.ToString(arValues.GetValue(0));
    }
}

oOpcGroup.Read() reads the value, quality and timestamp information for one or more items in a group. oOpcGroup.Read()读取组中一个或多个项的值,质量和时间戳信息。 and the return type looks like this: 返回类型如下所示:

 SyncRead(short Source, int NumItems, ref System.Array ServerHandles, out System.Array Values, out System.Array Errors, out object Qualities, out object TimeStamps);

Running this code gives me the error in the title, Value Does not fall within the expected range. 运行此代码会在标题中显示错误,值不在预期范围内。 Any ideas of what i might be doing wrong here? 我在这里做错了什么想法?

Brainstorm away! 头脑风暴!

It's alive! 它还活着!

This is the fixed code: 这是固定代码:

public partial class FrmPartialMain : Form
{   
    RsiOPCAuto.OPCServer oOpcServer;
    RsiOPCAuto.OPCGroup oOpcGroup;

    int ClHandle; //this is set to 1 in another part of the code.
    int SvHandle;


    int OpcDsCashe = 1;
    int OpcDsDevice = 2;
    private void cmdSyncRead_Click(object sender, EventArgs e)                                                                                  //Sync Read
    {
        int lNumItems = oOpcGroup.OPCItems.Count;
        int[] arH = new int[1 + lNumItems];
        Array arValues = new object[1 + lNumItems]; //<-- This needed to be an object array.
        Array arHandles;
        Array arErrors;
        object Qualities;
        object Timestamps;

        arH[ClHandle] = oOpcGroup.OPCItems.Item(ClHandle).ServerHandle;

        arHandles = (Array)arH;
        oOpcGroup.SyncRead((short)OpcDsDevice, lNumItems, ref arHandles, out arValues, out arErrors, out Qualities, out Timestamps);

        txtSubValue.Text = Convert.ToString(arValues.GetValue(1));
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “值不在预期范围内。”窗口8 ObservableDictionary错误 - “Value does not fall within the expected range.” Window 8 ObservableDictionary Error AZMan:InitializeClientContextFromName 失败并显示“值不在预期范围内”。 - AZMan: InitializeClientContextFromName failing with “Value does not fall within the expected range.” 值不在预期范围内。 在必应地图上 - Value does not fall within the expected range. in Bing Maps System.ArgumentException:&#39;值不在预期范围内。 - System.ArgumentException: 'Value does not fall within the expected range.' UWP StorageFile.CopyAsync()引发错误:“值不在预期范围内。” - UWP StorageFile.CopyAsync() Throwing Error: “Value does not fall within the expected range.” 在ExecuteStoreQuery中使用OracleParameter错误消息:“值不在预期范围内。” - Using OracleParameter in ExecuteStoreQuery Error Msg : “ Value does not fall within the expected range.” 从Windows Phone 7调用GAE托管的REST服务时,“错误值不在预期范围内。”错误 - “Value does not fall within the expected range.” error when call GAE-hosted REST service from Windows Phone 7 更改自定义传输控件的滑块值会产生异常{“该值未在预期范围内。”} - Changing slider value of custom transport control gives an exception {“Value does not fall within the expected range.”} Windows Phone 8映射:{System.ArgumentException:值不在预期范围内。} - Windows Phone 8 Map : {System.ArgumentException: Value does not fall within the expected range.} 如何防止此异常:值不在预期范围内。 使用WaitHandle.WaitAny方法? - How to prevent this Exception: Value does not fall within the expected range. with WaitHandle.WaitAny method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM