|
1 | 1 | import ctypes |
| 2 | +import logging |
2 | 3 | import usb.core |
3 | 4 | import time |
4 | 5 |
|
5 | 6 | from . import protocol |
6 | 7 |
|
| 8 | +logger = logging.getLogger(__name__) |
| 9 | + |
7 | 10 | # "Fast" lookups to go from channel to USB endpoint number |
8 | 11 | CHANNEL_TO_COMMAND_EP = [2, 4] # Command EP for channels 0,1 |
9 | 12 | CHANNEL_TO_MESSAGE_EP = [1, 3] # CAN Message EP for channels 0, 1 |
@@ -37,13 +40,29 @@ def __init__( |
37 | 40 | self._dev = devices[device_index] |
38 | 41 | self._dev.set_configuration(1) |
39 | 42 |
|
| 43 | + # Check this looks like the firmware we expect: as this is an unofficial driver, |
| 44 | + # we don't know if other versions might are out there. |
| 45 | + if self._dev.product != "Chuangxin Tech USBCAN/CANalyst-II": |
| 46 | + logger.warning( |
| 47 | + f"Unexpected USB product string: {self._dev.product}. Firmware version may be unsupported." |
| 48 | + ) |
| 49 | + interfaces = self._dev.get_active_configuration().interfaces() |
| 50 | + if len(interfaces) != 1: |
| 51 | + logger.warning( |
| 52 | + f"Unexpected interface count {len(interfaces)}. Firmware version may be unsupported." |
| 53 | + ) |
| 54 | + endpoints = interfaces[0].endpoints() |
| 55 | + # For whatever reason FW has 6 bidirectional BULK endpoints! |
| 56 | + if len(endpoints) != 12: |
| 57 | + logger.warning( |
| 58 | + f"Unexpected endpoint count {len(endpoints)}. Firmware version mayb e unsupported." |
| 59 | + ) |
| 60 | + |
40 | 61 | if bitrate is not None or timing0 is not None: |
41 | 62 | # if not specified, don't initialize yet |
42 | 63 | self.init(0, bitrate, timing0, timing1) |
43 | 64 | self.init(1, bitrate, timing0, timing1) |
44 | 65 |
|
45 | | - # TODO: check _dev properties match what we expect |
46 | | - |
47 | 66 | def clear_rx_buffer(self, channel): |
48 | 67 | """Clears the device's receive buffer for the specified channel. |
49 | 68 |
|
|
0 commit comments