• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hardbyte / python-can / 16362801995

18 Jul 2025 05:17AM UTC coverage: 70.862% (+0.1%) from 70.763%
16362801995

Pull #1920

github

web-flow
Merge f9e8a3c29 into 958fc64ed
Pull Request #1920: add FD support to slcan according to CANable 2.0 impementation

6 of 45 new or added lines in 1 file covered. (13.33%)

838 existing lines in 35 files now uncovered.

7770 of 10965 relevant lines covered (70.86%)

13.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.62
/can/interfaces/usb2can/serial_selector.py
1
""" """
21✔
2

3
import logging
21✔
4

5
log = logging.getLogger("can.usb2can")
21✔
6

7
try:
21✔
8
    import pythoncom
21✔
9
    import win32com.client
5✔
10
except ImportError:
16✔
11
    log.warning(
16✔
12
        "win32com.client module required for usb2can. Install the 'pywin32' package."
13
    )
14
    raise
16✔
15

16

17
def WMIDateStringToDate(dtmDate) -> str:
5✔
UNCOV
18
    if dtmDate[4] == 0:
×
19
        strDateTime = dtmDate[5] + "/"
×
20
    else:
UNCOV
21
        strDateTime = dtmDate[4] + dtmDate[5] + "/"
×
22

UNCOV
23
    if dtmDate[6] == 0:
×
24
        strDateTime = strDateTime + dtmDate[7] + "/"
×
25
    else:
UNCOV
26
        strDateTime = strDateTime + dtmDate[6] + dtmDate[7] + "/"
×
27
        strDateTime = (
×
28
            strDateTime
29
            + dtmDate[0]
30
            + dtmDate[1]
31
            + dtmDate[2]
32
            + dtmDate[3]
33
            + " "
34
            + dtmDate[8]
35
            + dtmDate[9]
36
            + ":"
37
            + dtmDate[10]
38
            + dtmDate[11]
39
            + ":"
40
            + dtmDate[12]
41
            + dtmDate[13]
42
        )
UNCOV
43
    return strDateTime
×
44

45

46
def find_serial_devices(serial_matcher: str = "") -> list[str]:
5✔
47
    """
48
    Finds a list of USB devices where the serial number (partially) matches the given string.
49

50
    :param serial_matcher:
51
        only device IDs starting with this string are returned
52
    """
53
    serial_numbers = []
5✔
54
    pythoncom.CoInitialize()
5✔
55
    wmi = win32com.client.GetObject("winmgmts:")
5✔
56
    for usb_controller in wmi.InstancesOf("Win32_USBControllerDevice"):
5✔
57
        usb_device = wmi.Get(usb_controller.Dependent)
×
58
        if "USB2CAN" in usb_device.Name:
×
59
            serial_numbers.append(usb_device.DeviceID.split("\\")[-1])
×
60

61
    if serial_matcher:
5✔
62
        return [sn for sn in serial_numbers if serial_matcher in sn]
×
63
    return serial_numbers
5✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc