Pm designer operation manual – B&B Electronics WOP-2121V-N4AE - Manual User Manual
Page 445

14
PM Designer Operation Manual
14-36
CHAPTER 14 USING MACROS
OPEN_FILE
Format
P1
= OPEN_FILE(P2,P3 )
Data Type
U
Function
Creates or opens a file.
P1 (I)
The starting location of the memory block that is used as a File Information Block to receive the
operation result. The structure of the File Information Block is shown below:
Data Item
Data Type/Size
Word No.
File handle
32-bit Unsigned Integer
0 and 1
File size
32 bit Unsigned Integer
2 and 3
Filename
Byte array with 81 elements
4 through 44
The file handle is zero if the operation failed.
The file size is zero for a newly created file.
The filename is a null-terminated character string. The maximum allowable size is 80. It is set
when the file is successfully opened.
A File Information Block requires 45 words.
P2 (I)
The byte array that contains the filename or the full pathname of the file to be opened. The name
is a null-terminated string and has only ASCII characters in it.
P3 (I/C)
Specifies the purpose of opening the file.
Purpose
Value
Read 0
Write 1
Append 3
Example 1
$U10
=
“test.txt”
$U100
= OPEN_FILE(
$U10
,
0
)
/* Open the file “test.txt” for the read operation. The double word
$100 will contain the file handle. The double word $102 will contain the file size. The byte array
$104 will contain the filename. */
READ_FILE
Format
P1
= READ_FILE(P2,P3,P4 )
Data Type
U
Function
Reads P4 bytes from file P2 to buffer P3 and saves the result in P1.
P1 (I)
The word to receive the number of bytes that were actually read. If the operation failed, the
number is 65535 (0xFFFF).
P2 (I)
The file handle of the file to be read.
P3 (I)
The memory block to receive the data read from the file.
P4 (I/C)
Number of bytes to be read from the file. The maximum you can specify is 32767(0x7FFF).
Example 1
$U200
= READ_FILE(
$U100
,
$U150
,
20
)
/* Read 20 bytes from the file specified by the file
handle in $U100 and saves the data in the memory block starting from $U150. */