Example #1
0
 private static void WriteDigValues(IIoDeviceRunTarget ioDevice, IList <int> ids, IList <bool> values)
 {
     for (var i = 0; i < ids.Count; i++)
     {
         ioDevice.SetDigitalValue(ids[i], values[i]);
     }
 }
Example #2
0
        private static void Remap(IIoDeviceRunTarget ioDevice, RemapTagsParameter parameter,
                                  RemapTagsResult result)
        {
            bool readOnly = !parameter.DigWriteIds.Any() && !parameter.NumWriteIds.Any();

            if (readOnly)
            {
                ioDevice.EnterReadLock();
            }
            else
            {
                ioDevice.EnterWriteLock();
            }
            try {
                if (!readOnly)
                {
                    WriteDigValues(ioDevice, parameter.DigWriteIds, parameter.DigWriteValues);
                    WriteNumValues(ioDevice, parameter.NumWriteIds, parameter.NumWriteValues);
                }

                result.DigReadValues = ReadDigValues(ioDevice, parameter.DigReadIds);
                result.NumReadValues = ReadNumValues(ioDevice, parameter.NumReadIds);
                result.Notifications = GetNotifications(ioDevice.Reporter.Notifications);
            } finally {
                if (readOnly)
                {
                    ioDevice.ExitReadLock();
                }
                else
                {
                    ioDevice.ExitWriteLock();
                }
            }
        }
Example #3
0
 private static void WriteNumValues(IIoDeviceRunTarget ioDevice, IList <int> ids, IList <double> values)
 {
     for (var i = 0; i < ids.Count; i++)
     {
         ioDevice.SetNumericValue(ids[i], values[i]);
     }
 }
Example #4
0
 protected override void EstablishContext()
 {
     base.EstablishContext();
     TimeService = new Mock <ITimeService>();
     Target      = Factory.Create(TimeService.Object, new IoDevice {
         Type = "Type"
     });
 }
Example #5
0
        private static double?[] ReadNumValues(IIoDeviceRunTarget ioDevice, IList <int> ids)
        {
            var values = new double?[ids.Count];

            for (var i = 0; i < ids.Count; i++)
            {
                values[i] = ioDevice.GetNumericValue(ids[i]);
            }
            return(values);
        }
Example #6
0
        private static bool?[] ReadDigValues(IIoDeviceRunTarget ioDevice, IList <int> ids)
        {
            var values = new bool?[ids.Count];

            for (var i = 0; i < ids.Count; i++)
            {
                values[i] = ioDevice.GetDigitalValue(ids[i]);
            }
            return(values);
        }
 protected override void EstablishContext()
 {
     base.EstablishContext();
     IoDeviceWrapper        = new Mock <IIoDeviceWrapper>();
     IoDeviceWrapperFactory = new Mock <IIoDeviceWrapperFactory>();
     IoDeviceWrapperFactory.Setup(f => f.Create()).Returns(IoDeviceWrapper.Object);
     IoDevice = new PHmiModel.Entities.IoDevice
     {
         Name    = "IoDeviceRunTargetName",
         Options = IoDeviceOptions,
         Type    = string.Format("{0}{1}{2}", IoDeviceFolder, PHmiConstants.PHmiIoDeviceSeparator, IoDeviceFile)
     };
     DigitalTag = new DigTag
     {
         Id      = 1,
         Device  = "M0",
         CanRead = true
     };
     IoDevice.DigTags.Add(DigitalTag);
     WriteOnlyDigitalTag = new DigTag
     {
         Id      = 2,
         Device  = "M1",
         CanRead = false
     };
     IoDevice.DigTags.Add(WriteOnlyDigitalTag);
     NumericTag = new NumTag
     {
         Id         = 1,
         Device     = "D0",
         NumTagType = new NumTagType {
             Name = "Int32"
         },
         CanRead = true
     };
     IoDevice.NumTags.Add(NumericTag);
     WriteOnlyNumericTag = new NumTag
     {
         Id         = 2,
         Device     = "D1",
         NumTagType = new NumTagType {
             Name = "Int16"
         },
         CanRead = false
     };
     IoDevice.NumTags.Add(WriteOnlyNumericTag);
     Reporter          = new Mock <INotificationReporter>();
     IoDeviceRunTarget = new IoDeviceRunTarget(IoDevice, IoDeviceWrapperFactory.Object, Reporter.Object);
     DigitalTagValue   = true;
     NumericTagValue   = new Random().Next();
     IoDeviceWrapper
     .Setup(w => w.Read(It.IsAny <ReadParameter[]>()))
     .Returns(new object[] { DigitalTagValue, NumericTagValue });
 }
 protected override void EstablishContext()
 {
     base.EstablishContext();
     IoDeviceWrapper        = new Mock <IIoDeviceWrapper>();
     IoDeviceWrapperFactory = new Mock <IIoDeviceWrapperFactory>();
     IoDeviceWrapperFactory.Setup(f => f.Create()).Returns(IoDeviceWrapper.Object);
     IoDevice = new io_devices
     {
         name    = "IoDeviceRunTargetName",
         options = IoDeviceOptions,
         type    = string.Format("{0}{1}{2}", IoDeviceFolder, PHmiConstants.PHmiIoDeviceSeparator, IoDeviceFile)
     };
     DigitalTag = new dig_tags
     {
         id       = 1,
         device   = "M0",
         can_read = true
     };
     IoDevice.dig_tags.Add(DigitalTag);
     WriteOnlyDigitalTag = new dig_tags
     {
         id       = 2,
         device   = "M1",
         can_read = false
     };
     IoDevice.dig_tags.Add(WriteOnlyDigitalTag);
     NumericTag = new num_tags
     {
         id            = 1,
         device        = "D0",
         num_tag_types = new num_tag_types {
             name = "Int32"
         },
         can_read = true
     };
     IoDevice.num_tags.Add(NumericTag);
     WriteOnlyNumericTag = new num_tags
     {
         id            = 2,
         device        = "D1",
         num_tag_types = new num_tag_types {
             name = "Int16"
         },
         can_read = false
     };
     IoDevice.num_tags.Add(WriteOnlyNumericTag);
     Reporter          = new Mock <INotificationReporter>();
     IoDeviceRunTarget = new IoDeviceRunTarget(IoDevice, IoDeviceWrapperFactory.Object, Reporter.Object);
     DigitalTagValue   = true;
     NumericTagValue   = new Random().Next();
     IoDeviceWrapper
     .Setup(w => w.Read(It.IsAny <ReadParameter[]>()))
     .Returns(new object[] { DigitalTagValue, NumericTagValue });
 }
