Пример #1
0
 private void SetListButtonsState(TagItem tag)
 {
     if (tag == null)
     {
         btnDeleteTag.IsEnabled = false;
     }
     else
     {
         btnDeleteTag.IsEnabled = true;
     }
 }
Пример #2
0
        public bool PLCAddTag(TagItem tag)
        {
            bool RetValue = true;

            // se già presente non lo agiungo
            if (model.ListTagItems.Contains(tag))
            {
                Logger.InfoFormat("tag {0}/{1} già presente", tag.PLCName, tag.Address);
                return(false);
            }


            //Create a DotNetMQ Message to send
            var message = mdsClient.CreateMessage();

            //Set destination application name
            message.DestinationApplicationName = PLCServerApplicationName;

            //Create a message
            var MsgData = new PLCTagData
            {
                MsgCode = MsgCodes.SubscribePLCTag,
                Tag     = new PLCTag()
                {
                    PLCName = tag.PLCName, Address = tag.Address
                }
            };

            //Set message data
            message.MessageData = GeneralHelper.SerializeObject(MsgData);

            // message.MessageData = Encoding.UTF8.GetBytes(messageText);
            message.TransmitRule = MessageTransmitRules.NonPersistent;

            try
            {
                //Send message
                message.Send();

                Logger.InfoFormat("Inviato Messaggio a {0}", message.DestinationApplicationName);
            }
            catch
            {
                // non sono riuscito a inviare il messaggio
                Logger.InfoFormat("Messaggio non inviato");
                RetValue = false;
            }

            return(RetValue);
        }
Пример #3
0
        // verifica correttezza formale nome tag ( <plcname>/<nometag>:<tipotag> )
        public bool PLCTagIsCorrect(string tagName)
        {
            bool RetVal = true;

            // split plcname e varname (es : plc4/db86.dbd58:Bool)
            string[] var1 = tagName.Split('/');
            if (var1.Count() == 2)
            {
                // split varname e var type (es : db86.dbd58:Bool)
                string[] var2 = var1[1].Split(':');
                if (var2.Count() == 2)
                {
                    var tag = new TagItem()
                    {
                        PLCName = var1[0], Address = var2[0], Type = var2[1]
                    };
                    // controlla che plcname sia un plc connesso
                    if (!PLCNameExists(tag.PLCName))
                    {
                        RetVal = false;
                    }
                    else
                    {
                        // controllo tipo tag
                    }
                    // controllo esistenza tag ?
                }
                else
                {
                    RetVal = false;
                }
            }
            else
            {
                RetVal = false;
            }

            return(RetVal);
        }
Пример #4
0
        private bool ResultSubscribePLCTag(IIncomingMessage Message)
        {
            bool RetValue = true;

            // get msg application data
            var MsgData = GeneralHelper.DeserializeObject(Message.MessageData) as PLCTagData;

            Logger.InfoFormat("Ricevuto Messaggio {1}/{2}:{3} da {0}", Message.SourceApplicationName, MsgData.Tag.PLCName, MsgData.Tag.Address, MsgData.Tag.Value);

            TagItem tag = new TagItem()
            {
                PLCName = MsgData.Tag.PLCName, Name = MsgData.Tag.Address
            };

            if (tag != null)
            {
                Logger.InfoFormat("Aggiunto {0}/{1}:{2}", tag.PLCName, tag.Address, tag.Type);

                /* verifica il nome del plc tag */
                model.ListTagItems.Add(tag);
            }
            return(RetValue);
        }
Пример #5
0
        private void btnAddTag_Click(object sender, RoutedEventArgs e)
        {
            // Create the startup window
            var AddVarWnd = new AddVar();

            // Show the window
            if (AddVarWnd.ShowDialog() == true)
            {
                // split plcname e varname (es : plc4/db86.dbd58:Bool)
                string[] var1 = AddVarWnd.tbVarName.Text.Split('/');
                if (var1.Count() == 2)
                {
                    // split varname e var type (es : db86.dbd58:Bool)
                    string[] var2 = var1[1].Split(':');
                    if (var2.Count() == 2)
                    {
                        var tag = new TagItem()
                        {
                            PLCName = var1[0], Address = var2[0], Type = var2[1]
                        };

                        // controlla che plcname sia un plc connesso
                        // ...

                        Controller.Instance.PLCAddTag(tag);
                    }
                    else
                    {
                        // errore in nome var
                    }
                }
                else
                {
                    // errore in nome var
                }
            }
        }