In this document, it mainly introduces several methods related to read/write of QuecPython file, which are applicable to all modules that supporting QuecPython development.
Basic concept of file
The file will be used to save and store the data on some devices that embedded with long-term storage capability such as SSD, USB, Mobile SSD and disk.
File storage
The file is stored with a format of text or binary.
Text, such as the source program of Python
- Check via text editor
- It is still binary file in essence
Binary file, such as figure, audio and video.
- The saved contents can’t be read directly; however, it is provided to other SW.
- The binary file can’t be checked via test editor.
Basic operation of file
For detailed API, please refer to QuecPython- Standard Library-uio
File Operation function
File operation function
Function | Illustration | Method |
---|---|---|
Open | Open file and return file operation object | Be responsible for opening file and returning file operation object |
Read | Read file into memory | Call via file object |
Write | Write the assigned content into file | Call via file object |
Close | Close file | Call via file object |
Operate file and directory
Connect the QuecPython EVB to the PC. (It is default that all quick start operations have been done ). For further operations, please refer to Quectel_QuecPython_-Basic operation illustrations.
Figure 1: Connect the QuecPython EVB to PC
Open file via Read Only
Step 1: Create test_r.py and test_r.txt files, then write in following codes into test_r.py file. Meanwhile, input “hello python” in test_r.txt file.
Click to download test_r.py codes
Click to download test_r.txt file
- Import the uio module of QuecPython into test_r.py and write into codes
import uio # Open test_r.txt file via Read Only. fd = uio.open(“usr/test_r.txt”, mode=‘r’) # Read file contents text = fd.read() print(text) # Close file fd.close()
- Input " Hello Python " in test_r.txt.
Figure 2: Input " Hello Python" in test_r.txt.
Step 2: Upload contents of test_r.py and test_r.txt files into QuecPython EVB. For detailed method, please refer to Quectel_QuecPython_-Basic operation illustrations.
Step 3: Read the running result
Figure 3: Read the running result
Open the file via Write Only
Step 1: Create test_w.py file and its contents as empty test_w.txt file, then import the uio module of the QuenPython into test_w.py file.
Click to download test_w.py codes
Click to download test_w.txt file
import uio # Open test_w.txt file via Write Only fd = uio.open(“usr/test_w.txt”, mode=‘w’) # Write contents into file fd.write(“HELLO PYTHON”) # Close file fd.close()
Step 2: Refer to the above case as well as its steps to create one test_w_r.py file, then the written result will be achieved, please refer to following codes.
Click to download test_w_r.py codes
import uio # Open test_r.txt file via Read Only. fd = uio.open(“usr/test_w.txt”, mode=‘r’) # Read file contents text = fd.read() print(text) # Close file fd.close()
Step 3: Upload both the test_w.py file and the test_w.txt and test_w_r.py files into QuecPython EVB separately.First run test_w.py to write the data, and then run the test_w_r.py file to read the written data.The running results are as follows:
Figure 4: Writes file data and reads run results.
Open the file in write - only append mode
Step 1: Create test_a.py and test_a.txt files,and import the uio module in QuecPython in test_a.py.Type “hello python” in test_a.txt.
Click to download test_a.py file
Click to download test_a.txt file
- Import the uio module of the QuecPython into the test_a.py file.
import uio # Open test_a.txt file via append method fd = uio.open(“usr/test_a.txt”, mode=‘a’) # Write contents in file via append method. fd.write(“Hello Quectel”) # Close file fd.close() # Check the append result via Read Only. fd = uio.open(“usr/test_a.txt”, mode=‘r’) # Read file text = fd.read() print(text) # Close file fd.close()
- Input " hello python " into test_a.txt file.
Figure 5: Input " Hello Python" in test_a.txt.
Step 2: Upload contents of test_a.py and test_a.txt files into QuecPython EVB separately.
Step 3: Run codes and get append result.
Deploy uos module
For detailed API, please refer to QuecPython-Standard Library-uos。
List current files
Note: When filling parameters of different modules, they are varied in format. Take EC600U module as an example, which is shown as following figure. For EC600N, you just pay attention to uos.chdir(‘usr’).
Figure 6: List the current files
Build new directory
Note: When filling parameters of different modules, they are varied in format. Take EC600U module as an example, which is shown as following figure. For EC600N, you just pay attention to uos.mkdir(‘testdir’).
Figure 7: Build new directory
Delete directory
Figure 8: Delete directory
Note: The system_config.json serves as the default script file
Get ROM and RAM info of module
- Case codes
import gc import uos res = uos.statvfs(“/usr”) res = list(res) print(‘Get file system status:’, res) print(‘f_bsize – Size of file system block, the unit is byte’, res[0]) print(‘f_bfree – Free blocks:’, res[3]) print(‘Remaining space {} Byte’.format(res[0] * res[3])) print(‘Remaining space{} MB’.format((res[0] * res[3]) / 1024 / 1024)) mem = gc.mem_free() print(‘Available RAM space{} KB’.format(mem / 1024))
- Result of code running
Figure 9 : Get ROM and RAM info
Get read/write speed of file
For this aspect, it is still to be supplemented, no data temporarily.
Appendix: Term abbreviation
Tablet 3: Term Abbreviation
Abbreviation | Full name in English |
---|---|
API | Application Programming Interface |