Пример #1
0
        public ModelElement DoVerify(ModelElement element, AceModelRestricted model)
        {
            // For interface that are not PnP and can come and go, verify that they are still present.
            //   (e.g. RemoteGPIB, etc.)
            // In most cases, nothing will need to be done to verify an interface.
            // Return a copy of the input element.
            // The following values need to be set in the returned element:
            //   Verified = true means it has been through this method
            //   Failed = true / false
            if (element == null)
            {
                return(null);
            }
            var        elementCopy = element.MakeCopy();
            IConfigDll hwconfig    = _container.Resolve <IConfigDll>(AgentName);

            hwconfig.VerifyElement(elementCopy);
            var parent = model.FindEquivalentElement(elementCopy.Parent);

            if (parent != null)
            {
                elementCopy.Parent   = parent;
                elementCopy.ParentId = parent.PersistentId;
            }
            return(elementCopy);
        }
Пример #2
0
        public void StartBackgroundProcessingTest()
        {
            var container = GenerateContainer();
            var agent     = new SampleIOAgent(container);

            agent.Initialize();
            IConfigDll config  = container.Resolve <IConfigDll>("IoAgentSample");
            var        watcher = container.Resolve <SampleDiscoveryWatcher>();
            var        discoveredInterfaceList = new List <string>();

            watcher.WaitingInterval        = 1;
            watcher.RequestDiscoveryAction = i =>
            {
                discoveredInterfaceList.Add(i.VisaInterfaceId);
            };
            var hwconfig = config as HwConfigSample;

            hwconfig.SampleFileName = "sample4.xml";
            agent.BackgroundWaiting = 1;

            var cts = new CancellationTokenSource();

            agent.StartBackgroundProcessing(cts.Token);
            for (int i = 0; i < 2; i++)
            {
                Thread.Sleep(1100);
            }
            cts.Cancel();

            Assert.IsTrue(discoveredInterfaceList.Contains("SAMP0"));
            Assert.IsTrue(discoveredInterfaceList.Count >= 2);
        }
Пример #3
0
        private ModelInterface[] GetUnconfigedInterfaces(AceModelRestricted model)
        {
            IConfigDll hwconfig = _container.Resolve <IConfigDll>(AgentName);

            if ((hwconfig == null) || (model == null))
            {
                return(Enumerable.Empty <ModelInterface>().ToArray());
            }
            return(model.GetUnconfigedSampleInterfaces(hwconfig).ToArray());
        }
 private void DiscoverInterfaces(IConfigDll hwconfig)
 {
     var intfcs = _model.GetAllElements().Where(e => e is ModelInterfaceSample).Select(i => i as ModelInterfaceSample);
     var unconfigedIntfcs = _model.GetUnconfigedSampleInterfaces(hwconfig);
     var intfcList = new List<ModelInterfaceSample>();
     intfcList.AddRange(intfcs);
     intfcList.AddRange(unconfigedIntfcs);
     var checkList = intfcList.Where(i => i.AutoDiscoverDevices);
     foreach (var intfc in checkList)
     {
         RequestDiscoveryAction(intfc);
     }
 }
Пример #5
0
        private void DiscoverInterfaces(IConfigDll hwconfig)
        {
            var intfcs           = _model.GetAllElements().Where(e => e is ModelInterfaceSample).Select(i => i as ModelInterfaceSample);
            var unconfigedIntfcs = _model.GetUnconfigedSampleInterfaces(hwconfig);
            var intfcList        = new List <ModelInterfaceSample>();

            intfcList.AddRange(intfcs);
            intfcList.AddRange(unconfigedIntfcs);
            var checkList = intfcList.Where(i => i.AutoDiscoverDevices);

            foreach (var intfc in checkList)
            {
                RequestDiscoveryAction(intfc);
            }
        }
        public static IEnumerable<ModelInterfaceSample> GetUnconfigedSampleInterfaces(this AceModelRestricted model, IConfigDll hwconfig)
        {
            var unconfigured = Enumerable.Empty<ModelInterfaceSample>();
            if ((hwconfig != null) && (model != null))
            {
                hwconfig.InitializeDll();
                //ModelElement[] configuredInterfaceElements = model.GetInterfacesOfVisaType(this.VisaIntfTypeString);  // EOS: unused, removed.
                var availableInterfaces = hwconfig.GetAvailableInterfaces().Where(i => i is ModelInterfaceSample).Select(i => i as ModelInterfaceSample);
                // TCPIP only configures 1 interface by default, but this pattern supports any number
                unconfigured = (from i in availableInterfaces
                                where model.FindEquivalentElement(i) == null
                                select i);

                hwconfig.UninitializeDll();
            }
            return unconfigured;
        }
