Пример #1
0
        public bool OPC_WritePoint(string ItemName, object value)
        {
            try
            {
                using (OPCXML_DataAccess srv = new OPCXML_DataAccess())
                {
                    WriteRequestItemList ItemLists = new WriteRequestItemList();
                    ItemLists.Items                       = new ItemValue[1];
                    ItemLists.Items[0]                    = new ItemValue();
                    ItemLists.Items[0].ItemPath           = "";
                    ItemLists.Items[0].ItemName           = ItemName;
                    ItemLists.Items[0].Value              = value;
                    ItemLists.Items[0].TimestampSpecified = false;

                    RequestOptions opt = new RequestOptions();

                    ReplyItemList ItemValues = new ReplyItemList();
                    OPCError[]    Errors;
                    opt.ReturnItemTime = true;
                    ReplyBase replay = srv.Write(opt, ItemLists, true, out ItemValues, out Errors);
                    if (replay.ServerState == serverState.failed || replay.ServerState == serverState.commFault)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #2
0
 public bool OPC_WriteSerial(List <string> ItemNames, List <object> values)
 {
     try
     {
         using (OPCXML_DataAccess srv = new OPCXML_DataAccess())
         {
             int count = ItemNames.Count;
             WriteRequestItemList ItemLists = new WriteRequestItemList();
             ItemLists.Items = new ItemValue[count];
             for (int i = 0; i < count; i++)
             {
                 ItemLists.Items[i]                    = new ItemValue();
                 ItemLists.Items[i].ItemPath           = "";
                 ItemLists.Items[i].ItemName           = ItemNames[i];
                 ItemLists.Items[i].Value              = values[i];
                 ItemLists.Items[i].TimestampSpecified = false;
             }
             RequestOptions opt        = new RequestOptions();
             ReplyItemList  ItemValues = new ReplyItemList();
             OPCError[]     Errors;
             opt.ReturnItemTime = true;
             ReplyBase replay = srv.Write(opt, ItemLists, true, out ItemValues, out Errors);
             if (replay.ServerState == serverState.failed || replay.ServerState == serverState.commFault)
             {
                 return(false);
             }
             else
             {
                 return(true);
             }
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #3
0
        /*---------------------------------------------Writing Function Decleration ----------------------------------------------------------------*/
        public void OPCWrite(List <string> TagNames, List <object> TagsValues)
        {
            /*---------------------------------------------Request Instance Decleration ----------------------------------------------------------------*/
            WriteRequestItemList WriteItemList = new WriteRequestItemList();
            List <string>        TagName       = new List <string>(TagNames);
            List <object>        TagValue      = new List <object>(TagsValues);

            RequestOptions.ClientRequestHandle      = "";
            RequestOptions.LocaleID                 = "EN-US";
            RequestOptions.RequestDeadlineSpecified = false;
            RequestOptions.ReturnDiagnosticInfo     = false;
            RequestOptions.ReturnErrorText          = false;
            RequestOptions.ReturnItemName           = false;
            RequestOptions.ReturnItemPath           = false;
            RequestOptions.ReturnItemTime           = false;

            int TagNos = TagName.Count();

            WriteItemList.Items = new ItemValue[TagNos];
            //Console.WriteLine(WriteItemList.Items.Length.ToString()); // Test for the No of Items

            for (int Looper = 0; Looper < TagNos; Looper++)
            {
                WriteItemList.Items[Looper]          = new ItemValue();
                WriteItemList.ItemPath               = "";
                WriteItemList.Items[Looper].ItemName = TagName[Looper];
                WriteItemList.Items[Looper].Value    = TagValue[Looper];
                Console.WriteLine(WriteItemList.Items[Looper].ItemName.ToString() + "Value Sent" + WriteItemList.Items[Looper].Value.ToString()); // Test Output
            }
            ReturnValueOnReply = false;
            /*---------------------------------------------Writing Invoked ----------------------------------------------------------------*/
            myClient.Write(RequestOptions, WriteItemList, ReturnValueOnReply, out ReplyList, out ErrorList);

            TagNames = null;
            TagValue = null;
        }