CreateItem() public méthode

Creates the item.
public CreateItem ( string itemId, int samplingInterval, float deadband, bool active ) : GroupItem
itemId string The item id.
samplingInterval int The sampling interval.
deadband float The deadband.
active bool if set to true [active].
Résultat GroupItem
Exemple #1
0
        /// <summary>
        /// Reads the item values and stores the results in the request object.
        /// </summary>
        /// <param name="requests">The requests.</param>
        private void Da20ReadItemValues(List<ReadRequest> requests)
        {
            // lock (m_groupLock)
            {
                // if (m_group == null)
                //{                
                    ComDaGroup m_group = new ComDaGroup(this, false);
                //}

                try
                {
                    int count1 = 0;
                    GroupItem[] items = new GroupItem[requests.Count];
                    ReadRequest[] addItemRequests = new ReadRequest[requests.Count];

                    // create the items in the temporary group.
                    for (int ii = 0; ii < requests.Count; ii++)
                    {
                        ReadRequest request = requests[ii];

                        if (request == null)
                        {
                            continue;
                        }

                        if (!request.ValueRequired)
                        {
                            continue;
                        }

                        // add the item.
                        items[count1] = m_group.CreateItem(request.ItemId, 0, 0, true);
                        addItemRequests[count1] = request;
                        count1++;
                    }

                    // create the items on the server.
                    m_group.ApplyChanges();

                    // build the list of values to write.
                    int count2 = 0;
                    int[] serverHandles = new int[count1];
                    ReadRequest[] readRequests = new ReadRequest[count1];

                    for (int ii = 0; ii < count1; ii++)
                    {
                        // check for error on create.
                        GroupItem item = items[ii];
                        ReadRequest request = addItemRequests[ii];

                        if (item.ErrorId < 0)
                        {
                            request.Value = new DaValue();
                            request.Value.Error = item.ErrorId;
                            continue;
                        }

                        serverHandles[count2] = item.ServerHandle;
                        readRequests[count2] = request;
                        count2++;
                    }

                    if (count2 > 0)
                    {
                        // write values to the server.
                        DaValue[] values = m_group.SyncRead(serverHandles, count2);

                        // read the values.
                        for (int ii = 0; ii < count2; ii++)
                        {
                            if (values != null && values.Length > ii)
                            {
                                readRequests[ii].Value = values[ii];
                            }
                            else
                            {
                                readRequests[ii].Value = new DaValue() { Error = ResultIds.E_FAIL, Timestamp = DateTime.UtcNow };
                            }
                        }

                        // delete the items.
                        for (int ii = 0; ii < count1; ii++)
                        {
                            GroupItem item = items[ii];

                            if (item.ErrorId >= 0)
                            {
                                m_group.RemoveItem(item);
                            }
                        }

                        m_group.ApplyChanges();
                    }
                }
                finally
                {
                    // delete the group and items.
                   m_group.Delete();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Writes the item values to servers.
        /// </summary>
        /// <param name="requests">The requests.</param>
        private void Da20WriteItemValues(List<WriteRequest> requests)
        {
            //lock (m_groupLock)
            {
                //if (m_group == null)
                //{
                    ComDaGroup m_group = new ComDaGroup(this, false);
                //}

                try
                {
                    int count1 = 0;
                    GroupItem[] items = new GroupItem[requests.Count];
                    WriteRequest[] addItemRequests = new WriteRequest[requests.Count];
                    object[] convertedValues = new object[requests.Count];

                    // create the items in the temporary group.
                    for (int ii = 0; ii < requests.Count; ii++)
                    {
                        WriteRequest request = requests[ii];

                        if (request == null)
                        {
                            continue;
                        }

                        // status code writes not supported.
                        if (request.Value.StatusCode != StatusCodes.Good)
                        {
                            request.Error = ResultIds.E_NOTSUPPORTED;
                            continue;
                        }

                        // timestamp writes not supported.
                        if (request.Value.ServerTimestamp != DateTime.MinValue)
                        {
                            request.Error = ResultIds.E_NOTSUPPORTED;
                            continue;
                        }

                        // timestamp writes not supported.
                        if (request.Value.SourceTimestamp != DateTime.MinValue)
                        {
                            request.Error = ResultIds.E_NOTSUPPORTED;
                            continue;
                        }

                        // convert to a DA compatible type.
                        object convertedValue = null;
                        request.Error = ComDaClientNodeManager.LocalToRemoteValue(request.Value.WrappedValue, out convertedValue);

                        if (request.Error < 0)
                        {
                            continue;
                        }

                        // add the item.
                        items[count1] = m_group.CreateItem(request.ItemId, 0, 0, true);
                        addItemRequests[count1] = request;
                        convertedValues[count1] = convertedValue;
                        count1++;
                    }

                    // create the items on the server.
                    m_group.ApplyChanges();

                    // build the list of values to write.
                    int count2 = 0;
                    int[] serverHandles = new int[count1];
                    object[] values = new object[count1];
                    WriteRequest[] writeRequests = new WriteRequest[count1];

                    for (int ii = 0; ii < count1; ii++)
                    {
                        // check for error on create.
                        GroupItem item = items[ii];
                        WriteRequest request = addItemRequests[ii];

                        if (item.ErrorId < 0)
                        {
                            request.Error = item.ErrorId;
                            continue;
                        }

                        serverHandles[count2] = item.ServerHandle;
                        values[count2] = convertedValues[ii];
                        writeRequests[count2] = request;
                        count2++;
                    }

                    if (count2 > 0)
                    {
                        // write values to the server.
                        int[] errors = m_group.SyncWrite(serverHandles, values, count2);

                        // read the errors.
                        for (int ii = 0; ii < count2; ii++)
                        {
                            if (errors != null && errors.Length > ii)
                            {
                                writeRequests[ii].Error = errors[ii];
                            }
                            else
                            {
                                writeRequests[ii].Error = ResultIds.E_FAIL;
                            }
                        }

                        // delete the items.
                        for (int ii = 0; ii < count1; ii++)
                        {
                            GroupItem item = items[ii];

                            if (item.ErrorId >= 0)
                            {
                                m_group.RemoveItem(item);
                            }
                        }

                        m_group.ApplyChanges();
                    }
                }
                finally
                {
                    // delete the group and items.
                    m_group.Delete();
                }
            }
        }