Skip to content
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

Fixed pcan Unpack error #1767

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

FedericoSpada
Copy link

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.
@@ -967,7 +967,7 @@ def GetValue(self, Channel, Parameter):
elif Parameter == PCAN_ATTACHED_CHANNELS:
res = self.GetValue(Channel, PCAN_ATTACHED_CHANNELS_COUNT)
if TPCANStatus(res[0]) != PCAN_ERROR_OK:
return (TPCANStatus(res[0]),)
return TPCANStatus(res[0]), ()
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Author

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.

Copy link
Collaborator

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:

return interfaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants