0

When I trace my program (online with breakpoint and singlestep) I see, that the VAR SOpen becomes "* INVALID: 16#02 *" when the line Step:=Step+1; is reached.

Watching the trace more careful, I saw, that Step changes from 0 to 1, in the first call of "0:". The two VARs are the two initialized and seem to be linked together. The aditional increase sets Step to 2 (in the 1st run!) and SOpen to invalid.

PROGRAM PLC_PRG
VAR
    SerIO: SERCOMM;
    Step: BYTE := 0;
    Input: ARRAY [0..50] OF DWORD;
    SOpen: BOOL := FALSE;
END_VAR

IF Eingang1 THEN
    CASE Step OF
    0:
        IF NOT SOpen THEN
            SerIO.FB_ACTION := Open;
            SerIO.RECEIVE_BUFFER:=Input[0];
            SerIO.COMPORT:=1;
            SerIO.EN:=TRUE;
            Ausgang1 := NOT SerIO.ERROR;
            SOpen :=TRUE;
            SerIO.EN:=FALSE;
        END_IF;
    1:
        IF SOpen THEN
            SerIO.FB_ACTION:=Read;
            SerIO.EN:=TRUE;
            Ausgang1 := NOT SerIO.ERROR;
            Ausgang2 := (SerIO.BYTES_DONE>3);
            SerIO.EN:=FALSE;
        END_IF;
    2:
        IF SOpen THEN
            SerIO.FB_ACTION:=Close;
            SerIO.EN:=TRUE;
            Ausgang1 := NOT SerIO.ERROR;
            SOpen :=FALSE;
            SerIO.EN:=FALSE;
        END_IF;
    END_CASE
    Step:=Step+1;
    IF Step>2 THEN Step :=0; END_IF;
ELSIF SOpen THEN
    SerIO.FB_ACTION:=Close;
    SerIO.EN:=TRUE;
    SerIO.EN:=FALSE;
    SOpen :=FALSE;
    Step:=0;
END_IF;
Nikodemus RIP
  • 1,369
  • 13
  • 20

2 Answers2

0

Question why would you place the CASE statement in an IF statement? The IF statement should be calling your steps?

If something then
  step = 10; (* start processing *)
else
  step = 0;
end_if

case step of

  0:
    Kill your enable or an idle state here stop state.
  10: (* Start *)
    step = step +1;
  20:
       Call FB
  40: (*continue *)
   step = 10;

  30: (* End *)
   step = 0;
   else (* catch something here *)

  end_case

call FB here that gets inputs from above code.

It's hard to tell the INVALID sometimes if you don't perform a clean all and the variable list gets out of wack that can happen. Sorry not much of a help I have seen the invalid and it came from clean project and looking at invalid pointer that haven't been called yet.

APC
  • 144,005
  • 19
  • 170
  • 281
0

I transferred the VAR now to VAR_GLOBAL. That's not really what I want, but now it works. Better solutions are welcome and will be accepted :)

Nikodemus RIP
  • 1,369
  • 13
  • 20