Use this test after the three-file example appears as a drive. First read the files, then try one fixed-length write.
After programming, connect the board and wait for its drive to appear. Read DEMO.TXT and STATUS.CSV. The latter should contain two CSV lines followed by spaces. SETTINGS.BIN should contain 64 bytes, beginning with hexadecimal 01 32.
Use a write-in-place test. Many editors save by making a new temporary file and renaming it. That cannot work on this fixed-file drive. Use a program that opens the existing file and changes its bytes without changing its length.
This PowerShell example reads and overwrites the existing 64-byte DEMO.TXT. Replace E: with the PIC's drive letter, and close any editor using the file first. The new text is padded to exactly 64 bytes.
$path = 'E:\DEMO.TXT'
[Text.Encoding]::ASCII.GetString([IO.File]::ReadAllBytes($path))
$text = [Text.Encoding]::ASCII.GetBytes("Hello from the PC!`r`n")
if ($text.Length -gt 64) { throw 'Text must fit in 64 bytes.' }
$payload = New-Object byte[] 64
for ($i = 0; $i -lt 64; $i++) { $payload[$i] = 32 }
[Array]::Copy($text, $payload, $text.Length)
$stream = [IO.File]::Open(
$path, [IO.FileMode]::Open,
[IO.FileAccess]::ReadWrite, [IO.FileShare]::None)
try {
if ($stream.Length -ne 64) { throw 'Unexpected file length.' }
$stream.Position = 0
$stream.Write($payload, 0, $payload.Length)
$stream.Flush($true)
} finally {
$stream.Dispose()
}
FileMode.Open preserves the existing file. Do not replace it with a create or truncate mode. For binary settings, construct a 64-byte payload in the format your firmware expects, preserving any fields you do not intend to change.
Created with the Personal Edition of HelpNDoc: Elevate Your CHM Help Files with HelpNDoc's Advanced Customization Options