Skip to content

Commit 12eae4d

Browse files
authored
Merge pull request #640 from jsee23/pcan-config-query
PCAN: add support for detecting available channels
2 parents 3023b70 + adcfe97 commit 12eae4d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

can/interfaces/pcan/pcan.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,55 @@ def state(self, new_state):
476476
self.m_PcanHandle, PCAN_LISTEN_ONLY, PCAN_PARAMETER_ON
477477
)
478478

479+
@staticmethod
480+
def _detect_available_configs():
481+
channels = []
482+
try:
483+
library_handle = PCANBasic()
484+
except OSError:
485+
return channels
486+
interfaces = []
487+
for i in range(16):
488+
interfaces.append(
489+
{
490+
"id": TPCANHandle(PCAN_PCIBUS1.value + i),
491+
"name": "PCAN_PCIBUS" + str(i + 1),
492+
}
493+
)
494+
for i in range(16):
495+
interfaces.append(
496+
{
497+
"id": TPCANHandle(PCAN_USBBUS1.value + i),
498+
"name": "PCAN_USBBUS" + str(i + 1),
499+
}
500+
)
501+
for i in range(2):
502+
interfaces.append(
503+
{
504+
"id": TPCANHandle(PCAN_PCCBUS1.value + i),
505+
"name": "PCAN_PCCBUS" + str(i + 1),
506+
}
507+
)
508+
for i in range(16):
509+
interfaces.append(
510+
{
511+
"id": TPCANHandle(PCAN_LANBUS1.value + i),
512+
"name": "PCAN_LANBUS" + str(i + 1),
513+
}
514+
)
515+
for i in interfaces:
516+
error, value = library_handle.GetValue(i["id"], PCAN_CHANNEL_CONDITION)
517+
if error != PCAN_ERROR_OK or value != PCAN_CHANNEL_AVAILABLE:
518+
continue
519+
has_fd = False
520+
error, value = library_handle.GetValue(i["id"], PCAN_CHANNEL_FEATURES)
521+
if error == PCAN_ERROR_OK:
522+
has_fd = bool(value & FEATURE_FD_CAPABLE)
523+
channels.append(
524+
{"interface": "pcan", "channel": i["name"], "supports_fd": has_fd}
525+
)
526+
return channels
527+
479528

480529
class PcanError(CanError):
481530
"""

0 commit comments

Comments
 (0)