From 6c9aa5794f55770a5dd636422bf8bbb89e0dec7f Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Tue, 1 Feb 2022 11:44:02 -0800 Subject: [PATCH 1/3] specify a code page on windows --- meshtastic/supported_device.py | 2 +- meshtastic/util.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/meshtastic/supported_device.py b/meshtastic/supported_device.py index e4d027d..02547b9 100755 --- a/meshtastic/supported_device.py +++ b/meshtastic/supported_device.py @@ -175,7 +175,7 @@ def detect_windows_port(sd): system = platform.system() if system == "Windows": - command = 'powershell.exe "Get-PnpDevice -PresentOnly | Where-Object{ ($_.DeviceId -like ' + command = 'powershell.exe /c chcp65001 "Get-PnpDevice -PresentOnly | Where-Object{ ($_.DeviceId -like ' command += f"'*{sd.usb_vendor_id_in_hex.upper()}*'" command += ')} | Format-List"' diff --git a/meshtastic/util.py b/meshtastic/util.py index c1a26b1..41884a0 100644 --- a/meshtastic/util.py +++ b/meshtastic/util.py @@ -297,7 +297,7 @@ def detect_supported_devices(): elif system == "Windows": # if windows, run Get-PnpDevice - _, sp_output = subprocess.getstatusoutput('powershell.exe "Get-PnpDevice -PresentOnly | Format-List"') + _, sp_output = subprocess.getstatusoutput('powershell.exe /c 65001 "Get-PnpDevice -PresentOnly | Format-List"') #print(f'sp_output:{sp_output}') vids = get_unique_vendor_ids() for vid in vids: @@ -365,7 +365,8 @@ def detect_windows_needs_driver(sd, print_reason=False): if system == "Windows": # if windows, see if we can find a DeviceId with the vendor id # Get-PnpDevice | Where-Object{ ($_.DeviceId -like '*10C4*')} | Format-List - command = 'powershell.exe "Get-PnpDevice | Where-Object{ ($_.DeviceId -like ' + # Note: Change '/c 65001' changes to code page 65001 which is mostly utf-8 + command = 'powershell.exe /c 65001 "Get-PnpDevice | Where-Object{ ($_.DeviceId -like ' command += f"'*{sd.usb_vendor_id_in_hex.upper()}*'" command += ')} | Format-List"' From 5241fabb33cc9a97d55ebb1e447b4c1c184db45a Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Tue, 1 Feb 2022 11:56:07 -0800 Subject: [PATCH 2/3] change encoding to utf8 for windows --- meshtastic/supported_device.py | 2 +- meshtastic/util.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/meshtastic/supported_device.py b/meshtastic/supported_device.py index 02547b9..3114288 100755 --- a/meshtastic/supported_device.py +++ b/meshtastic/supported_device.py @@ -175,7 +175,7 @@ def detect_windows_port(sd): system = platform.system() if system == "Windows": - command = 'powershell.exe /c chcp65001 "Get-PnpDevice -PresentOnly | Where-Object{ ($_.DeviceId -like ' + command = 'powershell.exe "[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8; Get-PnpDevice -PresentOnly | Where-Object{ ($_.DeviceId -like ' command += f"'*{sd.usb_vendor_id_in_hex.upper()}*'" command += ')} | Format-List"' diff --git a/meshtastic/util.py b/meshtastic/util.py index 41884a0..70150fe 100644 --- a/meshtastic/util.py +++ b/meshtastic/util.py @@ -297,7 +297,7 @@ def detect_supported_devices(): elif system == "Windows": # if windows, run Get-PnpDevice - _, sp_output = subprocess.getstatusoutput('powershell.exe /c 65001 "Get-PnpDevice -PresentOnly | Format-List"') + _, sp_output = subprocess.getstatusoutput('powershell.exe "[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8; Get-PnpDevice -PresentOnly | Format-List"') #print(f'sp_output:{sp_output}') vids = get_unique_vendor_ids() for vid in vids: @@ -365,8 +365,7 @@ def detect_windows_needs_driver(sd, print_reason=False): if system == "Windows": # if windows, see if we can find a DeviceId with the vendor id # Get-PnpDevice | Where-Object{ ($_.DeviceId -like '*10C4*')} | Format-List - # Note: Change '/c 65001' changes to code page 65001 which is mostly utf-8 - command = 'powershell.exe /c 65001 "Get-PnpDevice | Where-Object{ ($_.DeviceId -like ' + command = 'powershell.exe "[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8; Get-PnpDevice | Where-Object{ ($_.DeviceId -like ' command += f"'*{sd.usb_vendor_id_in_hex.upper()}*'" command += ')} | Format-List"' From ff5652058d13fb2a18a2ad24d2aef6b72b03cd6c Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Tue, 1 Feb 2022 12:00:58 -0800 Subject: [PATCH 3/3] fix lint complaining about long lines --- meshtastic/supported_device.py | 3 ++- meshtastic/util.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/meshtastic/supported_device.py b/meshtastic/supported_device.py index 3114288..0ae3d2c 100755 --- a/meshtastic/supported_device.py +++ b/meshtastic/supported_device.py @@ -175,7 +175,8 @@ def detect_windows_port(sd): system = platform.system() if system == "Windows": - command = 'powershell.exe "[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8; Get-PnpDevice -PresentOnly | Where-Object{ ($_.DeviceId -like ' + command = ('powershell.exe "[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8;' + 'Get-PnpDevice -PresentOnly | Where-Object{ ($_.DeviceId -like ') command += f"'*{sd.usb_vendor_id_in_hex.upper()}*'" command += ')} | Format-List"' diff --git a/meshtastic/util.py b/meshtastic/util.py index 70150fe..8d02ad9 100644 --- a/meshtastic/util.py +++ b/meshtastic/util.py @@ -297,7 +297,8 @@ def detect_supported_devices(): elif system == "Windows": # if windows, run Get-PnpDevice - _, sp_output = subprocess.getstatusoutput('powershell.exe "[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8; Get-PnpDevice -PresentOnly | Format-List"') + _, sp_output = subprocess.getstatusoutput('powershell.exe "[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8;' + 'Get-PnpDevice -PresentOnly | Format-List"') #print(f'sp_output:{sp_output}') vids = get_unique_vendor_ids() for vid in vids: