Exemplo n.º 1
0
        public IoDeviceRunTarget(io_devices ioDevice, IIoDeviceWrapperFactory wrapperFactory, INotificationReporter reporter)
        {
            _reporter = reporter;
            Name = string.Format(Res.IoDeviceWithName, ioDevice.name);
            _filePath = GetFilePath(ioDevice.type);
            _options = ioDevice.options;
            _wrapperFactory = wrapperFactory;

            var digReadParameters = new List<ReadParameter>();
            var digReadValueHolders = new List<ITagValueHolder>();
            foreach (var t in ioDevice.dig_tags)
            {
                var holder = new DigTagValueHolder(t);
                _digValueHolders.Add(t.id, holder);
                if (t.can_read)
                {
                    digReadValueHolders.Add(holder);
                    digReadParameters.Add(new ReadParameter(t.device, typeof(bool)));
                }
            }
            var numReadParameters = new List<ReadParameter>();
            var numReadValueHolders = new List<ITagValueHolder>();
            foreach (var t in ioDevice.num_tags)
            {
                var holder = new NumTagValueHolder(t);
                _numValueHolders.Add(t.id, holder);
                if (t.can_read)
                {
                    numReadValueHolders.Add(holder);
                    numReadParameters.Add(new ReadParameter(t.device, t.TagType));
                }
            }
            _readParameters = digReadParameters.Concat(numReadParameters).ToArray();
            _readValueHolders = digReadValueHolders.Concat(numReadValueHolders).ToArray();
        }
Exemplo n.º 2
0
 public IIoDeviceRunTarget Create(ITimeService timeService, io_devices ioDevice)
 {
     return new IoDeviceRunTarget(
         ioDevice,
         new IoDeviceWrapperFactory(string.Format("{0} domain", ioDevice.name)),
         new NotificationReporter(timeService){LifeTime = TimeSpan.FromTicks(0)});
 }
Exemplo n.º 3
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 });
 }
Exemplo n.º 4
0
 /// <summary>
 /// Create a new io_devices object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="name">Initial value of the name property.</param>
 /// <param name="type">Initial value of the type property.</param>
 public static io_devices Createio_devices(global::System.Int32 id, global::System.String name, global::System.String type)
 {
     io_devices io_devices = new io_devices();
     io_devices.id = id;
     io_devices.name = name;
     io_devices.type = type;
     return io_devices;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the io_devices EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToio_devices(io_devices io_devices)
 {
     base.AddObject("io_devices", io_devices);
 }
Exemplo n.º 6
0
            protected override void EstablishContext()
            {
                base.EstablishContext();
                IoDevice = new io_devices
                    {
                        name = "IoDevice",
                        id = 1
                    };
                IoDevices = new EnumerableQuery<io_devices>(new [] {IoDevice});
                Context.Setup(context => context.Get<io_devices>()).Returns(IoDevices);

                IoDeviceRunTarget = new Mock<IIoDeviceRunTarget>();
                IoDeviceRunTargetFactory.Setup(f => f.Create(TimeService.Object, IoDevice))
                    .Returns(IoDeviceRunTarget.Object);
                CyclicRunner = new Mock<ICyclicRunner>();
                CyclicRunnerFactory.Setup(f => f.Create(IoDeviceRunTarget.Object)).Returns(CyclicRunner.Object);
            }