Skip to content

Some suggestions about tutorial EN/ENO part #26

@Leeable

Description

@Leeable

Hi PLCnext Team, the README for EN/ENO is not so clearly, It only mentions three points.

  • EN has to be the first defined input and be in capital letters
  • ENO has to be the first defined output and be in capital letters
  • On error return (ENO == false) , the outputs must be well defined

For the reader we just know these for sure.

  1. EN needs to be defined and to be the first in the input.
  2. ENO needs to be defined to be the first in the output.
  3. Need to handle the case when ENO == false.

This might lead readers to think that PLCnext has some kind of 'magic' that can automatically handle error situations and jump to (ENO==false). But in reality, that's not the case; users need to explicitly handle error logic themselves. So I think this part should also be included in the README, so that readers can understand it more clearly.


Besides above, i also have a question about the Demo Code

public void __Process()
        {
            // EN/ENO handling must be implemented by the developer
            ENO = EN;
            if (ENO == false)
            {
                SetOutputValuesToDefault();
                return;
            }

            if (xDOWN)
            {
                iOUT--;
            }
            else
            {
                iOUT++;
            }
            // going into error state can be defined by the developer by setting ENO to false
            if (iOUT < 0 || iOUT > 1000)
            {
                ENO = false;
            }
        }

        // Outputs must be well defined on error return
        private void SetOutputValuesToDefault()
        {
            iOUT = 0;
        }
    }

In fact, the code will never trigger SetOutputValuesToDefault() if EN is always TRUE

if EN alwayss TRUE and iOUT exceed the range (<0 or > 1000) lead to ENO = false, at the beginning the ENO=EN will override ENO=false so the iOUT will increase (or decrease) indefinitely and will never be reset to zero.

Describe the solution you'd like

A clearer README document, and whether to improve the code in the demo?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions