private ModelInterfaceSample ConstructInterface(XElement intfcElement)
        {
            ModelInterfaceSample intfc = null;
            var connectionTimeoutAttr = intfcElement.Attribute(Consts.CONNECTION_TIMEOUT_ATTR);
            var busAddressAttr = intfcElement.Attribute(Consts.BUS_ADDRESS_ATTR);
            var visaNameAttr = intfcElement.Attribute(Consts.VISA_NAME_ATTR);
            var siclNameAttr = intfcElement.Attribute(Consts.SICL_NAME_ATTR);
            var luAttr = intfcElement.Attribute(Consts.LU_ATTR);
            var autoDiscoverAttr = intfcElement.Attribute(Consts.AUTO_DISCOVER);
            if (connectionTimeoutAttr != null
                && busAddressAttr != null
                && visaNameAttr != null
                && siclNameAttr != null
                && luAttr != null)
            {
                int connectionTimeout, busAddress, lu;
                intfc = new ModelInterfaceSample();
                intfc.VisaInterfaceId = visaNameAttr.Value;
                intfc.SiclInterfaceId = siclNameAttr.Value;
                intfc.ConnectionTimeout = int.TryParse(connectionTimeoutAttr.Value, out connectionTimeout) ? connectionTimeout : 5000;
                intfc.BusAddress = int.TryParse(busAddressAttr.Value, out busAddress) ? busAddress : 0;
                intfc.LogicalUnit = int.TryParse(luAttr.Value, out lu) ? luAttr.Value : "100";

                bool autoDiscover = false;
                autoDiscover = autoDiscoverAttr != null && bool.TryParse(autoDiscoverAttr.Value, out autoDiscover) ? autoDiscover : false;
                intfc.AutoDiscoverDevices = autoDiscover;
            }
            return intfc;
        }
Example #2
0
        public override ModelElement MakeCopy()
        {
            var intfc = new ModelInterfaceSample();

            CopyDataTo(intfc);
            return(intfc);
        }
 public IEnumerable<ModelDeviceSample> GetConnectedInstruments(ModelInterfaceSample intfc)
 {
     var availableInstruments = Enumerable.Empty<ModelDeviceSample>();
     Monitor.Enter(_modelList);
     availableInstruments = _modelList.Where(e => e is ModelDeviceSample && ((ModelDeviceSample)e).Parent.IsEquivalent(intfc))
         .Select(e => (ModelDeviceSample)e);
     Monitor.Exit(_modelList);
     return availableInstruments;
 }
 public IEnumerable<ModelDeviceSample> GetConnectedInstruments(ModelInterfaceSample intfc)
 {
     var availableInstruments = Enumerable.Empty<ModelDeviceSample>();
     Monitor.Enter(_modelList);
     availableInstruments = _modelList.Where(e => e is ModelDeviceSample && ((ModelDeviceSample)e).Parent.IsEquivalent(intfc))
         .Select(e => (ModelDeviceSample)e);
     Monitor.Exit(_modelList);
     return availableInstruments;
 }
        private bool IsDevicePresentProc(ModelDeviceSample deviceToCheck, ModelInterfaceSample parentInterface)
        {
            bool isPresent  = false;
            var  hwDetector = GenerateHardwareDetector();

            if (hwDetector != null)
            {
                var availableDevices = hwDetector.GetConnectedInstruments(parentInterface);
                isPresent = deviceToCheck.IsDevicePresent(availableDevices);
            }
            return(isPresent);
        }
 private void VerfiyInterface(ModelInterfaceSample intfc)
 {
     ModelInterface[] availableInterfaces = GetAvailableInterfaces();
     if (IsInterfacePresentProc(intfc, availableInterfaces) ||
         intfc.StaticallyDefined)
     {
         intfc.Verified = true;
         intfc.Failed   = false;
     }
     else
     {
         intfc.FailedReason = AgentKeys.FailedReason_InterfaceNotPresent;
     }
 }
