winIDEA SDK
test_storage_emmc_read_write.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5import os
6
7import isystem.connect as ic
8
9
10winidea_id = ''
11
12
13def test_readWrite():
14 connMgr = ic.ConnectionMgr()
15 connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
16
17 devName = "eMMCtest"
18 partitionName = "Boot1"
19
20 storageCtrl = ic.CStorageDeviceFactory.makeDevice(connMgr, ic.EStorageDevice_EMMCDevice, devName, partitionName)
21
22 print(f"Writing 8 bytes to partition {partitionName}...")
23 wData = ic.VectorBYTE(32)
24 # dummy data, values from 0 to 31
25 for index in range(32):
26 wData[index] = index
27 storageCtrl.write(ic.IConnectUMI.wProgDevice, 0x0, 8, wData)
28
29 ic.CStorageDeviceFactory.terminateDevice(connMgr, ic.EStorageDevice_EMMCDevice, devName)
30
31 # OR
32
33 filePath = os.path.join(os.getcwd(), "data.bin")
34 print(f"Alternatively, write data from file: {filePath}")
35 try:
36 with open(filePath, "w+b") as fHandler:
37 fHandler.write(bytes("0123456789876543210", "utf-8"))
38 storageCtrl.write(ic.IConnectUMI.wProgDevice, ic.IConnectUMI.wFileFormatAuto, 0x0, filePath)
39 finally:
40 os.remove(filePath) # file cleanup
41
42 ic.CStorageDeviceFactory.terminateDevice(connMgr, ic.EStorageDevice_EMMCDevice, devName)
43
44
45if __name__ == "__main__":
46 test_readWrite()