Example #1
0
        public ReturnCode WriteSingleTagValue(String TagName, String TagValue)
        {
            if (DAServer.ServerState == ServerState.CONNECTED)
            {
                int clientHandle      = 1;
                int transactionHandle = 1;

                ItemIdentifier[] itemIdentifiers = new ItemIdentifier[1];
                ItemValue[]      itemValues      = new ItemValue[1];

                itemIdentifiers[0]              = new ItemIdentifier();
                itemIdentifiers[0].ItemName     = TagName;
                itemIdentifiers[0].ClientHandle = clientHandle;

                itemValues[0]       = new ItemValue();
                itemValues[0].Value = TagValue;

                try
                {
                    return(DAServer.WriteAsync(transactionHandle, ref itemIdentifiers, itemValues));
                }
                catch { return(ReturnCode.ITEMERROR); }
            }
            else
            {
                return(ReturnCode.ITEMERROR);
            }
        }
Example #2
0
        public bool WriteAsync(ItemIdentifier[] itemIdentifiers, ItemValue[] itemValues)
        {
            bool succes = false;
            // Declare variables
            int transactionHandle = 1;

            ReturnCode returnCode;

            try
            { // Call WriteAsync API method
                returnCode = _daServerMgt.WriteAsync(transactionHandle, ref itemIdentifiers, itemValues);
                // Check item results

                if (returnCode != ReturnCode.SUCCEEDED)
                {
                    Writer.writeAll("Write request failed for one or more items : " + returnCode.ToString());
                    Writer.writeAll("ItemID : " + itemIdentifiers.ToString());
                    Writer.writeAll("ItemValue : " + itemValues.ToString());
                    // Examine ResultID objects for detailed information.
                }
                else
                {
                    succes = true;
                }
            }
            catch (Exception e)
            {
                for (int i = 0; i < itemIdentifiers.Length; i++)
                {
                    Writer.writeAll("Item : " + itemIdentifiers[i].ItemName);
                    Writer.writeAll("Value : " + itemValues[i].Value.ToString());
                }
                Writer.writeAll("WriteAsync exception. Reason: " + e);
                if (!_daServerMgt.IsConnected)
                {
                    Writer.writeAll("");
                    Connect();
                }
            }

            return(succes);
        }