LF: SD File Functions

Use File Functions to:

  • Move and copy files between the SD card and a Disk On Key (DOK or USB stick) in one of the controller's USB ports.

  • Rename or delete files from the SD card.

  • Zip files on the SD card in zip or .gz format

  • Load a Config .ini file from the SD card, and run it in your application to modify specific parameters.

 

SD Folder Paths

Data Type

Folder

Syntax

Data Samples

Samples/XXX/History

/Samples/XXX/History/filename.ext

Data Tables

DT/

/DT/filename.ext

Audio

Media/Audio/

/Media/Audio/filename.ext

Video

Media/Video/

/Media/Video/filename.mp4

Docs

Media/Docs/

/Media/Docs/filename.ext

Screenshots

Media/Screenshots/

/Media/Screenshots/filename.jpg

User Logs

UserLogs/Bin/

/UserLogs/Bin/filename.bin

UserLogs/Csv/

/UserLogs/Csv/filename.csv

UserLogs/Txt/

/UserLogs/txt/filename.txt

Alarm Logs

AlarmLog/AlarmLogs/

/AlarmLog/AlarmLogs/filename.ext

 

Copy/Move File

Use this to copy or move a file from the SD card to the DOK, and vice-versa.

 

Parameter Name

Purpose

A

Action Type

The default type is Copy File From DOK to SD.

To change the default, click in the field, delete the text, and select another Actionclick in the field, delete the text, and select another Action.

The Actions are:

  • Copy File from SD to DOK

  • Copy File from DOK to SD

  • Move File from SD to DOK

  • Move File from DOK to SD

B

SD Folder Path

Link a tag and enter the path as a power-up value, or enter a value into the tag at run-time.

 The Action Copy File from DOK to SD is restricted to the folders DT and Media folders.

C

SD File Name

Assign a Data Tag or enter a constant. Note that you need to supply both the filename and the extension.

The name may not exceed 63 characters.

D

DOK Folder Path

Assign a Data Tag or enter a constant.

E

DOK File Name

Assign a Data Tag or enter a constant.

F

Overwrite

Determines if the file will overwrite a file of the same name

0= No

1= Yes

G

Status

0 = No Error

1 = Function started

2 = Function in progress

-1 = Invalid SD folder path

-2 = Invalid SD file name

-3 = Invalid DOK folder path

-4 = Invalid DOK file name

-5 = Request queue is full

-6 = No SD

-7 = No DOK

-8 = No Source file

-9 = No Free space on SD

-10 = No free space on DOK

-11 = File name already exists

-12 = File transfer error

-13 = Source file can't be deleted

-14 = Can't overwrite destination file

-15 = SD is read-only

-16 = DOK is read-only