Example #7
0
        public static bool IsInterfacePresent(this ModelInterfaceSample interfaceToCheck, IEnumerable <ModelInterface> availableInterfaces)
        {
            bool isPresent = false;

            foreach (var availableInterface in availableInterfaces)
            {
                var specificInterface = availableInterface as ModelInterfaceSample;
                if (specificInterface != null &&
                    specificInterface.IsEquivalent(interfaceToCheck))
                {
                    isPresent = true;
                    break;
                }
            }
            return(isPresent);
        }
Example #8
0
        private ModelElement GenerateAddingDevice(AceModelRestricted model)
        {
            var intfc = model.FindElementByVisaName(Consts.DEFAULT_INTFC_VISANAME) as ModelInterfaceSample;

            if (intfc == null)
            {
                intfc = new ModelInterfaceSample();
                intfc.VisaInterfaceId = Consts.DEFAULT_INTFC_VISANAME;
            }
            var device = new ModelDeviceSample();

            device.Parent            = intfc;
            device.ParentId          = intfc.PersistentId;
            device.StaticallyDefined = true;
            return(device);
        }
Example #9
0
        private ModelElement GenerateAddingInterface(AceModelRestricted model)
        {
            var intfc            = new ModelInterfaceSample();
            var activeInterfaces = model.GetInterfaces().Where(i => i.AgentName == AgentId).Select(e => e as ModelInterfaceSample)
                                   .OrderBy(i => i.VisaInterfaceId.ToUpper(), new SampleIOAgentComparer(Consts.VISA_PRIFIX));
            var latestVisaInterface = activeInterfaces.LastOrDefault();
            var visaIndex           = latestVisaInterface.VisaInterfaceId.ToUpper().GetIndex(Consts.VISA_PRIFIX);

            var siclInterfaces      = activeInterfaces.OrderBy(i => i.SiclInterfaceId, new SampleIOAgentComparer(Consts.SICL_PRIFIX));
            var latestSiclInterface = siclInterfaces.LastOrDefault();
            var siclIndex           = (latestSiclInterface != null) ? latestVisaInterface.SiclInterfaceId.ToLower().GetIndex(Consts.SICL_PRIFIX) : -1;

            visaIndex++;
            siclIndex = siclIndex >= 0 ? ++siclIndex : 1;
            var visaIntfID = Consts.VISA_PRIFIX.GenerateNewPrifix(visaIndex);
            var siclIntfID = Consts.SICL_PRIFIX.GenerateNewPrifix(siclIndex);

            var luInterfaces = activeInterfaces.OrderBy(i => i.LogicalUnit, new LUComparer());
            var latestLUIntf = luInterfaces.LastOrDefault();
            var lu           = Consts.DEFAULT_LU;

            if (latestLUIntf != null)
            {
                int luValue;
                if (int.TryParse(latestLUIntf.LogicalUnit, out luValue))
                {
                    luValue++;
                    lu = luValue.ToString();
                }
                else
                {
                    lu = Consts.DEFAULT_LU;
                }
            }
            else
            {
                lu = Consts.DEFAULT_LU;
            }
            intfc.VisaInterfaceId   = visaIntfID;
            intfc.SiclInterfaceId   = siclIntfID;
            intfc.LogicalUnit       = lu;
            intfc.StaticallyDefined = true;
            return(intfc);
        }
Example #10
0
        public ModelInterface ReconstituteInterface(InterfaceDataRecord raw)
        {
            if (raw == null)
            {
                return(null);
            }
            if (!CanReconstituteThis(raw))
            {
                return(null);
            }

            var intfc = new ModelInterfaceSample();

            ExtractCommonInterfacePropertiesFromNVPairs(raw, intfc);
            intfc.ConnectionTimeout = raw.GetInt(Consts.CONNECTION_TIMEOUT_KEY);
            intfc.BusAddress        = raw.GetInt(Consts.BUS_ADDRESS_KEY);
            intfc.Dirty             = false;

            return(intfc);
        }
Example #11
0
 private static void AddInfoToInterface(InterfaceDataRecord raw, ModelInterfaceSample specificIntfc)
 {
     raw.AddProperty(Consts.CONNECTION_TIMEOUT_KEY, specificIntfc.ConnectionTimeout.ToString());
     raw.AddProperty(Consts.BUS_ADDRESS_KEY, specificIntfc.BusAddress.ToString());
 }