Пример #7
0
        public List <ModelElement> DoDiscovery(ModelElement discoveryRoot, AceModelRestricted model)
        {
            // Discover devices on interfaces
            // If discoveryRoot is null or empty discovery devices on all interfaces associated with this agent.
            // If discoveryRoot is specified, verify the presence of the interface and discover all devices on it.
            // - The model paramenter contains elements that are currently known - treat it as read-only
            // - Add only newly discovered or deleted elements to the output list.
            // - Notes:
            //      - Only devices are discovered here. Interfaces are discovered and added to the model in AutoConfig().
            //      - Elements in the output list will later be verified using DoVerify().
            //      - If we are not confident that a discovered device is the same as one already in the model,
            //        then we should copy it to the output List so it will later be verified.

            //string doDiscoveryTitle = string.Format("DoDiscovery of {0}", (discoveryRoot != null) ? discoveryRoot.ToString() : "<null>");
            //LogUtils.LogElements(_log, this, doDiscoveryTitle, model.GetInterfaces()); // Verbose
            if (_log != null && discoveryRoot != null)
            {
                var    id  = discoveryRoot.PersistentId;
                string msg = string.Format("Begin discovery of '{0}'", id);
                _log.Message(msg, LogUtils.MethodName(this));
            }
            var list  = new List <ModelElement>();
            var intfc = discoveryRoot as ModelInterfaceSample;

            if (intfc != null)
            {
                IConfigDll hwconfig = _container.Resolve <IConfigDll>(AgentName);
                hwconfig.InitializeDll();
                var intfcCopy       = intfc.MakeCopy() as ModelInterfaceSample;
                var availableIntfcs = hwconfig.GetAvailableInterfaces()
                                      .Where(i => i is ModelInterfaceSample)
                                      .Select(i => i as ModelInterfaceSample);
                if (intfcCopy.IsInterfacePresent(availableIntfcs) ||
                    intfc.StaticallyDefined)
                {
                    list.Add(intfcCopy);
                    FindAndUpdateDevices(hwconfig, list, intfc, model);
                }
                hwconfig.UninitializeDll();
            }
            return(list);
        }
Пример #8
0
        private void FindAndUpdateDevices(IConfigDll hwconfig, List <ModelElement> discoveredList, ModelInterfaceSample intfc, AceModelRestricted model)
        {
            var connectedDevices = hwconfig.GetAvailableDevices(intfc);

            discoveredList.AddRange(connectedDevices);
        }
Пример #9
0
        public static IEnumerable <ModelInterfaceSample> GetUnconfigedSampleInterfaces(this AceModelRestricted model, IConfigDll hwconfig)
        {
            var unconfigured = Enumerable.Empty <ModelInterfaceSample>();

            if ((hwconfig != null) && (model != null))
            {
                hwconfig.InitializeDll();
                //ModelElement[] configuredInterfaceElements = model.GetInterfacesOfVisaType(this.VisaIntfTypeString);  // EOS: unused, removed.
                var availableInterfaces = hwconfig.GetAvailableInterfaces().Where(i => i is ModelInterfaceSample).Select(i => i as ModelInterfaceSample);
                // TCPIP only configures 1 interface by default, but this pattern supports any number
                unconfigured = (from i in availableInterfaces
                                where model.FindEquivalentElement(i) == null
                                select i);

                hwconfig.UninitializeDll();
            }
            return(unconfigured);
        }
Пример #10
0
 private void FindAndUpdateDevices(IConfigDll hwconfig, List<ModelElement> discoveredList, ModelInterfaceSample intfc, AceModelRestricted model)
 {
     var connectedDevices = hwconfig.GetAvailableDevices(intfc);
     discoveredList.AddRange(connectedDevices);
 }