コード例 #1
0
ファイル: Program.cs プロジェクト: tikyau/iot-central
 static async void StartReadAsync(OPCDaHelper opcHelper, List <TopicItem> topicItems)
 {
     while (true)
     {
         var resultItems = opcHelper.Read();
         foreach (var item in resultItems)
         {
             var currentTopicItem = topicItems.SingleOrDefault(i => i.Name == item.ItemName);
             Console.WriteLine("Topic Found => " + currentTopicItem.Name);
             //Task.Run(async () => await SendDataToIoTCentralAsync(currentTopicItem.DeviceConnectionString, currentTopicItem.DeviceTelemetryFieldName, item.ItemName, item.Value.ToString())).ConfigureAwait(false);
             await SendDataToIoTCentralAsync(currentTopicItem.DeviceConnectionString,
                                             currentTopicItem.DeviceTelemetryFieldName,
                                             item.ItemName,
                                             item.Value.ToString());
         }
         await Task.Delay(delayInMilliseconds);
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: tikyau/iot-central
        static void Main(string[] args)
        {
            var topicConfig = GetTopicConfig();
            var topicItems  = topicConfig.TopicItems;

            var opcHelper = new OPCDaHelper();
            var connected = opcHelper.Connect("");

            if (connected)
            {
                Console.WriteLine(opcHelper.VendorInfo);
                Console.WriteLine(opcHelper.VersionInfo);
                Console.WriteLine(opcHelper.StatusInfo);

                var daItems = new List <Opc.Da.Item>();
                foreach (var item in topicItems)
                {
                    daItems.Add(new Opc.Da.Item(new Opc.ItemIdentifier(null, item.Name))
                    {
                        ReqType               = null,
                        MaxAge                = 0,
                        MaxAgeSpecified       = false,
                        Active                = false,
                        ActiveSpecified       = false,
                        Deadband              = 0,
                        DeadbandSpecified     = false,
                        SamplingRate          = 0,
                        SamplingRateSpecified = false,
                        ClientHandle          = Guid.NewGuid().ToString()
                    });
                }
                opcHelper.AddTopicItems(daItems);

                StartReadAsync(opcHelper, topicItems);
            }
            Console.ReadLine();
        }