Simple test

Mount a USB mass storage device to /usb_device in CircuitPython.

examples/usb_host_mass_storage_simpletest.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2023 Scott Shawcroft for Adafruit Industries
 3#
 4# SPDX-License-Identifier: Unlicense
 5
 6import os
 7import time
 8
 9import storage
10import usb.core
11
12import adafruit_usb_host_mass_storage
13
14device = None
15while device is None:
16    print("searching for devices")
17    for device in usb.core.find(find_all=True):
18        print("pid", hex(device.idProduct))
19        print("vid", hex(device.idVendor))
20        print("man", device.manufacturer)
21        print("product", device.product)
22        print("serial", device.serial_number)
23        break
24    if not device:
25        time.sleep(5)
26
27print("mounting")
28msc = adafruit_usb_host_mass_storage.USBMassStorage(device)
29vfs = storage.VfsFat(msc)
30storage.mount(vfs, "/usb_drive")
31
32l = os.listdir("/usb_drive")
33print(l)
34
35if "hello.txt" in l:
36    print("hello.txt:")
37    with open("/usb_drive/hello.txt") as f:
38        print(f.read())
39
40with open("/usb_drive/hello.txt", "w") as f:
41    f.write("Hello from the USB host device!")