Skip to content

Commit c6da1c4

Browse files
committed
Reimplement PcanBus.fd attribute as read-only property
The property is scheduled for removal in v5.0
1 parent 642e711 commit c6da1c4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

can/interfaces/pcan/pcan.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
Enable basic CAN over a PCAN USB device.
33
"""
44
import logging
5+
import platform
56
import time
7+
import warnings
68
from datetime import datetime
7-
import platform
89
from typing import Optional, List, Tuple, Union, Any
910

1011
from packaging import version
@@ -70,7 +71,6 @@
7071
VALID_PCAN_CAN_CLOCKS,
7172
)
7273

73-
7474
# Set up logging
7575
log = logging.getLogger("can.pcan")
7676

@@ -658,6 +658,15 @@ def shutdown(self):
658658

659659
self.m_objPCANBasic.Uninitialize(self.m_PcanHandle)
660660

661+
@property
662+
def fd(self) -> bool:
663+
warnings.warn(
664+
"The PcanBus.fd property is deprecated and superseded by BusABC.protocol. "
665+
"It is scheduled for removal in version 5.0.",
666+
DeprecationWarning,
667+
)
668+
return self.protocol == CanProtocol.CAN_FD
669+
661670
@property
662671
def state(self):
663672
return self._state

test/test_pcan.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def test_bus_creation(self) -> None:
5454

5555
self.assertIsInstance(self.bus, PcanBus)
5656
self.assertEqual(self.bus.protocol, CanProtocol.CAN_20)
57+
self.assertFalse(self.bus.fd)
5758

5859
self.MockPCANBasic.assert_called_once()
5960
self.mock_pcan.Initialize.assert_called_once()
@@ -82,6 +83,7 @@ def test_bus_creation_fd(self, clock_param: str, clock_val: int) -> None:
8283

8384
self.assertIsInstance(self.bus, PcanBus)
8485
self.assertEqual(self.bus.protocol, CanProtocol.CAN_FD)
86+
self.assertTrue(self.bus.fd)
8587

8688
self.MockPCANBasic.assert_called_once()
8789
self.mock_pcan.Initialize.assert_not_called()

0 commit comments

Comments
 (0)