diff --git a/tutorial/hello_world/hello_world.ipynb b/tutorial/hello_world/hello_world.ipynb index b1713a8c..1615d8d3 100644 --- a/tutorial/hello_world/hello_world.ipynb +++ b/tutorial/hello_world/hello_world.ipynb @@ -105,7 +105,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -123,12 +123,19 @@ " command = r'pnputil /enum-devices /bus PCI /deviceids '\n", " process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n", " stdout, stderr = process.communicate()\n", - " # Check for supported Hardware IDs\n", + " # Decode with error handling\n", " apu_type = ''\n", - " if 'PCI\\\\VEN_1022&DEV_1502&REV_00' in stdout.decode(): apu_type = 'PHX/HPT'\n", - " if 'PCI\\\\VEN_1022&DEV_17F0&REV_00' in stdout.decode(): apu_type = 'STX'\n", - " if 'PCI\\\\VEN_1022&DEV_17F0&REV_10' in stdout.decode(): apu_type = 'STX'\n", - " if 'PCI\\\\VEN_1022&DEV_17F0&REV_11' in stdout.decode(): apu_type = 'STX'\n", + " try: \n", + " stdout = stdout.decode('utf-8', errors='ignore') \n", + " except Exception as e: \n", + " # Log error message and return an empty string \n", + " print(f\"An error occurred while decoding output: {e}\") \n", + " return apu_type\n", + " # Check for supported Hardware IDs\n", + " if 'PCI\\\\VEN_1022&DEV_1502&REV_00' in stdout: apu_type = 'PHX/HPT' \n", + " if 'PCI\\\\VEN_1022&DEV_17F0&REV_00' in stdout: apu_type = 'STX' \n", + " if 'PCI\\\\VEN_1022&DEV_17F0&REV_10' in stdout: apu_type = 'STX' \n", + " if 'PCI\\\\VEN_1022&DEV_17F0&REV_11' in stdout: apu_type = 'STX' \n", " return apu_type\n", "\n", "apu_type = get_apu_info()\n", diff --git a/tutorial/hello_world/hello_world.py b/tutorial/hello_world/hello_world.py index b5703cd6..4408cfd0 100644 --- a/tutorial/hello_world/hello_world.py +++ b/tutorial/hello_world/hello_world.py @@ -121,12 +121,19 @@ def forward(self, x): command = r'pnputil /enum-devices /bus PCI /deviceids ' process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = process.communicate() + +# Decode with error handling +try: + stdout = stdout.decode('utf-8', errors='ignore') +except Exception as e: + # Log error message and return an empty string + print(f"An error occurred while decoding output: {e}") # Check for supported Hardware IDs apu_type = '' -if 'PCI\\VEN_1022&DEV_1502&REV_00' in stdout.decode(): apu_type = 'PHX/HPT' -if 'PCI\\VEN_1022&DEV_17F0&REV_00' in stdout.decode(): apu_type = 'STX' -if 'PCI\\VEN_1022&DEV_17F0&REV_10' in stdout.decode(): apu_type = 'STX' -if 'PCI\\VEN_1022&DEV_17F0&REV_11' in stdout.decode(): apu_type = 'STX' +if 'PCI\\VEN_1022&DEV_1502&REV_00' in stdout: apu_type = 'PHX/HPT' +if 'PCI\\VEN_1022&DEV_17F0&REV_00' in stdout: apu_type = 'STX' +if 'PCI\\VEN_1022&DEV_17F0&REV_10' in stdout: apu_type = 'STX' +if 'PCI\\VEN_1022&DEV_17F0&REV_11' in stdout: apu_type = 'STX' print(f"APU Type: {apu_type}")