Example #9
0
 private void StartIoDevices()
 {
     foreach (IoDevice ioDevice in _context.Get <IoDevice>().ToArray())
     {
         IIoDeviceRunTarget ioDeviceRunTarget =
             _ioDeviceRunTargetFactory.Create(_timeService, ioDevice);
         IoDeviceRunTargets.Add(ioDevice.Id, ioDeviceRunTarget);
         ICyclicRunner runner = _cyclicRunnerFactory.Create(ioDeviceRunTarget);
         _ioDeviceRunners.Add(
             new Tuple <IRunner, string, IIoDeviceRunTarget>(runner, ioDevice.Name, ioDeviceRunTarget));
         runner.Start();
         _reporter.Report(string.Format(Res.IoDeviceStartedMessage, ioDevice.Name));
     }
 }
Example #10
0
 private void UpdateAlarmDigitalValues(IEnumerable <Tuple <int, Tuple <int, int>[]> > ioDeviceGroups)
 {
     foreach (var g in ioDeviceGroups)
     {
         IIoDeviceRunTarget ioDev = _project.IoDeviceRunTargets[g.Item1];
         ioDev.EnterReadLock();
         try {
             foreach (var t in g.Item2)
             {
                 _alarmDigitalValues[t.Item2].Value = ioDev.GetDigitalValue(t.Item1);
             }
         } finally {
             ioDev.ExitReadLock();
         }
     }
 }
Example #11
0
        public RemapTagsResult[] RemapTags(RemapTagsParameter[] parameters)
        {
            if (NotValid())
            {
                return(null);
            }
            var results = new RemapTagsResult[parameters.Length];

            for (var parameterIndex = 0; parameterIndex < parameters.Length; parameterIndex++)
            {
                RemapTagsParameter parameter = parameters[parameterIndex];
                var result = new RemapTagsResult();
                results[parameterIndex] = result;
                IIoDeviceRunTarget ioDevice = _project.IoDeviceRunTargets[parameter.IoDeviceId];
                Remap(ioDevice, parameter, result);
            }

            return(results);
        }
Example #12
0
 private static void WriteNumValues(IIoDeviceRunTarget ioDevice, IList<int> ids, IList<double> values)
 {
     for (var i = 0; i < ids.Count; i++)
     {
         ioDevice.SetNumericValue(ids[i], values[i]);
     }
 }
Example #13
0
 private static void WriteDigValues(IIoDeviceRunTarget ioDevice, IList<int> ids, IList<bool> values)
 {
     for (var i = 0; i < ids.Count; i++)
     {
         ioDevice.SetDigitalValue(ids[i], values[i]);
     }
 }
Example #14
0
 private static void Remap(IIoDeviceRunTarget ioDevice, RemapTagsParameter parameter, RemapTagsResult result)
 {
     var readOnly = !parameter.DigWriteIds.Any() && !parameter.NumWriteIds.Any();
     if (readOnly)
         ioDevice.EnterReadLock();
     else
         ioDevice.EnterWriteLock();
     try
     {
         if (!readOnly)
         {
             WriteDigValues(ioDevice, parameter.DigWriteIds, parameter.DigWriteValues);
             WriteNumValues(ioDevice, parameter.NumWriteIds, parameter.NumWriteValues);
         }
         result.DigReadValues = ReadDigValues(ioDevice, parameter.DigReadIds);
         result.NumReadValues = ReadNumValues(ioDevice, parameter.NumReadIds);
         result.Notifications = GetNotifications(ioDevice.Reporter.Notifications);
     }
     finally
     {
         if (readOnly)
             ioDevice.ExitReadLock();
         else
             ioDevice.ExitWriteLock();
     }
 }
Example #15
0
 private static double?[] ReadNumValues(IIoDeviceRunTarget ioDevice, IList<int> ids)
 {
     var values = new double?[ids.Count];
     for (var i = 0; i < ids.Count; i++)
     {
         values[i] = ioDevice.GetNumericValue(ids[i]);
     }
     return values;
 }
Example #16
0
 private static bool?[] ReadDigValues(IIoDeviceRunTarget ioDevice, IList<int> ids)
 {
     var values = new bool?[ids.Count];
     for (var i = 0; i < ids.Count; i++)
     {
         values[i] = ioDevice.GetDigitalValue(ids[i]);
     }
     return values;
 }
Example #17
0
 protected override void EstablishContext()
 {
     base.EstablishContext();
     IoDeviceWrapper = new Mock<IIoDeviceWrapper>();
     IoDeviceWrapperFactory = new Mock<IIoDeviceWrapperFactory>();
     IoDeviceWrapperFactory.Setup(f => f.Create()).Returns(IoDeviceWrapper.Object);
     IoDevice = new PHmiModel.Entities.IoDevice
         {
             Name = "IoDeviceRunTargetName",
             Options = IoDeviceOptions,
             Type = string.Format("{0}{1}{2}", IoDeviceFolder, PHmiConstants.PHmiIoDeviceSeparator, IoDeviceFile)
         };
     DigitalTag = new DigTag
         {
             Id = 1,
             Device = "M0",
             CanRead = true
         };
     IoDevice.DigTags.Add(DigitalTag);
     WriteOnlyDigitalTag = new DigTag
         {
             Id = 2,
             Device = "M1",
             CanRead = false
         };
     IoDevice.DigTags.Add(WriteOnlyDigitalTag);
     NumericTag = new NumTag
         {
             Id = 1,
             Device = "D0",
             NumTagType = new NumTagType {Name = "Int32"},
             CanRead = true
         };
     IoDevice.NumTags.Add(NumericTag);
     WriteOnlyNumericTag = new NumTag
         {
             Id = 2,
             Device = "D1",
             NumTagType = new NumTagType {Name = "Int16"},
             CanRead = false
         };
     IoDevice.NumTags.Add(WriteOnlyNumericTag);
     Reporter = new Mock<INotificationReporter>();
     IoDeviceRunTarget = new IoDeviceRunTarget(IoDevice, IoDeviceWrapperFactory.Object, Reporter.Object);
     DigitalTagValue = true;
     NumericTagValue = new Random().Next();
     IoDeviceWrapper
         .Setup(w => w.Read(It.IsAny<ReadParameter[]>()))
         .Returns(new object[] { DigitalTagValue, NumericTagValue });
 }
 protected override void EstablishContext()
 {
     base.EstablishContext();
     TimeService = new Mock<ITimeService>();
     Target = Factory.Create(TimeService.Object, new PHmiModel.Entities.IoDevice { Type = "Type" });
 }
 protected override void EstablishContext()
 {
     base.EstablishContext();
     TimeService = new Mock<ITimeService>();
     Target = Factory.Create(TimeService.Object, new io_devices { type = "Type" });
 }
Example #20
0
 protected override void EstablishContext()
 {
     base.EstablishContext();
     IoDeviceWrapper = new Mock<IIoDeviceWrapper>();
     IoDeviceWrapperFactory = new Mock<IIoDeviceWrapperFactory>();
     IoDeviceWrapperFactory.Setup(f => f.Create()).Returns(IoDeviceWrapper.Object);
     IoDevice = new io_devices
         {
             name = "IoDeviceRunTargetName",
             options = IoDeviceOptions,
             type = string.Format("{0}{1}{2}", IoDeviceFolder, PHmiConstants.PHmiIoDeviceSeparator, IoDeviceFile)
         };
     DigitalTag = new dig_tags
         {
             id = 1,
             device = "M0",
             can_read = true
         };
     IoDevice.dig_tags.Add(DigitalTag);
     WriteOnlyDigitalTag = new dig_tags
         {
             id = 2,
             device = "M1",
             can_read = false
         };
     IoDevice.dig_tags.Add(WriteOnlyDigitalTag);
     NumericTag = new num_tags
         {
             id = 1,
             device = "D0",
             num_tag_types = new num_tag_types {name = "Int32"},
             can_read = true
         };
     IoDevice.num_tags.Add(NumericTag);
     WriteOnlyNumericTag = new num_tags
         {
             id = 2,
             device = "D1",
             num_tag_types = new num_tag_types {name = "Int16"},
             can_read = false
         };
     IoDevice.num_tags.Add(WriteOnlyNumericTag);
     Reporter = new Mock<INotificationReporter>();
     IoDeviceRunTarget = new IoDeviceRunTarget(IoDevice, IoDeviceWrapperFactory.Object, Reporter.Object);
     DigitalTagValue = true;
     NumericTagValue = new Random().Next();
     IoDeviceWrapper
         .Setup(w => w.Read(It.IsAny<ReadParameter[]>()))
         .Returns(new object[] { DigitalTagValue, NumericTagValue });
 }