Ejemplo n.º 1
0
        private bool PLCTagsChanged(IIncomingMessage Message)
        {
            bool RetValue = true;

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

            Logger.InfoFormat("Ricevuto Messaggio da {0}", Message.SourceApplicationName);

            foreach (var plctag in plctags)
            {
                bool bOK = true;

                // trova il tag corrispondente (uno solo) all'indirizzo sottoscritto
                TagItem tag = ListTagItems.FirstOrDefault(item => item.PLCName == plctag.PLCName && item.Address == plctag.Address);

                if (tag != null)
                {
                    //
                    try
                    {
                        tag.Value = plctag.Value;
                        Logger.InfoFormat("Cambiato Tag {0} : {1}/{2}:{3} -> {4}", tag.Name, tag.PLCName, tag.Address, tag.Type, tag.Value);
                    }
                    catch (Exception exc)
                    {
                        Logger.WarnFormat("Errore in cambio Tag value {0} : {1}/{2}:{3} -> {4} {5}", tag.Name, tag.PLCName, tag.Address, tag.Type, tag.Value, exc.Message);
                    }

                    // recuperare la lista delle properties dell'impianto
                    List <MariniProperty> props = mariniImpiantoTree.MariniImpianto.GetObjectListByType(typeof(MariniProperty)).Cast <MariniProperty>().ToList();
                    // trova la property associata e cambia il valore
                    MariniProperty property = props.FirstOrDefault(prp => prp.bind == tag.Name);

                    if (property != null)
                    {
                        try
                        {
                            property.value = tag.Value;
                        }
                        catch (Exception exc)
                        {
                            Logger.WarnFormat("Errore in cambio valore property {0}:{1} {2}", property.name, tag.Value, exc.Message);
                            bOK = false;
                        }
                    }
                }
                else
                {
                    Logger.InfoFormat("Tag associato a : {0}/{1} non trovato", plctag.PLCName, plctag.Address);
                    bOK = false;
                }
                if (bOK == false)
                {
                    RetValue = bOK;
                }
            }
            return(RetValue);
        }
Ejemplo n.º 2
0
        public void Handle(object sender, PropertyChangedEventArgs e)
        {
            MariniProperty mp     = sender as MariniProperty;
            string         p_name = e.PropertyName;

            Console.WriteLine("Motore1AlarmHandler->Handler --- sender: {0} proprieta: {1} valore: {2}", mp.path, p_name, mp.value);
            //methodToBeCalledWhenPropertyIsSet();
        }
Ejemplo n.º 3
0
        public void MariniPropertyHandler(object sender, PropertyChangedEventArgs e)
        {
            MariniProperty mp     = sender as MariniProperty;
            string         p_name = e.PropertyName;

            Logger.DebugFormat("MariniPropertyHandler --- sender: {0}, proprieta': {1} valore: {2}", mp.path, p_name, mp.value);
            //Console.WriteLine( "MariniPropertyHandler --- sender: {0}, proprieta': {1} valore: {2}", mp.path, p_name, mp.value);

            // Qui devo verificare il tipo di variabile e fare il lavoro richiesto sul plctag
        }
Ejemplo n.º 4
0
        private bool SetPropertyPLCTag(MariniProperty mp)
        {
            bool bOK = true;

            string PLCTagName = mp.bind;

            var plctag = GetPLCTagData(PLCTagName);

            if (plctag == null)
            {
                bOK = false;
            }

            if (bOK)
            {
                // Mando messaggio di set tag a plcserver
                //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.SetPLCTag,
                    Tag     = new PLCTag()
                    {
                        PLCName = plctag.PLCName,
                        Address = plctag.Address,
                        Value   = mp.value
                    }
                };

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

                try
                {
                    // send message
                    message.Send();
                    Logger.InfoFormat("Set Value {0}:{1}", plctag.Name, mp.value);
                }
                catch (Exception exc)
                {
                    // non sono riuscito a inviare il messaggio
                    Logger.WarnFormat("Exception : {0}", exc.Message);
                }
            }
            return(bOK);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// invia la notifica ai sottoscrittori
        /// </summary>
        /// <param name="mp">Property to notify</param>
        private void ObjectPropertyNotifyToSubscribers(MariniProperty mp)
        {
            foreach (var subscriber in ListSubscriptions.Keys)
            {
                Property property = null;
                // cerco la property con path corrispondente
                foreach (var prop in ListSubscriptions[subscriber].ToList())
                {
                    if (prop.ObjPath == mp.path)
                    {
                        property = prop;
                        break;
                    }
                }

                if (property != null)
                {
                    // assegno il valore alla property
                    property.Value = mp.value;

                    // Mando messaggio di property changed al sottoscrittore
                    //Create a DotNetMQ Message to send
                    var message = mdsClient.CreateMessage();

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

                    //Create a message
                    var MsgData = new PropertyData
                    {
                        MsgCode = MsgCodes.PropertyChanged,
                        Prop    = property
                    };

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

                    try
                    {
                        //Send message
                        message.Send();
                        Logger.InfoFormat("{1}:{2} : Inviato valore a {0}", message.DestinationApplicationName, property.ObjPath, property.Value.ToString());
                    }
                    catch (Exception exc)
                    {
                        // non sono riuscito a inviare il messaggio
                        Logger.WarnFormat("valore non inviato - {0}", exc.Message);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public static MariniGenericObject CreateMariniObject(MariniGenericObject parent, XmlNode node)
        {
            MariniGenericObject mgo;

            // uso il ToLower percui mettere tutto a minuscolo qui e come si vuole nel file xml
            switch (node.Name)
            {
            case "Impianto":
                mgo = new MariniImpianto(parent, node);
                break;

            case "ZonaPredosaggio":
                mgo = new MariniZonaPredosaggio(parent, node);
                break;

            case "Predosatore":
                mgo = new MariniPredosatore(parent, node);
                break;

            case "Property":
                mgo = new MariniProperty(parent, node);
                break;

            default:
                mgo = new MariniOggettoBase(parent, node);
                break;
                //    throw new ApplicationException(string.Format("MariniObject '{0}' cannot be created", mgo));
            }

            /* Riempio la lista oggetti con i nodi figli */
            XmlNodeList children = node.ChildNodes;

            foreach (XmlNode child in children)
            {
                if (children.Count > 0)
                {
                    //Console.WriteLine("Parent id: {0} node.childnodes = {1}", mgo.id, node.ChildNodes.Count);
                    mgo.ListaGenericObject.Add(CreateMariniObject(mgo, child));
                }
            }

            /* restituisco l'oggetto creato: GOF factory pattern */
            return(mgo);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// metodo chiamato sul cambiamento del valore di una property
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void PropertyValueChangedHandler(object sender, PropertyChangedEventArgs e)
        {
            MariniProperty mp = sender as MariniProperty;

            /* se la property ha un plctag associato ... */
            switch (mp.binddirection)
            {
            case BindDirection.TwoWay:
            case BindDirection.OneWayToSource:
                // setto il plc tag corrispondente
                SetPropertyPLCTag(mp);
                break;

            case BindDirection.OneTime:
                break;

            case BindDirection.OneWay:
                break;
            }

            // notifico l'eventuale sottoscrizione
            ObjectPropertyNotifyToSubscribers(mp);
        }