Procedure

In this example, the data is to be written into a file, which is then to be closed, after which it is re-opened to read the data from the same file. The table below describes the procedure to follow for this example:

Step

Action

1

Execute the OPEN_FILE function by enabling the cmd_open bit, by right-clicking on the Req input parameter.

Result: A unique and temporary identification number is assigned to the opening instance as a FileDesc output. (In this case, we have assigned value 5 to this output. Use this value to declare the FileDesc input variable for the WR_DATA_TO_FILE and CLOSE_FILE functions.)

The graphic below is a representation of the function after execution:

Disable cmd_open by right-clicking on the Req input parameter.

2

In the WR_DATA_TO_FILE block, force the %MW10 variable to the value 100 by right-clicking on the variable input parameter.

3

Execute the WR_DATA_TO_FILE function by enabling the cmd_write bit by right-clicking on the Req input parameter.

Result: the value of the variable is written into the test file.

The graphic below is a representation of the function after execution:

Disable cmd_write by right-clicking on the Req input parameter.

4

Execute the CLOSE_FILE function by enabling the cmd_close bit by right-clicking on the Req input parameter.

Result: The file is closed and the FileDesc identification number is freed for use at a later date.

The graphic below is a representation of the function after execution:

Disable cmd_close by right-clicking on the Req input parameter.

5

Execute the OPEN_FILE function again by enabling the cmd_open bit by right-clicking on the Req input parameter.

Result: It is a new opening instance, so a new FileDesc number is assigned, in this case 6. Use these values to declare the FileDesc input variable for the RD_FILE_TO_DATA and CLOSE_FILE functions.

The graphic below is a representation of the function after execution:

Disable cmd_open by right-clicking on the Req input parameter.

6

In the RD_FILE_TO_DATA block, force the %MW10 variable to the value 120 by right-clicking on the variable input parameter. By doing this, it is possible to check that the value retrieved by the RD_FILE_TO_DATA function is correct.

The graphic below is a representation of the function before execution:

7

Execute the RD_FILE_TO_DATA function by enabling the cmd_read bit, by right-clicking on the Req input parameter.

Result: The function reads the file data, i.e., the value of the variable written beforehand with the WR_DATA_TO_FILE function. This value can be found in the Variable output parameter.

The graphic below is a representation of the function after execution:

Disable cmd_read by right-clicking on the Req input parameter.

8

Execute the CLOSE_FILE function by enabling the cmd_close bit by right-clicking on the Req input parameter.

Result: The file is closed and the FileDesc identification number is freed for use at a later date.

The graphic below is a representation of the function after execution:

Disable cmd_close by right-clicking on the Req input parameter.