SD write

 1'''
 2SD - SD_write.py with synchronous mode.
 3
 4This example demonstrates how to write a message in SD card from WifiDAQE3AOD.
 5
 6-------------------------------------------------------------------------------------
 7Please change correct serial number or IP and port number BEFORE you run example code.
 8
 9For other examples please check:
10    https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
11See README.md file to get detailed usage of this example.
12
13Copyright (c) 2022-2024 WPC Systems Ltd. All rights reserved.
14'''
15
16## Python
17import time
18
19## WPC
20
21from wpcsys import pywpc
22
23def main():
24    ## Get Python driver version
25    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
26
27    ## Create device handle
28    dev = pywpc.WifiDAQE3AOD()
29
30    ## Connect to device
31    try:
32        dev.connect("192.168.5.38") ## Depend on your device
33    except Exception as err:
34        pywpc.printGenericError(err)
35        ## Release device handle
36        dev.close()
37        return
38
39    try:
40        ## Parameters setting
41        filename = "WPC_test.txt"
42        write_data = "12345"
43        mode = 0 ## 0 : write, 1 : read
44        timeout = 3 ## second
45
46        ## Open file in sdcard
47        err = dev.SD_openFile(filename, mode, timeout)
48        print(f"SD_openFile, status: {err}")
49
50        ## Get sdcard storage
51        storage = dev.SD_getStorage(timeout)
52        print(f"SD_getStorage: {storage}")
53
54        ## Write data in sdcard
55        err = dev.SD_writeFile(write_data, timeout)
56        print(f"SD_writeFile, status: {err}")
57
58        ## Close file in sdcard
59        err = dev.SD_closeFile(timeout)
60        print(f"SD_closeFile, status: {err}")
61    except Exception as err:
62        pywpc.printGenericError(err)
63
64    ## Disconnect network device
65    dev.disconnect()
66
67    ## Release device handle
68    dev.close()
69
70    return
71if __name__ == '__main__':
72    main()