Skip to content

Do not fail when XL_HardwareType is unknown #1297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions can/interfaces/vector/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ def popup_vector_hw_configuration(wait_for_finish: int = 0) -> None:
@staticmethod
def get_application_config(
app_name: str, app_channel: int
) -> Tuple[xldefine.XL_HardwareType, int, int]:
) -> Tuple[Union[int, xldefine.XL_HardwareType], int, int]:
"""Retrieve information for an application in Vector Hardware Configuration.

:param app_name:
Expand All @@ -702,26 +702,33 @@ def get_application_config(
if xldriver is None:
raise CanInterfaceNotImplementedError("The Vector API has not been loaded")

hw_type = ctypes.c_uint()
hw_index = ctypes.c_uint()
hw_channel = ctypes.c_uint()
_hw_type = ctypes.c_uint()
_hw_index = ctypes.c_uint()
_hw_channel = ctypes.c_uint()
_app_channel = ctypes.c_uint(app_channel)

xldriver.xlGetApplConfig(
app_name.encode(),
_app_channel,
hw_type,
hw_index,
hw_channel,
_hw_type,
_hw_index,
_hw_channel,
xldefine.XL_BusTypes.XL_BUS_TYPE_CAN,
)
return xldefine.XL_HardwareType(hw_type.value), hw_index.value, hw_channel.value

hw_type: Union[int, xldefine.XL_HardwareType]
try:
hw_type = xldefine.XL_HardwareType(_hw_type.value)
except ValueError:
hw_type = _hw_type.value

return hw_type, _hw_index.value, _hw_channel.value

@staticmethod
def set_application_config(
app_name: str,
app_channel: int,
hw_type: xldefine.XL_HardwareType,
hw_type: Union[int, xldefine.XL_HardwareType],
hw_index: int,
hw_channel: int,
**kwargs: Any,
Expand Down Expand Up @@ -783,7 +790,7 @@ def set_timer_rate(self, timer_rate_ms: int) -> None:

class VectorChannelConfig(NamedTuple):
name: str
hwType: xldefine.XL_HardwareType
hwType: Union[int, xldefine.XL_HardwareType]
hwIndex: int
hwChannel: int
channelIndex: int
Expand Down Expand Up @@ -811,9 +818,15 @@ def get_channel_configs() -> List[VectorChannelConfig]:
channel_list: List[VectorChannelConfig] = []
for i in range(driver_config.channelCount):
xlcc: xlclass.XLchannelConfig = driver_config.channel[i]

try:
hw_type = xldefine.XL_HardwareType(xlcc.hwType)
except ValueError:
hw_type = xlcc.hwType

vcc = VectorChannelConfig(
name=xlcc.name.decode(),
hwType=xldefine.XL_HardwareType(xlcc.hwType),
hwType=hw_type,
hwIndex=xlcc.hwIndex,
hwChannel=xlcc.hwChannel,
channelIndex=xlcc.channelIndex,
Expand Down