Skip to main content

File System

File access is standard .NET (System.IO.File, Directory, Stream) on the on-board storage, SD cards and USB drives. The Endpoint-specific GHIElectronics.Endpoint.Devices.Storage package handles the hot-plug events and mount folder for removable media.

  • On-board storage: always mounted and available to System.IO the moment your program starts. The partition at /data/ is where deployed applications live.
  • SD card: mounts at /media/sd/ when a card is present.
  • USB mass storage: each drive gets the next free /media/usbN/ folder, the same way Windows gives each one the next free drive letter.

SD card​

Open the SD-card controller, subscribe to ConnectionChanged, and mount the drive when it connects. Everything from System.IO then works against the returned path.

using GHIElectronics.Endpoint.Core;
using GHIElectronics.Endpoint.Devices.Storage;

var sd = StorageController.FromName(EPDomino24.StorageController.SdCard);

sd.ConnectionChanged += (sender, e) => {
if (e.DeviceStatus == DeviceConnectionStatus.Connected) {
var drive = FileSystem.Mount(e.Hdc); // "/media/sd/"
File.WriteAllText(Path.Combine(drive.Name, "log.txt"), "Hello SD");
FileSystem.Flush(e.Hdc); // write everything before unmount / pull
}
else {
Console.WriteLine("SD card removed");
}
};

sd.Enable(); // the card already in the slot is reported too

USB mass storage​

Same shape as above, with a different controller name. Multiple USB drives can be plugged in at once; each one fires ConnectionChanged with its own Hdc, and each mounts to its own /media/usbN/.

using GHIElectronics.Endpoint.Core;
using GHIElectronics.Endpoint.Devices.Storage;

var usb = StorageController.FromName(EPDomino24.StorageController.UsbHostMassStorage);

usb.ConnectionChanged += (sender, e) => {
if (e.DeviceStatus == DeviceConnectionStatus.Connected) {
var drive = FileSystem.Mount(e.Hdc); // "/media/usb0/", usb1, ...
Console.WriteLine($"Mounted {drive.Name}, label '{e.VolumeLabel}'");

foreach (var file in Directory.EnumerateFiles(drive.Name))
Console.WriteLine(file);
}
else {
Console.WriteLine("USB drive removed");
}
};

usb.Enable();
tip

Always call FileSystem.Flush(e.Hdc) after writing and before the drive is pulled out. On Endpoint, as on a PC, System.IO.DriveInfo.VolumeLabel returns the drive's mount folder rather than its label. Use e.VolumeLabel from the event to read the actual label.