Example #12
0
        private void FindAndUpdateDevices(IConfigDll hwconfig, List <ModelElement> discoveredList, ModelInterfaceSample intfc, AceModelRestricted model)
        {
            var connectedDevices = hwconfig.GetAvailableDevices(intfc);

            discoveredList.AddRange(connectedDevices);
        }
        public void VerifyElementTestDevice()
        {
            var intfc1 = new ModelInterfaceSample { VisaInterfaceId = "SAMP0", SiclInterfaceId = "samp", LogicalUnit = "100" };
            var instrument1 = new ModelDeviceSample
            {
                Manufacturer = "KT",
                ModelNumber = "DEV001",
                SerialNumber = "X01234",
                FirmwareRevision = "1.0.0.1",
                IPAddress = "192.168.56.128",
                DeviceName = "inst0"
            };
            instrument1.Parent = intfc1;
            instrument1.ParentId = intfc1.PersistentId;
            var hwconfig1 = GenerateHwConfig();
            hwconfig1.VerifyElement(instrument1);
            Assert.IsTrue(!instrument1.Failed);
            Assert.IsTrue(instrument1.Verified);

            var intfc2 = new ModelInterfaceSample { VisaInterfaceId = "SAMP1", SiclInterfaceId = "samp1", LogicalUnit = "101" };
            var instrument2 = new ModelDeviceSample
            {
                Manufacturer = "KT",
                ModelNumber = "DEV001",
                SerialNumber = "X01234",
                FirmwareRevision = "1.0.0.1",
                IPAddress = "192.168.56.130",
                DeviceName = "inst0"
            };
            instrument2.Parent = intfc2;
            instrument2.ParentId = intfc2.PersistentId;
            var hwconfig2 = GenerateHwConfig();
            hwconfig2.VerifyElement(instrument2);
            Assert.IsTrue(instrument2.Failed);
            Assert.IsTrue(!instrument2.Verified);
        }
 private ModelElement GenerateAddingDevice(AceModelRestricted model)
 {
     var intfc = model.FindElementByVisaName(Consts.DEFAULT_INTFC_VISANAME) as ModelInterfaceSample;
     if (intfc == null)
     {
         intfc = new ModelInterfaceSample();
         intfc.VisaInterfaceId = Consts.DEFAULT_INTFC_VISANAME;
     }
     var device = new ModelDeviceSample();
     device.Parent = intfc;
     device.ParentId = intfc.PersistentId;
     device.StaticallyDefined = true;
     return device;
 }
        public ModelInterface ReconstituteInterface(InterfaceDataRecord raw)
        {
            if (raw == null) return null;
            if (!CanReconstituteThis(raw)) return null;

            var intfc = new ModelInterfaceSample();
            ExtractCommonInterfacePropertiesFromNVPairs(raw, intfc);
            intfc.ConnectionTimeout = raw.GetInt(Consts.CONNECTION_TIMEOUT_KEY);
            intfc.BusAddress = raw.GetInt(Consts.BUS_ADDRESS_KEY);
            intfc.Dirty = false;

            return intfc;
        }
 private static void AddInfoToInterface(InterfaceDataRecord raw, ModelInterfaceSample specificIntfc)
 {
     raw.AddProperty(Consts.CONNECTION_TIMEOUT_KEY, specificIntfc.ConnectionTimeout.ToString());
     raw.AddProperty(Consts.BUS_ADDRESS_KEY, specificIntfc.BusAddress.ToString());
 }
 private static ModelInterfaceSample GenerateSampleInterface(string visaID, string siclID, string lu, bool staticDefailed = false)
 {
     var sampleInterface = new ModelInterfaceSample();
     sampleInterface.VisaInterfaceId = visaID;
     sampleInterface.SiclInterfaceId = siclID;
     sampleInterface.LogicalUnit = lu;
     sampleInterface.StaticallyDefined = staticDefailed;
     return sampleInterface;
 }
        public void GetAddingElementSingleInterfaceTest()
        {
            var sampleInterface = new ModelInterfaceSample();
            sampleInterface.VisaInterfaceId = "SAMP0";
            sampleInterface.SiclInterfaceId = "samp";
            sampleInterface.LogicalUnit = "100";
            var model = GenerateModel(sampleInterface);
            var intfc = GenerateNewSampleInterface(model);

            Assert.IsNotNull(intfc);
            Assert.IsTrue(intfc.VisaInterfaceId == "SAMP1");
            Assert.IsTrue(intfc.SiclInterfaceId == "samp1");
            Assert.IsTrue(intfc.LogicalUnit == "101");
        }
        public void GetAddingElementMultipleInterfaceTest()
        {
            var sampleInterface1 = new ModelInterfaceSample();
            sampleInterface1.VisaInterfaceId = "SAMP0";
            sampleInterface1.SiclInterfaceId = "samp";
            sampleInterface1.LogicalUnit = "100";
            var sampleInterface2 = new ModelInterfaceSample();
            sampleInterface2.VisaInterfaceId = "SAMP1";
            sampleInterface2.SiclInterfaceId = "samp1";
            sampleInterface2.LogicalUnit = "101";

            var model = GenerateModel(sampleInterface1, sampleInterface2);
            var intfc = GenerateNewSampleInterface(model);

            Assert.IsNotNull(intfc);
            Assert.IsTrue(intfc.VisaInterfaceId == "SAMP2");
            Assert.IsTrue(intfc.SiclInterfaceId == "samp2");
            Assert.IsTrue(intfc.LogicalUnit == "102");
        }
 public override ModelElement MakeCopy()
 {
     var intfc = new ModelInterfaceSample();
     CopyDataTo(intfc);
     return intfc;
 }
        private ModelElement GenerateAddingInterface(AceModelRestricted model)
        {
            var intfc = new ModelInterfaceSample();
            var activeInterfaces = model.GetInterfaces().Where(i => i.AgentName == AgentId).Select(e => e as ModelInterfaceSample)
                .OrderBy(i => i.VisaInterfaceId.ToUpper(), new SampleIOAgentComparer(Consts.VISA_PRIFIX));
            var latestVisaInterface = activeInterfaces.LastOrDefault();
            var visaIndex = latestVisaInterface.VisaInterfaceId.ToUpper().GetIndex(Consts.VISA_PRIFIX);

            var siclInterfaces = activeInterfaces.OrderBy(i => i.SiclInterfaceId, new SampleIOAgentComparer(Consts.SICL_PRIFIX));
            var latestSiclInterface = siclInterfaces.LastOrDefault();
            var siclIndex = (latestSiclInterface != null) ? latestVisaInterface.SiclInterfaceId.ToLower().GetIndex(Consts.SICL_PRIFIX) : -1;
            visaIndex++;
            siclIndex = siclIndex >= 0 ? ++siclIndex : 1;
            var visaIntfID = Consts.VISA_PRIFIX.GenerateNewPrifix(visaIndex);
            var siclIntfID = Consts.SICL_PRIFIX.GenerateNewPrifix(siclIndex);

            var luInterfaces = activeInterfaces.OrderBy(i => i.LogicalUnit, new LUComparer());
            var latestLUIntf = luInterfaces.LastOrDefault();
            var lu = Consts.DEFAULT_LU;
            if (latestLUIntf != null)
            {
                int luValue;
                if (int.TryParse(latestLUIntf.LogicalUnit, out luValue))
                {
                    luValue++;
                    lu = luValue.ToString();
                }
                else
                {
                    lu = Consts.DEFAULT_LU;
                }
            }
            else
            {
                lu = Consts.DEFAULT_LU;
            }
            intfc.VisaInterfaceId = visaIntfID;
            intfc.SiclInterfaceId = siclIntfID;
            intfc.LogicalUnit = lu;
            intfc.StaticallyDefined = true;
            return intfc;
        }
 private void VerfiyInterface(ModelInterfaceSample intfc)
 {
     ModelInterface[] availableInterfaces = GetAvailableInterfaces();
     if (IsInterfacePresentProc(intfc, availableInterfaces)
         || intfc.StaticallyDefined)
     {
         intfc.Verified = true;
         intfc.Failed = false;
     }
     else
     {
         intfc.FailedReason = AgentKeys.FailedReason_InterfaceNotPresent;
     }
 }
 private bool IsInterfacePresentProc(ModelInterfaceSample interfaceToCheck, ModelInterface[] availableInterfaces)
 {
     return(interfaceToCheck.IsInterfacePresent(availableInterfaces));
 }
        public void VerifyElementTestInterface()
        {
            var intfc1 = new ModelInterfaceSample { VisaInterfaceId = "SAMP0", SiclInterfaceId = "samp", LogicalUnit = "100" };
            var hwconfig1 = GenerateHwConfig();
            hwconfig1.VerifyElement(intfc1);
            Assert.IsTrue(!intfc1.Failed);
            Assert.IsTrue(intfc1.Verified);

            var intfc2 = new ModelInterfaceSample { VisaInterfaceId = "SAMP1", SiclInterfaceId = "samp1", LogicalUnit = "101" };
            var hwconfig2 = GenerateHwConfig();
            hwconfig2.VerifyElement(intfc2);
            Assert.IsTrue(intfc2.Failed);
            Assert.IsTrue(!intfc2.Verified);
        }
 private bool IsDevicePresentProc(ModelDeviceSample deviceToCheck, ModelInterfaceSample parentInterface)
 {
     bool isPresent = false;
     var hwDetector = GenerateHardwareDetector();
     if (hwDetector != null)
     {
         var availableDevices = hwDetector.GetConnectedInstruments(parentInterface);
         isPresent = deviceToCheck.IsDevicePresent(availableDevices);
     }
     return isPresent;
 }
 private void FindAndUpdateDevices(IConfigDll hwconfig, List<ModelElement> discoveredList, ModelInterfaceSample intfc, AceModelRestricted model)
 {
     var connectedDevices = hwconfig.GetAvailableDevices(intfc);
     discoveredList.AddRange(connectedDevices);
 }
        private ModelInterfaceSample ConstructInterface(XElement intfcElement)
        {
            ModelInterfaceSample intfc = null;
            var connectionTimeoutAttr = intfcElement.Attribute(Consts.CONNECTION_TIMEOUT_ATTR);
            var busAddressAttr = intfcElement.Attribute(Consts.BUS_ADDRESS_ATTR);
            var visaNameAttr = intfcElement.Attribute(Consts.VISA_NAME_ATTR);
            var siclNameAttr = intfcElement.Attribute(Consts.SICL_NAME_ATTR);
            var luAttr = intfcElement.Attribute(Consts.LU_ATTR);
            var autoDiscoverAttr = intfcElement.Attribute(Consts.AUTO_DISCOVER);
            if (connectionTimeoutAttr != null
                && busAddressAttr != null
                && visaNameAttr != null
                && siclNameAttr != null
                && luAttr != null)
            {
                int connectionTimeout, busAddress, lu;
                intfc = new ModelInterfaceSample();
                intfc.VisaInterfaceId = visaNameAttr.Value;
                intfc.SiclInterfaceId = siclNameAttr.Value;
                intfc.ConnectionTimeout = int.TryParse(connectionTimeoutAttr.Value, out connectionTimeout) ? connectionTimeout : 5000;
                intfc.BusAddress = int.TryParse(busAddressAttr.Value, out busAddress) ? busAddress : 0;
                intfc.LogicalUnit = int.TryParse(luAttr.Value, out lu) ? luAttr.Value : "100";

                bool autoDiscover = false;
                autoDiscover = autoDiscoverAttr != null && bool.TryParse(autoDiscoverAttr.Value, out autoDiscover) ? autoDiscover : false;
                intfc.AutoDiscoverDevices = autoDiscover;
            }
            return intfc;
        }
 private bool IsInterfacePresentProc(ModelInterfaceSample interfaceToCheck, ModelInterface[] availableInterfaces)
 {
     return interfaceToCheck.IsInterfacePresent(availableInterfaces);
 }