Skip to content
Merged
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/pcan/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ def GetValue(self, Channel, Parameter):

elif (
Parameter == PCAN_ACCEPTANCE_FILTER_11BIT
or PCAN_ACCEPTANCE_FILTER_29BIT
or Parameter == PCAN_ACCEPTANCE_FILTER_29BIT
):
mybuffer = c_int64(0)

Expand Down Expand Up @@ -1018,7 +1018,7 @@ def SetValue(self, Channel, Parameter, Buffer):
mybuffer = create_string_buffer(256)
elif (
Parameter == PCAN_ACCEPTANCE_FILTER_11BIT
or PCAN_ACCEPTANCE_FILTER_29BIT
or Parameter == PCAN_ACCEPTANCE_FILTER_29BIT
):
mybuffer = c_int64(0)
else:
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/2143.fixed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix PCAN parameter buffer sizes so only the 11-bit and 29-bit acceptance filters use 64-bit buffers.
42 changes: 41 additions & 1 deletion test/test_pcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import can
from can import BusState, CanProtocol
from can.exceptions import CanInitializationError
from can.interfaces.pcan import PcanBus, PcanError
from can.interfaces.pcan import PcanBus, PcanError, basic
from can.interfaces.pcan.basic import *


Expand Down Expand Up @@ -508,5 +508,45 @@ def test_constructor_bit_timing_fd(self):
self.assertTrue(b"data_sjw=1" in bitrate_arg)


@pytest.mark.parametrize(
"parameter,ctype,value",
[
(basic.PCAN_CHANNEL_CONDITION, ctypes.c_int, 3),
(basic.PCAN_DEVICE_ID, ctypes.c_int, 42),
(basic.PCAN_BUSOFF_AUTORESET, ctypes.c_int, 1),
(basic.PCAN_ACCEPTANCE_FILTER_11BIT, ctypes.c_int64, 0x123456789ABCDEF),
(basic.PCAN_ACCEPTANCE_FILTER_29BIT, ctypes.c_int64, 0x123456789ABCDEF),
(basic.PCAN_TRACE_LOCATION, ctypes.c_char * 256, b"/tmp/can-traces"),
],
)
@pytest.mark.parametrize("operation", ["get", "set"])
def test_parameter_buffer_type(parameter, ctype, value, operation):
api = basic.PCANBasic.__new__(basic.PCANBasic)
driver = Mock()
api._PCANBasic__m_dllBasic = driver

def transfer(channel, requested_parameter, buffer, size):
assert channel is basic.PCAN_USBBUS1
assert requested_parameter is parameter
assert size == ctypes.sizeof(ctype)
typed = ctypes.cast(buffer, ctypes.POINTER(ctype)).contents
if operation == "get":
typed.value = value
else:
assert typed.value == value
return basic.PCAN_ERROR_OK

if operation == "get":
driver.CAN_GetValue.side_effect = transfer
status, result = api.GetValue(basic.PCAN_USBBUS1, parameter)
assert result == value
driver.CAN_GetValue.assert_called_once()
else:
driver.CAN_SetValue.side_effect = transfer
status = api.SetValue(basic.PCAN_USBBUS1, parameter, value)
driver.CAN_SetValue.assert_called_once()
assert status == basic.PCAN_ERROR_OK


if __name__ == "__main__":
unittest.main()
Loading