Skip to content

Commit a20af38

Browse files
committed
Implement CanProtocol for NiXNETcanBus
1 parent 652d5cc commit a20af38

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

can/interfaces/nixnet.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
import logging
1212
import os
1313
import time
14+
import warnings
1415
from queue import SimpleQueue
1516
from types import ModuleType
1617
from typing import Optional, List, Union, Tuple, Any
1718

1819
import can.typechecking
19-
from can import BusABC, Message, BitTiming, BitTimingFd
20+
from can import BusABC, Message, BitTiming, BitTimingFd, CanProtocol
2021
from can.exceptions import (
2122
CanInitializationError,
2223
CanOperationError,
@@ -103,10 +104,10 @@ def __init__(
103104

104105
self.poll_interval = poll_interval
105106

106-
self.fd = isinstance(timing, BitTimingFd) if timing else fd
107+
is_fd = isinstance(timing, BitTimingFd) if timing else fd
107108

108109
# Set database for the initialization
109-
database_name = ":can_fd_brs:" if self.fd else ":memory:"
110+
database_name = ":can_fd_brs:" if is_fd else ":memory:"
110111

111112
try:
112113
# We need two sessions for this application,
@@ -158,7 +159,7 @@ def __init__(
158159
if bitrate:
159160
self._interface.baud_rate = bitrate
160161

161-
if self.fd:
162+
if is_fd:
162163
# See page 951 of NI-XNET Hardware and Software Manual
163164
# to set custom can configuration
164165
self._interface.can_fd_baud_rate = fd_bitrate or bitrate
@@ -185,9 +186,19 @@ def __init__(
185186
channel=channel,
186187
can_filters=can_filters,
187188
bitrate=bitrate,
189+
protocol=CanProtocol.CAN_FD if is_fd else CanProtocol.CAN_20,
188190
**kwargs,
189191
)
190192

193+
@property
194+
def fd(self) -> bool:
195+
warnings.warn(
196+
"The NiXNETcanBus.fd property is deprecated and superseded by "
197+
"BusABC.protocol. It is scheduled for removal in version 5.0.",
198+
DeprecationWarning,
199+
)
200+
return self.protocol == CanProtocol.CAN_FD
201+
191202
def _recv_internal(
192203
self, timeout: Optional[float]
193204
) -> Tuple[Optional[Message], bool]:

0 commit comments

Comments
 (0)