private void DevicesDocumentReceived(MTConnectDevices.Document document) { log.Trace("MTConnect Devices Document Received @ " + DateTime.Now.ToString("o")); UpdateConnectedStatus(true); if (document.Header != null && document.Devices != null && document.Devices.Count == 1) { currentAgentInstanceId = document.Header.InstanceId; DateTime timestamp = document.Header.CreationTime; // Send Agent AgentReceived?.Invoke(this, Create(_deviceId, document.Header)); var dataItems = new List <DataItemDefinition>(); var components = new List <ComponentDefinition>(); var device = document.Devices[0]; // Send Device DeviceReceived?.Invoke(this, Create(_deviceId, currentAgentInstanceId, device)); // Add DataItems foreach (var item in device.DataItems) { dataItems.Add(Create(_deviceId, currentAgentInstanceId, device.Id, "Device", item)); } // Add Component components.AddRange(GetComponents(_deviceId, currentAgentInstanceId, device.Id, "Device", device.Components)); // Add Component DataItems foreach (var component in device.GetComponents()) { foreach (var dataItem in component.DataItems) { dataItems.Add(Create(_deviceId, currentAgentInstanceId, component.Id, "Component", dataItem)); } } // Get the Availability DataItem var avail = device.DataItems.Find(o => o.Type == "AVAILABILITY"); if (avail != null) { availabilityId = avail.Id; } // Send ContainerDefinition Objects if (components.Count > 0) { ComponentsReceived?.Invoke(this, components); } // Send DataItemDefinition Objects if (dataItems.Count > 0) { DataItemsReceived?.Invoke(this, dataItems); } } }
private void Probe_Successful(MTConnectDevices.Document document) { Dispatcher.BeginInvoke(new Action(() => { ConnectionTestResult = 1; ConnectionTestResultText = "MTConnect Probe Successful @ " + document.Url; ConnectionTestLoading = false; })); }
// --- Event Handlers --- void DevicesSuccessful(MTConnectDevices.Document document) { foreach (var device in document.Devices) { var dataItems = device.GetDataItems(); foreach (var dataItem in dataItems) { Console.WriteLine(dataItem.Id + " : " + dataItem.Name); } } }
private void Start(DeviceConfiguration config) { if (!started) { stop = new ManualResetEvent(false); started = true; probeData = null; var requestsThread = new Thread(new ParameterizedThreadStart(Worker)); requestsThread.Start(config); } }
private MTConnectDevices.Document GetProbe(Data.AgentInfo config) { MTConnectDevices.Document result = null; string address = config.Address; int port = config.Port; string deviceName = config.DeviceName; //// Set Proxy Settings //var proxy = new HTTP.ProxySettings(); //proxy.Address = config.ProxyAddress; //proxy.Port = config.ProxyPort; DateTime requestTimestamp = DateTime.Now; // Create Agent Url var protocol = "http://"; var adr = address; if (adr.IndexOf(protocol) >= 0) { adr = adr.Substring(protocol.Length); } else { adr = protocol + adr; } var url = adr; if (port > 0 && port != 80) { url += ":" + port; } // Send Probe Request var probe = new MTConnect.Clients.Probe(url, deviceName); result = probe.Execute(); if (result != null) { if (verbose) { logger.Info("Probe Successful : " + url + " @ " + requestTimestamp.ToString("o")); } } else { logger.Warn("Probe Error : " + url + " @ " + requestTimestamp.ToString("o") + " : Retrying in " + (config.Heartbeat / 1000) + " sec.."); } return(result); }
private void RunRequests(DeviceConfiguration config) { var ac = config.Agent; if (ac != null) { // Run a Probe request and get the returned data if (probeData == null) { probeData = GetProbe(ac); // Send the Probe data to other plugins SendProbeData(probeData, config); } if (probeData != null) { // Run a Current request and get the returned data currentData = GetCurrent(ac); if (currentData != null && currentData.Header != null) { // Send the Current data to other plugins SendCurrentData(currentData, config); //Run a Sample request and get the returned data var sampleData = GetSample(currentData.Header, ac, config); //Send the Sample data to other plugins if (sampleData != null) { SendSampleData(sampleData, config); } UpdateAgentData(currentData.Header.InstanceId, currentData.Header.LastSequence); } else { probeData = null; SendAvailability(false, ac.Heartbeat, config); } } else { SendAvailability(false, ac.Heartbeat, config); } } }
private void SendProbeData(MTConnectDevices.Document returnData, DeviceConfiguration config) { if (returnData != null && returnData.Header != null) { if (returnData.Header.InstanceId != agentInstanceId) { SendAgentReset(config); } agentInstanceId = returnData.Header.InstanceId; } var data = new EventData(this); data.Id = "MTCONNECT_PROBE"; data.Data01 = config; data.Data02 = returnData; SendData?.Invoke(data); }
public static List <StatusInfo> GetList(MTConnectDevices.Document probe) { var result = new List <StatusInfo>(); if (probe.Devices != null && probe.Devices.Count > 0) { var device = probe.Devices[0]; foreach (var item in device.DataItems) { result.Add(ProcessDataItem(item)); } foreach (var component in device.Components.Components) { result.AddRange(ProcessComponent(component)); result.AddRange(ProcessSubcomponents(component.SubComponents.Components)); } } return(result); }
private void Client_ProbeReceived(MTConnectDevices.Document document) { throw new NotImplementedException(); }
private void DevicesSuccessful(MTConnectDevices.Document document) { log.Trace("MTConnect Devices Document Received @ " + DateTime.Now.ToString("o")); UpdateConnectedStatus(true); if (document.Header != null && document.Devices != null && document.Devices.Count == 1) { long agentInstanceId = document.Header.InstanceId; DateTime timestamp = document.Header.CreationTime; // Send Agent Definition 发送Agent的定义 AgentDefinitionsReceived.Invoke(Create(_deviceId, document.Header)); var dataItemDefinitions = new List <DataItemDefinitionData>(); var componentDefinitions = new List <ComponentDefinitionData>(); var dataFilters = new List <DataFilter>(); var device = document.Devices[0]; // Send Device Definition 发送Device的定义 DeviceDefinitionsReceived.Invoke(Create(_deviceId, agentInstanceId, device)); // Add DataItems 向数据项定义数据集合dataItemDefinitions中添加设备的数据项定义数据的数据项 foreach (var item in device.DataItems) { dataItemDefinitions.Add(Create(_deviceId, agentInstanceId, device.Id, item)); } // Add Component Definitions 向组件定义数据集合componentDefinitions中添加设备的组件定义数据的数据项 componentDefinitions.AddRange(GetComponents(_deviceId, agentInstanceId, device.Id, device.Components)); // Add Component DataItems 添加组件的数据项 foreach (var component in device.GetComponents()) { foreach (var dataItem in component.DataItems) { dataItemDefinitions.Add(Create(_deviceId, agentInstanceId, component.Id, dataItem)); } } // Get the Availability DataItem获取可用的DataItem var avail = device.DataItems.Find(o => o.Type == "AVAILABILITY"); if (avail != null) { availabilityId = avail.Id; } // Send ContainerDefinition Objects 发送定义的组件对象 if (componentDefinitions.Count > 0) { ComponentDefinitionsReceived.Invoke(componentDefinitions); } // Send DataItemDefinition Objects 发送数据项定义对象 if (dataItemDefinitions.Count > 0) { DataItemDefinitionsReceived.Invoke(dataItemDefinitions); } } }