-17 = Illegal SD folder (

-20 = Parameters Error

-21 = Internal error

 

Delete File

Use this to delete a file from the SD card.

 

Parameter Name

Purpose

A

SD Folder Path

Link a tag and enter the path as a power-up value, or enter a value into the tag at run-time.

B

SD File Name

This is the file to be deleted.

The name may not exceed 63 characters.

C

Overwrite

Determines if the file will overwrite a file of the same name

0= No

1= Yes

D

Status

0 = No Error

1 = Function started

2 = Function in progress

-1 = Invalid SD folder path

-5 = Request queue is full

-6 = No SD

-8 = No Source file

-13 = Source file cannot be deleted

-15 = SD is read-only

-20 = Parameters Error

-21 = Internal error

 

Read Line From File

Use this to read a line from a file on the SD card.

 

Parameter Name

Purpose

A

SD Folder Path

Link a tag and enter the path as a power-up value, or enter a value into the tag at run-time.
Include the file name in the path

B

Line Number: Source

This is the row the function reads.

Assign a Data Tag to provide the Line Number, or enter a number.

C

Destination Buffer

Select the target Buffer.

This is the Buffer the function writes the dats to.

D

Status

0 = No Error

1 = Function started

2 = Function in progress

-1 = No SD

-2 = File not found

-3 = Line in file not found

-4 = Internal error

-5 = File name too long

 

Zip File on SD

Locate a file in an SD folder, zip it in .zip or gz format, and place it in a destination folder on the SD.

 

Parameter Name

Purpose

A

SD Source Folder Path

Link a tag and enter the path as a power-up value, or enter a value into the tag at run-time.

B

Input File Name

This is the name of the SD file to zip. Assign a Data Tag or enter a constant.

The name may not exceed 63 characters.

C

SD Folder Path Output

Link a tag and enter the path as a power-up value, or enter a value into the tag at run-time.

D

Output File Name

This is the name for the zipped file. Assign a Data Tag or enter a constant.

The name may not exceed 63 characters.

E

Zip Format

This bit determines the zip file format. Assign a Data Tag or enter a constant.
0= No

1= Yes

F

Overwrite

Determines if the file will overwrite a file of the same name

0= .gz

1= .zip

G

Status

0 = No Error

1 = Function started

2 = Function in progress

-1 = Invalid SD folder path

-5 = Request queue is full

-6 = No SD

-8 = No Source file

-11 = File name already exists

-14 = Can't overwrite destination file

-15 = SD is read-only

-17 = Illegal SD folder

-18 = Invalid original file name

-19 = Invalid new file name

-20 = Parameters Error

-21 = Internal error

 

Load Config - .ini from SD

This Ladder function enables you to create an .ini file in a text editor and run it in your application to modify the parameters shown below.

Use this Function to zip a source file from an SD folder, into a destination folder on the SD.

Note that you can only run a maximum of two such functions during a single program scan.

File Syntax Example

Note that file begins with version 100.

[Version=100]

[EMAIL_ACCOUNTS:Account1]UserName=fyodordostoyevsky

[EMAIL_ACCOUNTS:Account1]OutgoingServerSettings=fedya.man.dd:1

[FTP_CLIENT:FTP Client1]UserName=PrinceMyshkin

[FTP_CLIENT:FTP Client1]Password=lee1987WWWnEW1

[FTP_CLIENT:dimanewclient]Password=lee1987WWW

[FTP_CLIENT:dimarnewclient]Port=1212

[FTP_CLIENT:dimanewclient]RemoteIp=10.1.30.252

[FTP_SERVER:FTP Server1]Password=fF1s3New1

[FTP_SERVER:FTP Server1]Port=23

 

Function

Editable Parameters

Email Accounts

User Name, Password, Outgoing Server Settings, From

FTP Client

User Name, Password, Port, Remote IP

FTP Server

User Name, Password, Port, Read Only

FTP RAM Server

User Name, Password, Port

Network Panel

IP Address, Subnet Mask, Default Gateway

COM Modbus

Baud Rate, Data Bit, Parity Bit, Stop Bit
Legal values:

BaudRate values: 1200/2400/4800/9600/19200/38400/57600/115200

[MODBUS_MASTER_TCP:SlaveName1]Ip=172.16.10.162

[MODBUS_MASTER_TCP:SlaveName2]Port=502

COM txrx/com

DataBit values:8/7/6/5

ParityBit values: N,E,O

StopBit values: 1,2

SQL Connector

This is case-sensitive. File syntax is as follows:

[SQL_CONNECTOR:SQL-Server_Connector]HostName=hostName

or 
[SQL_CONNECTOR:SQL-Server_Connector]IP=0.0.0.0

[SQL_CONNECTOR:SQL-Server_Connector]InstanceName=instanceName

[SQL_CONNECTOR:SQL-Server_Connector]DatabaseName=dbName

[SQL_CONNECTOR:SQL-Server_Connector]UserName=userName

[SQL_CONNECTOR:SQL-Server_Connector]Password=password

BACnet

[BACNET]InstanceNumber=1234

[BACNET]TcpIpPort=888

MQTT Broker

[MQTT_Broker:1]CAFileName=MyNewCA.pem 
[MQTT_Broker:1]ClientCertificateFileName=MyNewCert.crt 
[MQTT_Broker:1]ClientKeyFileName=MyNewKey.key 

 

Load Config - .ini from SD Ladder Element

 

Parameter Name

Purpose

A

Device

The default is SD. Click to select DOK.

B

Source Folder Path

Link a tag and enter the path as a power-up value, or enter a value into the tag at run-time.

C

*.ini File Name

This is the name of the .ini file. Assign a Data Tag or enter a constant.

The name may not exceed 63 characters.

D

Status

0 = No Error

1 = Function started

2 = Function in progress

-1 = Internal error - contact support

-2 = Internal error - contact support

-3 =  .ini file not found

-4 = .ini file version illegal

-5 = .ini file parsing delimiters error

-6 = Internal error - contact support

-7 = Illegal port configured as Modbus

-8 = Modbus port not found

-9 = Internal error - contact support

-10 = Illegal port configured as TxRx

-11 = TxRx port not found

-12 = Com syntax error

-13 = Com illegal value

-14 = Internal error - contact support

-15 = FTP client not found

-16 = FTP client syntax error

-17 = FTP client value error

-18 = Internal error - contact support

-19 = FTP server not found

-20 = FTP server syntax error

-21 = FTP server value error

-22 = Internal error - contact support

-23 = FTP RAM server not found

-24 = FTP RAM syntax error

-25 = FTP RAM server value error

-26 = Internal error - contact support

-27 = Network syntax error

-28 = Network value error

-29 = Internal error - contact support

-30 = Email account not found

-31 = Email account syntax error

-32 = Email account value error

-33 = IniFileSqlConnectorInternalError 

-34 = IniFileSqlConnectorNotFound  

-35 = IniFileESqlConnectorKeyError

-36 = IniFileESqlConnectorValueError

-37 = IniFileMqttBrokerGetCertsInternalError

-38 = IniFileMqttBrokerGetCertsNotFound  

-39 = IniFileEMqttBrokerGetCertsKeyError  

-40 = IniFileEMqttBrokerGetCertsValueError 

-41 = IniFileEMqttBrokerGetCertBadBrokerIdError

-42 = IniFileDNSInternalError 

-43 = IniFileDNSKeyError 

-44 = IniFileDNSValueError

-45 = IniFileBACNETInternalError

-46 = IniFileBACNETNotFound

-47 = IniFileBACNETKeyError

-48 = IniFileBACNETValueError

-53 = IniFileModbusMasterTcpInternalError

-54 = IniFileModbusMasterTcpKeyError

-55 = IniFileModbusMasterTcpSlaveNotFound

-56 = IniFileModbusMasterTcpPortError, Validation of port failed

-57 = IniFileModbusMasterTcpIpError, Validation of IP failed

 

Rename File

Use this to rename a file on the SD card.

Note that you cannot use this function to rename a file that is located in the Alarm Log folder

 

Parameter Name

Purpose

A

SD Folder Path

Link a tag and enter the path as a constant, power-up value, or enter a value into the tag at run-time.

B

Original File Name

This is the file to be renamed.

The name may not exceed 63 characters.

C

New File Name

The file will be renamed.

The name may not exceed 63 characters.

D

Status

0 = No Error

1 = Function started

2 = Function in progress

-1 = Invalid SD folder path

-5 = Request queue is full

-6 = No SD

-8 = No Source file

-11 = File name already exists

-14 = Can't overwrite destination file

-15 = SD is read-only

-17 = Illegal SD folder

-18 = Invalid original file name

-19 = Invalid new file name

-20 = Parameters Error

-21 = Internal error

 

Related Topics

LF: Update Application

SD Management