Current limitation: Only one file can be opened at a time.
Open a file named filename on the NPU file system, and return a NpufsFile object to access it. The NpufsFile object may be used as a context manager.
filename is a string with the name and path to the file on the file system. The file name must be compliant with standard filenames and paths with respect to the FAT32 format. This means that certain special characters, such as ‘:’, are prohibited.
mode is a string describing how to open the file: read, write, text, binary, append, etc. See the mode parameter of Python’s open() for details.
The supported 'mode' values are listed in the table below:
Mode |
Function read() |
Function write() |
Notes |
---|---|---|---|
r, rb, rt |
+ 1) |
- 2) |
|
r+, rb+, rt+ |
+ |
- |
|
w, wb, wt |
- |
+ |
|
w+, wb+, wt+ |
- |
+ |
Function read() not supported on TM NPU |
a, ab, at |
- |
- |
Not supported - will result in overwriting the file |
a+, ab+, at+ |
- |
- |
Not supported - will result in overwriting the file |
x |
- |
+ |
1) supported
2) not supported
Accessing the SD Card or FTP Server using npufs: In order to either access the SD Card or a FTP Server use the appropriate path as filename.
The TM NPU has a startup period for enabling all its services at the very beginning of the execution of the application. Therefore, ensure that the FTP Server can be accessed by delaying the ‘npufs.open()’ call. This can be realized by calling sleep prior to the ‘npufs.open()’ call. Another option is to retry the ‘npufs.open()’ procedure until the startup of the TM NPU is complete.
Only absolute paths are allowed to open files on SD Card or FTP Server.
The standard Python open() method is not available on the TM NPU. To access files on the TM NPU the user must instead use the TM NPU-specific module ‘npufs.open()’
Accessing the SD Card
To access files on the SD Card, use the npufs module.
PATH = SDCARDMOUNT = "/media/mmcsd-0-0/" |
with npufs.open(PATH + 'testFile.txt', 'r') as fp: |
Accessing the FTP Server
The FTP client functionality can be used by applying the npufs.open() function and providing the path information of the FTP Server as shown in the example below.
The configuration and setup of the FTP client in the TM NPU is done via the ‘ftpclient.conf’ config file which has to be present on the SD Card of the TM NPU. Details are described in the TM NPU User Manual.
The following parameters affect the ‘path’ parameter of npufs.open():
ftpclient.conf:
{ |
..., |
"server":"192.168.1.1", |
"localPath":"/SERVERROOT", |
..., |
} |
*SERVERROOT is not the root of the host system, but depends on the server configuration
Use the mapped path to access FTP server:
PATH = FTPMOUNT = "/SERVERROOT/testFolder/" |
with npufs.open(PATH + 'testFile.txt', 'r') as fp: |