Access to the drive’s SD card is possible from an MCi200 / MCi210 user application using the common ‘CAA File’ interface.
The ‘CT File Access’ library implements the following ‘CAA File’ function blocks for drive SD card access:
Function Block |
Inputs |
Outputs |
Remarks / implementation specific behaviour |
GetSize |
xExecute sFileName |
xDone xBusy xError eError szSize |
Will succeed only if no SD card file is open. It is recommended to determine the size of a file before opening the file for reading.
|
Open |
xExecute sFileName eFileMode xExclusive
|
xDone xBusy xError eError hFile |
eFileMode (CAA ‘MODE’ enum): MWRITE: Open file for writing with file pointer at start of file. MREAD: Open file for reading with file pointer at start of file. MRDWR: Open file for reading and writing with file pointer at start of file. MAPPD: Open file for writing with file pointer at end of file. (Append mode) |
Close |
xExecute hFile |
xDone xBusy xError eError |
|
Read |
xExecute xAbort udiTimeOut hFile pBuffer szBuffer
|
xDone xBusy xError xAborted eError szSize |
The timeout specified in udiTimeOut is in microseconds; some SD card operations can take a considerable amount of time, especially if a great deal of data is to be read in a low priority task. Please ensure that this timeout is adequate. |
Write |
xExecute xAbort udiTimeOut hFile pBuffer szSize |
xDone xBusy xError xAborted eError |
|
Delete |
xExecute sFileName |
xDone xBusy xError eError |
Will succeed only if no SD card file is open. File is specified by name, not by handle. |
SetPos |
xExecute hFile udiPos |
xDone xBusy xError eError |
The file must be open and a valid file handle obtained. Setting the file pointer beyond the end of a file will increase the size of the file; this can take a considerable time as padding data is written to the file. |
Notes / restrictions:
1) | Files without a prefix (e.g. “myfile.dat” will be routed to the local file system on the module. To access the drive SD card the file path should be “/sd/” followed by file name, e.g. “/sd/recipe01.dat”. Files with an unsupported prefix will fail. |
2) | Default path for file access is to the root of the SD card. |
3) | Folders cannot be created on the SD card from the MCi2x0 user application. (Though they can be seen and navigated from the MCi2x0 user application.) A folder can be created on the PC before inserting the card into the drive. |
4) | Only short (8.3) file names are supported by the drive. |
5) | Only one SD card file may be open at a time. Please note that this means from all devices / communications interfaces; if another option module has any SD card file open then the local option module will not be able to open a file. |
6) | The drive will close any file which is not accessed for approximately 5 seconds. Under such circumstances the file handle will become invalid and the file must be reopened before it can be used again. |
7) | SD card access operations may take a considerable (and variable) amount of time to complete and should therefore not be used from real-time cyclic tasks. |
8) | In addition to the library specific ‘eError’ codes defined in “CT File Access”->”CAA File”->”Enums”->”ERROR” the following error codes are possible: |
FS_NO_FILE 1 File does not exist or handle does not exist
FS_ILLEGALPOS 2 Invalid file position
Example usage in CT File Access