Exemplo n.º 1
0
        public void Test_WriteAndReadDefaultString()
        {
            _tagController.WriteTag(_defaultStringTestTag, "123456789abcdefghijklmnopqrstuvwxyz").Wait();

            _tagListener.ReadTagSynchronously(_defaultStringTestTag);
            _defaultStringTestTag.Value.ToString().Should().Be("123456789abcdefghijklmnopqrstuvwxyz");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Resets the alarm manager of the module this controller is in.
        /// </summary>
        public void ResetModuleAlarms()
        {
            var resetAlarmsTag = new Tag(
                TagName.AlarmManager(parent: null).AlarmCommand(),
                TagName.Global(),
                "INT");

            _tagController.WriteTag(resetAlarmsTag, (short)StandardAlarmCommands.ResetAll);
        }
Exemplo n.º 3
0
        public void SetChannel(string fbName, string scope, string typeName)
        {
            _channelToPlcTag = new Tag(fbName + "." + UdtDataFieldName, scope, typeName);

            _dataChannelStateTag = new Tag(fbName + "." + UdtHandshakeFieldName, scope, "INT");

            // initialize DataChannel on PLC side
            _tagController.WriteTag(_dataChannelStateTag, (short)DataStateEnum.DataChannelFree);
        }
Exemplo n.º 4
0
        public void WhenWriteAndReadValue_TagShouldRaiseEvent()
        {
            _tag.MonitorEvents();

            var writeAction = new Action(() => _tagController.WriteTag(_tag, 5).Wait());
            var readAction  = new Action(() => _tagListener.ReadTagSynchronously(_tag));

            writeAction.ShouldNotThrow();
            readAction.ShouldNotThrow();
            _tag.ShouldRaise("ValueChanged");
            _tag.Value.Should().Be((uint)5);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates and sets the channel
        /// </summary>
        /// <param name="fbName">Generic Plc to Mosaic Datachannel Function Object Block Name</param>
        /// <param name="scope">Scope</param>
        /// <param name="typeName">PLC Struct name to load</param>
        /// <exception><cref>VP.FF.PT.Common.PlcCommunication.PlcCommunicationException</cref></exception>
        public void SetChannel(string fbName, string scope, string typeName)
        {
            _dataChannelStateTag = new Tag(fbName + "." + UdtHandshakeFieldName, scope, "INT", _tagListener.Port);
            _dataChannelStateTag.ValueChanged += DataChannelStateTagValueChanged;

            // initialize DataChannel on PLC side
            _tagController.WriteTag(_dataChannelStateTag, (short)DataStateEnum.DataChannelFree);

            _channelToLineTag = new Tag(fbName + "." + UdtDataFieldName, scope, typeName, _tagListener.Port);
            _tagListener.AddUdtHandler <TDataType>(_channelToLineTag.DataType);

            // try to read value for the first time (might throw an exception if symbol does not exist)
            _tagListener.ReadTagSynchronously(_dataChannelStateTag);
            _tagListener.AddTag(_dataChannelStateTag);
        }
Exemplo n.º 6
0
        private int SendData(Tag tag, object value)
        {
            // make sure that intDataState is set to 1
            var fields = value.GetType().GetFields();

            if (fields.Length == 0 || fields[fields.Length - 1].Name != UdtHandshakeFieldName)
            {
                RaiseCommunicationProblem(
                    new PlcCommunicationException(
                        "Cannot send data over DataChannel because Data UDT does not follow convention! Must have variable " +
                        UdtHandshakeFieldName + " as last field. Tag: " + tag.Name, _tagListener.AddressAndPath, ""));

                return(-1);
            }

            fields[fields.Length - 1].SetValue(value, (short)DataStateEnum.DataWritten);

            try
            {
                _tagController.WriteTag(tag, value);
            }
            catch (Exception e)
            {
                RaiseCommunicationProblem(e);
                return(-1);
            }

            return(0);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Sets the channel.
        /// </summary>
        /// <param name="channelToLineTag">The channel automatic line tag.</param>
        /// <exception cref="PlcCommunicationException">Data UDT must follow convention! It must contain a intDataState field and connection to PLC must be possible!</exception>
        public void SetChannel(Tag channelToLineTag)
        {
            // make sure that intDataState is set to 1
            var fields = typeof(TDataType).GetFields();

            if (fields.Length == 0 || fields[fields.Length - 1].Name != UdtHandshakeFieldName)
            {
                throw new PlcCommunicationException(
                          "Cannot set DataChannel " + channelToLineTag.Name + " because Data UDT does not follow convention! DataType Must contain a variable " +
                          UdtHandshakeFieldName + " as last field. Tag: " + channelToLineTag.Name, _tagListener.AddressAndPath, "");
            }

            var dataChannelStateTag = new Tag(channelToLineTag.Name + "." + UdtHandshakeFieldName, channelToLineTag.Scope, "INT", channelToLineTag.AdsPort);

            dataChannelStateTag.ValueChanged += DataChannelStateTagValueChanged;

            // initialize DataChannel on PLC side
            _tagController.WriteTag(dataChannelStateTag, (short)DataStateEnum.DataChannelFree);

            _tagListener.AddUdtHandler <TDataType>(channelToLineTag.DataType);
            _tagListener.AddTag(dataChannelStateTag);
            _channelToLineTag = channelToLineTag;
        }
Exemplo n.º 8
0
        public void SetUp()
        {
            _tagController  = new BeckhoffTagController(Global.AdsAddress, Global.AdsPort);
            _tagListener    = new BeckhoffPollingTagListener(Global.AdsAddress, Global.AdsPort, new GlobalLock());
            _alarmsImporter = new BeckhoffOnlineAlarmsImporter(Global.AdsAddress, Global.AdsPort, new GlobalLock());
            _alarmsImporter.Initialize(_tagListener);

            _tagController.StartConnection();
            _tagListener.StartListening();

            // prepare test by clear out all alarms
            _tagController.WriteTag(WriteTags.GlobalAlarmsCommandTag, WriteTags.ClearAllAlarmsCommand).Wait();
            Thread.Sleep(500);
        }
Exemplo n.º 9
0
        public void SetUp()
        {
            _tag           = new Tag("fbAGS_1.udiAlarmId", "MiddlePRG_1", "UDINT", Global.AdsPort);
            _tagController = new BeckhoffTagController(Global.AdsAddress, Global.AdsPort);
            _tagController.StartConnection();
            _tagListener = new BeckhoffPollingTagListener(Global.AdsAddress, Global.AdsPort, new GlobalLock());
            _tagListener.StartListening();

            try
            {
                _tagController.WriteTag(_tag, 0).Wait(1000);
            }
            catch (Exception e)
            {
                Assert.Fail("Cannot setup test because writing initial values to PLC failed. " + e.Message);
            }
        }