Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions can/interfaces/kvaser/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,8 @@ def __init__(
canIoCtlInit(
self._read_handle,
canstat.canIOCTL_SET_LOCAL_TXACK,
ctypes.byref(ctypes.c_byte(local_echo)),
1,
ctypes.byref(ctypes.c_uint(local_echo)),
ctypes.sizeof(ctypes.c_uint),
)

if self.single_handle:
Expand Down
2 changes: 2 additions & 0 deletions doc/changelog.d/2050.fixed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Correct the Kvaser local transmit acknowledgement buffer type and size to match
CANlib's unsigned-integer argument.
29 changes: 29 additions & 0 deletions test/test_kvaser.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ def test_bus_creation(self):
self.assertTrue(canlib.canOpenChannel.called)
self.assertTrue(canlib.canBusOn.called)

def test_local_transmit_ioctl_buffer_types(self):
# CANlib defines TXECHO as an unsigned byte, but TXACK as unsigned int.
for single_handle in (False, True):
for receive_own_messages in (False, True):
with self.subTest(
single_handle=single_handle,
receive_own_messages=receive_own_messages,
):
canlib.canIoCtlInit.reset_mock()
with can.Bus(
channel=0,
interface="kvaser",
single_handle=single_handle,
receive_own_messages=receive_own_messages,
):
calls = {
call.args[1]: call.args
for call in canlib.canIoCtlInit.call_args_list
}
expected = int(single_handle or receive_own_messages)
for function, buffer_type in (
(constants.canIOCTL_SET_LOCAL_TXECHO, ctypes.c_byte),
(constants.canIOCTL_SET_LOCAL_TXACK, ctypes.c_uint),
):
_, _, buffer, length = calls[function]
self.assertEqual(length, ctypes.sizeof(buffer_type))
self.assertIsInstance(buffer._obj, buffer_type)
self.assertEqual(buffer._obj.value, expected)

def test_bus_creation_illegal_channel_name(self):
# Test if the bus constructor is able to deal with non-ASCII characters
def canGetChannelDataMock(
Expand Down
Loading