private void fetchNodeData()
        {
            //Database Stuff
            NpgsqlConnection conn = new NpgsqlConnection("Server=flick.cs.niu.edu;Port=5432;User Id=readonly;Database=aot;CommandTimeout=240");

            conn.Open();
            NpgsqlCommand command = new NpgsqlCommand("SELECT FORMAT('%s, %s', lat, lon) lat_lon, aot_node_id, address, start_timestamp, end_timestamp, lat, lon FROM aot_nodes WHERE project_id = 'AoT_Chicago' AND aot_node_id != '001e0610ef73';", conn);

            try
            {
                NpgsqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    NodeLocations.Add(reader.GetString(0));
                    NodeIds.Add(reader.GetString(1));
                    NodeAddresses.Add(reader.GetString(2));
                    NodeStart.Add(reader.GetTimeStamp(3).ToString());
                    try
                    {
                        NodeEnd.Add(reader.GetTimeStamp(4).ToString());
                    }
                    catch (System.InvalidCastException icex)
                    {
                        NodeEnd.Add("");
                    }
                    NodeLat.Add(reader.GetString(5));
                    NodeLon.Add(reader.GetString(6));
                }
            }
            catch (System.Exception ex)
            {
                print(ex.Message);
            }

            conn.Close();
        }
Esempio n. 2
0
            private async Task FindObjects(Opc.Ua.Client.Session session, NodeId nodeid)
            {
                if (session == null)
                {
                    return;
                }

                try
                {
                    ReferenceDescriptionCollection references;
                    Byte[] continuationPoint;

                    if (NodeIdsFromObjects.Contains(nodeid.ToString()))
                    {
                        return;
                    }

                    session.Browse(
                        null,
                        null,
                        nodeid,
                        0u,
                        BrowseDirection.Forward,
                        ReferenceTypeIds.HierarchicalReferences,
                        true,
                        (uint)NodeClass.Variable | (uint)NodeClass.Object,
                        out continuationPoint,
                        out references);

                    foreach (var rd in references)
                    {
                        Log(conn_name + " - " + rd.NodeId + ", " + rd.DisplayName + ", " + rd.BrowseName + ", " + rd.NodeClass);
                        if (rd.NodeClass == NodeClass.Variable && !NodeIds.Contains(rd.NodeId.ToString()))
                        {
                            NodeIds.Add(rd.NodeId.ToString());
                            ListMon.Add(
                                new MonitoredItem()
                            {
                                DisplayName      = rd.DisplayName.ToString(),
                                StartNodeId      = rd.NodeId.ToString(),
                                SamplingInterval = System.Convert.ToInt32(System.Convert.ToDouble(OPCUA_conn.autoCreateTagSamplingInterval) * 1000),
                                QueueSize        = System.Convert.ToUInt32(OPCUA_conn.autoCreateTagQueueSize),
                                MonitoringMode   = MonitoringMode.Reporting,
                                DiscardOldest    = true,
                                AttributeId      = Attributes.Value
                            });
                        }
                        else
                        if (rd.NodeClass == NodeClass.Object)
                        {
                            NodeIdsFromObjects.Add(nodeid.ToString());
                            await FindObjects(session, ExpandedNodeId.ToNodeId(rd.NodeId, session.NamespaceUris));

                            Thread.Yield();
                            //Thread.Sleep(1);
                            //await Task.Delay(1);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log(conn_name + " - " + ex.Message);
                }
            }