TSL Automation Solutions Logo

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.
File Operation P2 P3 Default Filename Format
Save Logged Data (.txt) 1 Data logger ID (0-15) DL<ID>_<Date>_<Time>.txt
Save Logged Data (.csv) 14 DL<ID>_<Date>_<Time>.csv
Save Logged Alarms (.txt) 2 0 AL_<Date>_<Time>.txt
Save Logged Alarms (.csv) 15 AL_<Date>_<Time>.csv
Save Alarm Counts (.txt) 3 0 AC_<Date>_<Time>.txt
Save Alarm Counts (.csv) 16 AC_<Date>_<Time>.csv
Save Recipe Data (.txt) 4 Recipe block ID (0-15) RB<ID>.txt
Save Recipe Data (.csv) 17 RB<ID>.csv
Save Recipe Data (.prd) 5 RB<ID>.prd
Read Recipe Data (.csv) 19 RB<ID>.csv
Read Recipe Data (.txt) 20 RB<ID>.txt
Read Recipe Data (.prd) 21 RB<ID>.prd
Print Screen to File (256-color .bmp) 6 Screen number (1-7999) S<ID>_<Date>_<Time>.bmp
Print Screen to File (64K-color .bmp) 7 S<ID>_<Date>_<Time>.bmp
Save Logged Operations (.txt) 9 0 OL_<Date>_<Time>.txt
Save Logged Operations (.csv) 18 0 OL_<Date>_<Time>.csv
Save Logged Data (.ldf) 10 Data logger ID (0-15) DL<ID>_<Date>_<Time>.ldf
Take Picture (.bmp) 12 USB camera ID (0-3) CAM<ID>_<Date>_<Time>.bmp
Take Picture (.jpg) 13 CAM<ID>_<Date>_<Time>.jpg
Print Screen to File (.jpg) 22 Screen number (1-7999) S<ID>_<Date>_<Time>.jpg
Take Picture for HMI units (.jpg) 23 Video Channel ID (1-2) V<ID>_<Date>_<Time>.jpg
Note:
<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.
File Operation P2 P3
Save Logged Data (.csv/.txt) 31 Data logger ID (0-15)
Save Logged Alarms (.txt) 32 0
Save Alarm Counts (.txt) 33 0
Save Recipe Data (.csv/.txt) 34 Recipe block ID (0-15)
Save Recipe Data (.prd) 35 Recipe block ID (0-15)
Print Screen to File (256-color .bmp) 36 Screen number (1-7999)
Print Screen to File (64K-color .bmp) 37 Screen number (1-7999)
Save Logged Operations (.txt) 39 0
Save Logged Data (.ldf) 40 Data logger ID (0-15)
Take Picture (.bmp) 42 USB camera ID (0-3)
Take Picture (.jpg) 43 USB camera ID (0-3)
Print Screen to File (.jpg) 52 Screen number (1-7999)
Take Picture for HMI units (.jpg) 53 Video channel ID (1-2)
Append Logged Data (in CSV/TXT format) 231 Data logger ID (0-15)
Append Logged Alarms 232 0
Append Logged Operations 239 0
Load Logged Data (in CSV/TXT format) Code ID of the file buffer that the loaded data will be stored Data logger ID (0-15)
1000 0
1001 1
1002 2
... ...
1015 15

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:
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
Read CSV File 5
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.
ID Drive
0 Current drive
3 Drive C
4 Drive D
5 Drive E
T
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:
Data Item Data Type/Size Word No.
Volume name Byte array with 32 elements 0 through 15
Volume size 32-bit Unsigned Integer 16 and 17
Free size 32-bit Unsigned Integer 18 and 19
Drive ID 16-bit Unsigned Integer 20
The volume name is a null-terminated character string. The maximum allowable size is 31 characters.
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.