Skip to content

Fix Join-Path PowerShell syntax error#3

Merged
thompcd merged 13 commits intomainfrom
fix/join-path-error
Jan 2, 2026
Merged

Fix Join-Path PowerShell syntax error#3
thompcd merged 13 commits intomainfrom
fix/join-path-error

Conversation

@thompcd
Copy link
Owner

@thompcd thompcd commented Jan 2, 2026

PowerShell's Join-Path cmdlet only accepts 2 positional arguments (Path and ChildPath).
The script was attempting to pass 3 positional arguments which caused a syntax error.

Fixed by nesting the Join-Path calls:

  • Old: Join-Path $ReleaseRoot "source" "arduino"
  • New: Join-Path (Join-Path $ReleaseRoot "source") "arduino"

This resolves the error users encountered when running the upload script in v1.0.2.

thompcd added 13 commits January 2, 2026 00:22
The build_release.sh script places upload_firmware.ps1 in the tools/
subdirectory, but the batch file was looking for it in the root directory.
Updated batch file to reference tools\upload_firmware.ps1.
When multiple USB devices are detected, the device names were not displaying
properly, showing empty entries. Now displays the COM port number at minimum,
and includes the full device name if available.

This fixes the issue where users see empty device listings when connecting
multiple USB devices to their computer.
The script was looking for firmware in tools/arduino instead of
source/arduino. Updated to find the source folder relative to the
release package root directory.

Path now correctly resolves to: release_root/source/arduino/JudgeController
The pre-compiled firmware and flash scripts are untested and unused.
Only support the Arduino CLI compile-from-source upload method.

Changes:
- Remove firmware compilation from build_release.sh
- Remove flash_firmware.sh and flash_firmware.ps1
- Remove Flash Firmware (Windows).bat from release package
- Update build_release.sh to only include source code and upload tools
- Simplify UPLOAD_GUIDE.md to show only Arduino upload method
- Update README.txt template to reflect source-only approach
Join-Path only accepts 2 positional arguments. Nested the calls to properly
construct the path to the Arduino source directory.

Old: Join-Path $ReleaseRoot "source" "arduino"
New: Join-Path (Join-Path $ReleaseRoot "source") "arduino"
The batch file now checks for upload_firmware.ps1 in two locations:
1. tools/upload_firmware.ps1 (release package structure)
2. upload_firmware.ps1 (local repository structure)

This allows the batch file to work whether you're testing locally or
using the release package, and provides helpful error messages if the
script can't be found.
Changed port detection method to be more reliable:
1. Primary method: Use .NET SerialPort.GetPortNames() to reliably get COM ports
2. Friendly names: Query WMI for device descriptions when available
3. Fallback: Use WMI-only search if primary method fails

This ensures COM port numbers are always displayed, even if device names
are unavailable, fixing the empty device listing issue.
The previous inline if statement in Write-Host was causing the display
to show empty values. Changed to assign port/name to variables first,
then use them in Write-Host calls.

Also removed debug output now that we've verified port detection works.
Added defensive programming to handle different data structure types
and ensure port numbers are always displayed even if properties are
empty or missing. Falls back to 'COM?' if port is not found.
Simplified the function to:
1. Use .NET GetPortNames() as primary method (most reliable)
2. Build a map of port->device name from WMI for friendly names
3. Explicitly create port objects ensuring Port is always set
4. Use 'return , $ports' to properly return array without unwrapping
5. Fall back to WMI-only if GetPortNames fails

This should fix the empty Port values issue.
The path resolution now checks if source/arduino exists relative to the
script location to determine context:
- Local repo: upload_firmware.ps1 at root, arduino in source/arduino
- Release package: upload_firmware.ps1 in tools/, arduino in ../source/arduino

This fixes the 'Firmware folder not found' error when running from the repo.
Resolves merge conflicts by keeping improved path detection and device handling logic from fix/join-path-error branch:
- Fixed Join-Path 3-argument syntax error
- Added intelligent path detection for repo vs release contexts
- Improved device property access safety checks
- Better support for both hashtable and object returns
@thompcd thompcd merged commit 4734f8b into main Jan 2, 2026
1 check passed
@thompcd thompcd deleted the fix/join-path-error branch January 2, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant