File: structures.py

package info (click to toggle)
python-can 4.6.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,428 kB
  • sloc: python: 27,154; makefile: 32; sh: 16
file content (68 lines) | stat: -rw-r--r-- 1,971 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Contains Python equivalents of the structures in CANLIB's canlib.h,
with some supporting functionality specific to Python.
"""

import ctypes


class BusStatistics(ctypes.Structure):
    """This structure is used with the method
    :meth:`~can.interfaces.kvaser.canlib.KvaserBus.get_stats`.
    """

    _fields_ = [
        ("m_stdData", ctypes.c_ulong),
        ("m_stdRemote", ctypes.c_ulong),
        ("m_extData", ctypes.c_ulong),
        ("m_extRemote", ctypes.c_ulong),
        ("m_errFrame", ctypes.c_ulong),
        ("m_busLoad", ctypes.c_ulong),
        ("m_overruns", ctypes.c_ulong),
    ]

    def __str__(self):
        return (
            f"std_data: {self.std_data}, "
            f"std_remote: {self.std_remote}, "
            f"ext_data: {self.ext_data}, "
            f"ext_remote: {self.ext_remote}, "
            f"err_frame: {self.err_frame}, "
            f"bus_load: {self.bus_load / 100.0:.1f}%, "
            f"overruns: {self.overruns}"
        )

    @property
    def std_data(self):
        """Number of received standard (11-bit identifiers) data frames."""
        return self.m_stdData

    @property
    def std_remote(self):
        """Number of received standard (11-bit identifiers) remote frames."""
        return self.m_stdRemote

    @property
    def ext_data(self):
        """Number of received extended (29-bit identifiers) data frames."""
        return self.m_extData

    @property
    def ext_remote(self):
        """Number of received extended (29-bit identifiers) remote frames."""
        return self.m_extRemote

    @property
    def err_frame(self):
        """Number of error frames."""
        return self.m_errFrame

    @property
    def bus_load(self):
        """The bus load, expressed as an integer in the interval 0 - 10000 representing 0.00% - 100.00% bus load."""
        return self.m_busLoad

    @property
    def overruns(self):
        """Number of overruns."""
        return self.m_overruns