Section 15.4.16 · Chapter 15: Using Macros
File Operation
■ FILE_IO
| Format | P1 = FILE_IO(P2,P3 ) | Data Type | U | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Function | Performs the file operation specified by P2 and P3 using default filename and saves the completion code in P1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| P1 (I) |
The word to receive the completion code of the
operation. If the completion code is 0, the operation
succeeded; otherwise the operation failed. Note: This command can only be used in the following types of macros: Main Macro, Event Macro, Time Macro, and Cycle Macro. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| P2,P3 (I/C) |
P2 specifies the type of file operation. P3 specifies
the ID of the data source. The following table describes
how to set P2 and P3.
<ID>: ID of the data logger, ID of the recipe block, ID of the USB camera, or number of the screen <Date>: The date when saving the data. <Time>: The time when saving the data. You can select the formats of <Date> and <Time> on the Custom page in the General Setup dialog box. You can select not to show the progress bar when the macro command is executed. To hide the progress bar, use the normal operation code plus 100. For example, to save the logged data to a CSV file without showing the progress bar, use the code 114 (100+14) instead of 14. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
■ FILE_IO_N
| Format | P1 = FILE_IO_N(P2,P3,P4) | Data Type | U | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Function | Performs the file operation specified by P2 and P3 using filename P4 and saves the completion code in P1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| P1 (I) |
The word to receive the completion code of the
operation. If the completion code is 0, the operation
succeeded; otherwise the operation failed. Note: This command can only be used in the following types of macros: Main Macro, Event Macro, Time Macro, and Cycle Macro. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| P2,P3 (I/C) |
P2 specifies the type of file operation. P3 specifies
the ID of the data source. The following table describes
how to set P2 and P3.
Note: You can select not to show the progress bar when the macro command is executed. To hide the progress bar, use the normal operation code plus 100. For example, to save the logged data to a CSV file without showing the progress bar, use the code 131 (100+31) instead of 31. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| P4 (I) | The byte array that contains the specified filename or full pathname. The name must be a valid Windows pathname with ASCII characters only. The character string must be null terminated and each character occupies one byte. The maximum length of the string is 127. All the folders stated in the full pathname must already exist or the file operation will fail. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
■ MKDIR
| Format | P1 = MKDIR(P2 ) |
| Function | Creates a new directory with the specified name P2 and saves the result to P1. |
| P1 (I) | The word to receive the completion code of the operation. If the completion code is 0, the operation succeeded; otherwise the operation failed. |
| P2 (I) | The byte array that contains the name of the new directory. The name must be a valid directory name with or without pathname and has only ASCII characters in it. |
■ 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:
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.
|
||||||||||||||
| Example 1 |
$U10 =
“test.txt” $U100 = OPEN_FILE($U10, 0) /* Open the file “test.txt” for the read operation. The double word $U100 will contain the file handle. The double word $U102 will contain the file size. The byte array $U104 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. */ | ||
■ WRITE_FILE
| Format | P1 = WRITE_FILE(P2,P3,P4 ) | Data Type | U |
|---|---|---|---|
| Function | Writes P4 bytes of data in P3 to file P2 and saves the completion code in P1. | ||
| P1 (I) | The word to receive the completion code of the operation. If the completion code is 0, the operation succeeded; otherwise the operation failed. | ||
| P2 (I) | The file handle of the file. | ||
| P3 (I) | The memory block (or byte array) that stores the data to be written to the file. | ||
| P4 (I/C) | Number of bytes to be written to the file. | ||
| Example 1 | $U200=WRITE_FILE($U100,$U150,30) /* Write 30 bytes of data stored in the memory block starting from $U150 to the file specified by the file handle in $U100. */ | ||
■ CLOSE_FILE
| Format | P1 = CLOSE_FILE(P2,P3 ) | Data Type | U |
|---|---|---|---|
| Function | Closes an opened file P2 and saves the completion code in P1. | ||
| P1 (I) | The word to receive the completion code of the operation. If the completion code is 0, the operation succeeded; otherwise the operation failed. | ||
| P2 (I) | The file handle of the file to be closed. | ||
| Example 1 | $U200=CLOSE_FILE($U100) /* Close the file specified by the file handle in $U100. */ | ||
■ DELETE_FILE
| Format | P1 = DELETE_FILE(P2 ) | Data Type | U |
|---|---|---|---|
| Function | Deletes a file named P2 and saves the completion code in P1. | ||
| P1 (I) | The word to receive the completion code of the operation. If the completion code is 0, the operation succeeded; otherwise the operation failed. | ||
| P2 (I) | The byte array that contains the filename or the full pathname of the file to be deleted. The name is a null-terminated string and has only ASCII characters in it. | ||
| Example 1 |
$U10 =
“test.txt” $U200 = DELETE_FILE($U10) /* Delete the file “test.txt”. */ |
||
■ RENAME_FILE
| Format | P1 = RENAME_FILE(P2,P3 ) | Data Type | U |
|---|---|---|---|
| Function | Renames file P2 with new name P3 and saves the completion code in P1. | ||
| P1 (I) | The word to receive the completion code of the operation. If the completion code is 0, the operation succeeded; otherwise the operation failed. | ||
| P2 (I) | The byte array that contains the filename or the full pathname of the file to be renamed. The name is a null-terminated string and has only ASCII characters in it. | ||
| P3 (I) | The byte array that contains the new filename. The name is a null-terminated string and has only ASCII characters in it. | ||
| Example 1 |
$U10 =
“test.txt” $U50 = “new.txt” $U200 = RENAME_FILE($U10, $U50) /* Rename the file “test.txt” to “new.txt”. */ |
||
■ COPY_FILE
| Format | P1 = COPY_FILE(P2,P3 ) | Data Type | U |
|---|---|---|---|
| Function | Copies the file P2 to a new file P3 and saves the completion code in P1. | ||
| P1 (I) |
The word to receive the completion code of the
operation. If the completion code is 0, the operation
succeeded; Otherwise the operation failed. Note: This command can only be used in the following types of macros: Main Macro, Event Macro, Time Macro, and Cycle Macro. |
||
| P2 (I) | The byte array that contains the filename or the full pathname of the file to be copied. The name is a null-terminated string and has only ASCII characters in it. | ||
| P3 (I) | The byte array that contains the filename or the full pathname of the new file. The name is a null-terminated string and has only ASCII characters in it. | ||
| Example 1 |
$U10 =
“c:\abc.txt” $U50 = “d:\new.txt” $U200 = COPY_FILE($U10, $U50) /* Copy the file “c:\abc.txt” to the new file “d:\new.txt”. */ |
||
■ GET_VOL_INFO
| Format | P1 = GET_VOL_INFO(P2,P3 ) | Data Type | U | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Function | Gets the information of volume P2 and saves the result in P3. The completion code is saved in P1. | |||||||||||||||||
| P1 (I) | The word to receive the completion code of the operation. If the completion code is 0, the operation succeeded; otherwise the operation failed. | |||||||||||||||||
| P2 (I/C) |
The drive ID.
|
|||||||||||||||||
| P3 (I) |
The starting location of the memory block that is used
as a Volume Information Block to receive the operation
result. The structure of the Volume Information Block is
shown below:
Both the unit of volume size and the unit of free size are 1024 bytes. A Volume Information Block requires 21 words. |
|||||||||||||||||
| Example 1 | $U100 = GET_VOL_INFO(0, $U0) /* Get the volume information of the current drive. The volume name will be stored in $U0 through $U15. The size of the drive will be stored in $U16 and $U17. The free size of the drive will be stored in $U18 and $U19. The ID of the current drive will be stored in $U20. */ | |||||||||||||||||
■ READ_CSV
| Format | P1 = READ_CSV(P2,P3,P4 ) | Data Type | S/U/SD/UD/F |
|---|---|---|---|
| Function | Reads the data in the field of row P3 and column P4 of the CSV file P2 and saves the result in P1. | ||
| P1(I) | The word location to receive the value of the specified field. The data type selected for this command should be the same as the data type of the specified field, or the operation may fail. If the operation fails for any reason, no value will be written to P1. To know if the operation failed or not, check the word $S522. When the value of $S522 is non-zero, the operation failed. | ||
| P2(I) | The file handle of the file to be read. The file must be a CSV file and is opened with the purpose of Read CSV File. The delimiter must be TAB. | ||
| P3(I/C) | The row number of the field to be read. The row counts from 0. | ||
| P4(I/C) | The column number of the field to be read. The column counts from 0. | ||
| Example 1 |
$U10 = "test.csv" $U100 = OPEN_FILE($U10,5) /* Open the file "test.csv" for the READ CSV FILE operation. */ $U200 = READ_CSV($U100,2,3) (F) /* Read the floating point number in the field of row 2 and column 3 and save the result in $U200 and $U201. */ |
||
■ READ_CSV_STR
| Format | P1 = READ_CSV_STR (P2,P3,P4 ) |
| Function | Reads the string in the field of row P3 and column P4 of the CSV file P2 and saves the result in P1. |
| P1(I) | The byte array to receive the string in the specified field. The maximal string length that this command can handle is 128. If the operation fails for any reason, no value will be written to P1. To know if the operation failed or not, check the word $S522. When the value of $S522 is non-zero, the operation failed. |
| P2(I) | The file handle of the file to be read. The file must be a CSV file and is opened with the purpose of Read CSV File. The delimiter must be TAB. |
| P3(I/C) | The row number of the field to be read. The row counts from 0. |
| P4(I/C) | The column number of the field to be read. The column counts from 0. |
| Example 1 |
$U10 = "test.csv" $U100 = OPEN_FILE($U10,5) /* Open the file "test.csv" for the READ CSV FILE operation. */ $U200 = READ_CSV_STR($U100,2,4) /* Read the string in the field of row 2 and column 4 and save the result in the byte array starting at $U200. */ |
Need PM Designer itself?
V4 for current PK, PT, ITV and PM panels, V2 for older models. Free, sent by email.
Source.Section 15.4.16 of the PM Designer Software User Manual, Edition 2.0, © Cermate Technologies Inc. (www.cermate.com, service@cermate.com). Reproduced online, with the manual's own figures, by TSL Automation Solutions, authorised Cermate distributor, for users of Cermate HMI panels. PM Designer and PanelMaster are trademarks of Cermate Technologies Inc.
Text and figures are the manufacturer's and may describe features your panel or software version does not have. For a plain-language introduction read the PM Designer guide; for help with a specific panel contact TSL Automation.