SmartConnector Forum
Schneider Electric support forum about SmartConnector applications for integration of other building management systems (BMS) into EcoStruxure Building Operation.
Link copied. Please paste this link to share this article on your social media post.
Dear Community,
I have a problem with the implementation of the CustomSetValueProcessor and the SetValue function:
when I update the value from the Workstation I see the correct value in the CustomSetValueProcessor in my logs, but in the SetupProcessor I don't see the updated value.
I followed what has been done in the developer guide: I created the class CustomEwsServiceHost, with my CustomSetValueProcessor and the SetValue function.
protected override ResultType SetValue(ValueTypeStateless item)
{
log.Debug("[CARDPROGRAMMERPROCESSOR UPDATE] Changed item " + item.Id + " to " + item.Value);
string errorMessage = "";
Utility.MakeDataServedUncertain(DataAdapter, item.Id, item.Value, out errorMessage);
log.Debug("[CARDPROGRAMMERPROCESSOR UPDATE] MakeDataServedUncertain DONE:"+ errorMessage);
return base.SetValue(item);
}
Created the function MakeDataServerdUncertain that updates the value in the dataAdapter and verifies to have update it correctly
public static bool MakeDataServedUncertain(EwsServerDataAdapter adapter, string itemID, string itemValue, out string ErrorMessage)
{
bool result = true;
ErrorMessage = "";
try
{
switch (itemID)
{
case EWSServerNames.WriteCardIDX:
case EWSServerNames.ReadCardIDX:
adapter.ModifyValueItemValue(itemID, Convert.ToBoolean(Convert.ToInt32(itemValue)), EwsValueStateEnum.Good);
var currentWriteValue = adapter.ValueItems.FirstOrDefault(x => x.AlternateId == EWSServerNames.WriteCardIDX);
ErrorMessage = "modified correctly!"+ currentWriteValue.Value;
break;
case EWSServerNames.CardNumberIDX:
case EWSServerNames.PlantCodeIDX:
adapter.ModifyValueItemValue(itemID, Convert.ToInt32(itemValue), EwsValueStateEnum.Uncertain);
break;
case EWSServerNames.ExpirationDateIDX:
adapter.ModifyValueItemValue(itemID, Convert.ToDateTime(itemValue), EwsValueStateEnum.Uncertain);
break;
default:
break;
}
}
catch (Exception ex)
{
ErrorMessage = ex.Message;
result = false;
}
return result;
}
In the SetupProcessor I call the function CheckReadWriteCommand which periodically (every 2 seconds) re-reads the value of the item WriteCard and in case it's true it will write the card:
private void CheckReadWriteCommand()
{
try
{
while (continueExecution && !IsCancellationRequested)
{
var currentWriteValue = DataAdapter.ValueItems.FirstOrDefault(x => x.AlternateId == EWSServerNames.WriteCardIDX);
if (currentWriteValue == null)
{
log.Debug("[CARDPROGRAMMERPROCESSOR UPDATE] Write card idx not found");
}
log.Debug("[CARDPROGRAMMERPROCESSOR UPDATE] CheckReadWriteCommand: New value of currentWriteValue = " + currentWriteValue.Value + " [last modified: " + currentWriteValue.LastModified + "]");
// if true write the card
System.Threading.Thread.Sleep(2000);
}
}
catch (Exception ex)
{
log.Error("[CARDPROGRAMMERPROCESSOR UPDATE] CheckReadWriteCommand: error: " + ex.Message);
}
}
Nonetheless when I write the WriteCard value to true from the Workstation I see the correct variation of the value in the CustomSetValuesProcessor, but not in the SetupProcessor: there the value is always the previous one. The only way to see the value updated is to restart the processor, that reupload the values from the EWSServer.
In the logs I see:
2021-02-11 11:40:01.7725,[CARDPROGRAMMERPROCESSOR UPDATE] CheckReadWriteCommand: New value of currentWriteValue = False [last modified: 11/02/2021 10:39:20], //dato letto periodicamente dal SetupProcessor
2021-02-11 11:40:01.8833,[CARDPROGRAMMERPROCESSOR UPDATE] Changed item WriteCard to 1, //informazione che vedo nel CustomSetValuesProcessor
2021-02-11 11:40:01.9451,[CARDPROGRAMMERPROCESSOR UPDATE] MakeDataServedUncertain DONE:modified correctly!True, //conferma nel CustomSetValuesProcessor della modifica del valore nell’item del dataAdapter
2021-02-11 11:40:03.7769,[CARDPROGRAMMERPROCESSOR UPDATE] CheckReadWriteCommand: New value of currentWriteValue = False [last modified: 11/02/2021 10:39:20], //dato letto periodicamente dal SetupProcessor
My doubts are: the 2 adapters (CustomSetValueProcessor and SetupProcessor) are effectively the same adapter? Or they are 2 distinct adapters?
Why I cant propagate the modifies from one to the other?
I have to manage manually, with some events, the passage of the data from the CustomSetValuesProcessor to the SetupProcessor?
Many thanks to who helps me!!
Sabrina
Link copied. Please paste this link to share this article on your social media post.
Hi Sabrina,
If I understand correctly, you have a setup processor that implements an infinite loop (in that you are not utilizing Smart Connector schedules to run on an interval). In this case, I am assuming that the EwsServerDataAdapter class you have is instantiated once and reused in the infinite loop. If this is the case, and you are not instantiating a new instance, you need to call .CreateDatabaseContext() on the DataAdapter before reading the values. The description for this method is:
“Will regenerate the database contexts this adapter is connected to. You only need to call this if you know that objects may have been modified by another process (WHICH IN YOUR CASE YOU KNOW THEY ARE BY THE CUSTOM SET VALUES). All pending changes will be lost.”
However, while the above will work in your infinite loop code, what I would suggest in this case, as it seems like there is no real need for an infinite loop in this scenario, is to setup your Setup Processor to run on a schedule in the Smart Connector portal instead. That way the processor will automatically ‘restart’ every x seconds. In general this is the preferred way to develop processors as it is enough in the majority of cases.
Please let me know if you have any questions.
Best Regards,
-Jeff
Link copied. Please paste this link to share this article on your social media post.
Hi Sabrina,
If I understand correctly, you have a setup processor that implements an infinite loop (in that you are not utilizing Smart Connector schedules to run on an interval). In this case, I am assuming that the EwsServerDataAdapter class you have is instantiated once and reused in the infinite loop. If this is the case, and you are not instantiating a new instance, you need to call .CreateDatabaseContext() on the DataAdapter before reading the values. The description for this method is:
“Will regenerate the database contexts this adapter is connected to. You only need to call this if you know that objects may have been modified by another process (WHICH IN YOUR CASE YOU KNOW THEY ARE BY THE CUSTOM SET VALUES). All pending changes will be lost.”
However, while the above will work in your infinite loop code, what I would suggest in this case, as it seems like there is no real need for an infinite loop in this scenario, is to setup your Setup Processor to run on a schedule in the Smart Connector portal instead. That way the processor will automatically ‘restart’ every x seconds. In general this is the preferred way to develop processors as it is enough in the majority of cases.
Please let me know if you have any questions.
Best Regards,
-Jeff
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.