/// <summary> /// Impostazione valore plctag /// </summary> /// <param name="tag"></param> /// <returns>true se tutto bene, altrimenti false</returns> private bool SetPLCTag(PLCTag tag) { bool RetValue = true; /* verifico connessione/esistenza PLC interessato */ if (!_PLCs.ContainsKey(tag.PLCName)) { // log Logger.WarnFormat("PLC [{0}] not connected", tag.PLCName); RetValue = false; } else { try { /* scrivo tag */ var plctag = new S7NetWrapper.Tag(tag.Address, tag.Value); _PLCs[tag.PLCName].Write(plctag); } catch (Exception exc) { // log Logger.WarnFormat("PLC [{0}] error writing tag {1} : {2}", tag.PLCName, tag.Address, exc.Message); RetValue = false; } } return(RetValue); }
/// <summary> /// Implementazione esecuzione comando di set valore lista plctags /// </summary> /// <param name="Message">Dati messaggio ricevuto</param> /// <returns>true se tutto bene, altrimenti false</returns> private bool SetPLCTags(IIncomingMessage Message) { bool RetValue = true; // get msg application data var MsgData = GeneralHelper.DeserializeObject(Message.MessageData) as PLCTagsData; var tagslist = MsgData.Tags; Logger.InfoFormat("{0}", Message.SourceApplicationName); for (int i = 0; i < tagslist.Count; i++) { var tag = tagslist[i]; // verifico connessione/esistenza PLC interessato if (!_PLCs.ContainsKey(tag.PLCName)) { // log Logger.WarnFormat("PLC [{0}] not connected", tag.PLCName); tag.Validation = false; RetValue = false; } else { try { // scrivo tag var plctag = new S7NetWrapper.Tag(tag.Address, tag.Value); _PLCs[tag.PLCName].Write(plctag); tag.Validation = true; } catch (Exception exc) { // log Logger.WarnFormat("PLC [{0}] error writing tag {1} : {2}", tag.PLCName, tag.Address, exc.Message); tag.Validation = false; RetValue = false; } } } // invio messaggio di risposta generica return(SendResponse(Message, MsgCodes.ResultSetPLCTags, MsgData, RetValue)); }