예제 #1
0
        public bool PLCAddTag(TagItem tag)
        {
            bool RetValue = true;

            // se già presente non lo aggiungo
            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(Texts._MSG_SENT_TO_ + " {0}", message.DestinationApplicationName);
            }
            catch
            {
                // non sono riuscito a inviare il messaggio
                Logger.InfoFormat(Texts._MSG_NOT_SENT_);
                RetValue = false;
            }

            return(RetValue);
        }
예제 #2
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);
        }