Skip to content

Commit 024b855

Browse files
committed
do not fail when XL_HardwareType is unknown
1 parent fe18a34 commit 024b855

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

can/interfaces/vector/canlib.py

+22-11
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ def popup_vector_hw_configuration(wait_for_finish: int = 0) -> None:
685685
@staticmethod
686686
def get_application_config(
687687
app_name: str, app_channel: int
688-
) -> Tuple[xldefine.XL_HardwareType, int, int]:
688+
) -> Tuple[Union[int, xldefine.XL_HardwareType], int, int]:
689689
"""Retrieve information for an application in Vector Hardware Configuration.
690690
691691
:param app_name:
@@ -702,26 +702,31 @@ def get_application_config(
702702
if xldriver is None:
703703
raise CanInterfaceNotImplementedError("The Vector API has not been loaded")
704704

705-
hw_type = ctypes.c_uint()
706-
hw_index = ctypes.c_uint()
707-
hw_channel = ctypes.c_uint()
705+
_hw_type = ctypes.c_uint()
706+
_hw_index = ctypes.c_uint()
707+
_hw_channel = ctypes.c_uint()
708708
_app_channel = ctypes.c_uint(app_channel)
709709

710710
xldriver.xlGetApplConfig(
711711
app_name.encode(),
712712
_app_channel,
713-
hw_type,
714-
hw_index,
715-
hw_channel,
713+
_hw_type,
714+
_hw_index,
715+
_hw_channel,
716716
xldefine.XL_BusTypes.XL_BUS_TYPE_CAN,
717717
)
718-
return xldefine.XL_HardwareType(hw_type.value), hw_index.value, hw_channel.value
718+
try:
719+
hw_type = xldefine.XL_HardwareType(_hw_type.value)
720+
except ValueError:
721+
hw_type = _hw_type.value
722+
723+
return hw_type, _hw_index.value, _hw_channel.value
719724

720725
@staticmethod
721726
def set_application_config(
722727
app_name: str,
723728
app_channel: int,
724-
hw_type: xldefine.XL_HardwareType,
729+
hw_type: Union[int, xldefine.XL_HardwareType],
725730
hw_index: int,
726731
hw_channel: int,
727732
**kwargs: Any,
@@ -783,7 +788,7 @@ def set_timer_rate(self, timer_rate_ms: int) -> None:
783788

784789
class VectorChannelConfig(NamedTuple):
785790
name: str
786-
hwType: xldefine.XL_HardwareType
791+
hwType: Union[int, xldefine.XL_HardwareType]
787792
hwIndex: int
788793
hwChannel: int
789794
channelIndex: int
@@ -811,9 +816,15 @@ def get_channel_configs() -> List[VectorChannelConfig]:
811816
channel_list: List[VectorChannelConfig] = []
812817
for i in range(driver_config.channelCount):
813818
xlcc: xlclass.XLchannelConfig = driver_config.channel[i]
819+
820+
try:
821+
hw_type = xldefine.XL_HardwareType(xlcc.hwType)
822+
except ValueError:
823+
hw_type = xlcc.hwType
824+
814825
vcc = VectorChannelConfig(
815826
name=xlcc.name.decode(),
816-
hwType=xldefine.XL_HardwareType(xlcc.hwType),
827+
hwType=hw_type,
817828
hwIndex=xlcc.hwIndex,
818829
hwChannel=xlcc.hwChannel,
819830
channelIndex=xlcc.channelIndex,

0 commit comments

Comments
 (0)