At a Glance

The following example illustrates the WRITE_VAR function with a management parameter check.

Programming the function

Programming in ST:

IF NOT %M20 AND %I0.1.2 THEN
   %MW200:4:= 0;
   INC %MW1700
   %MW202:= 50;
  WRITE_VAR(ADDR(’0.3.1.7’),’%MW’,20,1,%MW1700:1,%MW200:4);
   SET %M20;
END_IF;
  • the input bit %I0.1.2 controls the function,

  • the internet bit %M20 is used to test the activity of the function,

  • %MW200:4:= 0; sets the management table to 0,

  • INC %MW1700; increments the word %MW1700,

  • MW202:= 50; initializes the timeout value to 5 seconds.

NOTE: WRITE_VAR(ADDM(‘0.3.1.7’),’%MW’,20,1,%MW1700:4,%MW200:4); syntax must be used for Modicon M340 PLCs as ADDR function cannot be used by a Modicon M340 PLC.

Programming the exchange check

Programming in ST:

IF %M20 AND NOT %M200.0 THEN
   INC %MW204;
   IF %MW201 = 0 THEN
      INC %MW205;
   ELSE
      SET %Q0.2.2;
      INC %MW206;
      %MW207 := %MW201; 
   END_IF;
END_IF;
  • %MW204 counts the number of exchanges,

  • %MW205 counts the number of correct exchanges,

  • %MW206 counts the number of exchanges generating errors,

  • %MW207 stores the error message,

  • %Q0.2.2 indicates an exchange failure.