Fixed pcan Unpack error by FedericoSpada · Pull Request #1767 · hardbyte/python-can

Conversation

@FedericoSpada

One of my colleagues encountered a "not enough values to unpack" error while scanning for connected dongles with PCAN drivers installed.
I couldn't replicate the error on my computer after installing the latest PCAN drivers. Still, analysing the instruction that raised that error, it seems that PCANBasic.GetValue() returned a wrong Tuple for a specific error condition.
That method must always return a Tuple with 2 elements, otherwise PcanBus._detect_available_configs() raises a "not enough values to unpack" error at line 718.

PCANBasic.GetValue() must always return a Tuple with 2 elements, otherwise PcanBus._detect_available_configs() raises a "not enough values to unpack" error at line 718.

zariiii9003

res = self.GetValue(Channel, PCAN_ATTACHED_CHANNELS_COUNT)
if TPCANStatus(res[0]) != PCAN_ERROR_OK:
return (TPCANStatus(res[0]),)
return TPCANStatus(res[0]), ()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return TPCANStatus(res[0]), ()
return TPCANStatus(res[0]), None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you expect to receive an Iterable, returning an empty tuple is better so you don't have to check if it is "None" before using it in a For loop.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the error case. There is no valid result, so it is not used here:

2 participants

@FedericoSpada @zariiii9003