Skip to content

Commit 9eeba4f

Browse files
author
Federico Bregant
committed
fix: conversion for port number
1 parent 796b525 commit 9eeba4f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

can/util.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,16 @@ def _create_bus_config(config: Dict[str, Any]) -> typechecking.BusConfig:
211211
raise CanInterfaceNotImplementedError(
212212
f'Unknown interface type "{config["interface"]}"'
213213
)
214-
214+
if "port" in config:
215+
if isinstance(config["port"], str):
216+
if config["port"].isnumeric():
217+
config["port"] = int(config["port"])
218+
if not 0 < config["port"] < 65535:
219+
raise ValueError("Port config must be inside 0-65535 range!")
220+
else:
221+
raise ValueError("Port config must be a number!")
222+
elif not isinstance(config["port"], int):
223+
raise TypeError("Port config must be string or integer!")
215224
if "bitrate" in config:
216225
config["bitrate"] = int(config["bitrate"])
217226
if "fd" in config:

0 commit comments

Comments
 (0)