Output handling through both C# and HMI

Hello,
I want to be able to have a variable BOOL ARM in my C# code which will be connected to my OUTPUT1 of my PLCnext. I also want to be able to change OUTPUT1 state from my HMI and I want my C# code to also be informed about the status change. How can I do that?
Thank you for your time in advance.

Hello dimitrismvrm,
The changing of variable value in C# code and HMI will leads in inconsistent variable value and program behavior. Generally the write access to variable should be implemented only once in program code. This ensure the code quality and helps in failure sarching or debugging.
I’m not familiar with your application requirement, but I assume the implementation of state machine for atomatical and manual mode for exchange the variable value can help (e.g. you can switch between calculated value in C# code and manual setting value in HMI).
I hope it helps.
BR Eduard

Hello again,
How can I do what you said in the last paragraph?

Hello dimitrismvrm,
please find the programming introduction in PLCnext Info Center: Introduction to PLCnext programmingCode Examples are available on GitHub: GitHub - PLCnext/CSharpExamples: Collection of various C# sample code for PLCnext Technology controllers.
I think the most efficient way is to take programming training in our training department. If you are interested please let me know and I will forward the information.
To learn more about State Machine, please visit the following MS-Link: State Machine Workflows - .NET Framework | Microsoft Learn
The training for implementing C# programs is outside the support scope, but may be the following simple FB-Sample code will help you in the first step:

[FunctionBlock]
public class Sample
{
    [Input]
    public bool xManualMode; //Consumer Variable (Input), will be connected in PLCnext Engineer with HMI-Variable (Operation Mode)
[Input]

public int iHMI_VarValue; //Consumer Variable (Input), will be connected in PLCnext Engineer e.g.

with HMI-Variable (manual Value)
    [Output]
    public int iVariableValue = 0; //Producer Variable (Output), will be connected in PLCnext Engineer with e.g. process data
        
    [Initialization]
    public void __Init()
    {
  iVariableValue = 0;
    }
    [Execution]
    public void __Process()
    {
    
if (xManualMode)
 {
    iVariableValue = iHMI_VarValue;
 }
else
{
   iVariableValue ++;
}
    }
}

BR Eduard