Skip to content

Wired

Source code in src\eConEXG\triggerBox\triggerbox.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
class triggerBoxWired:
    def __init__(self, port: str = None):
        """
        Args:
            port: The serial port of the trigger box. If not given,
                the function will try to find the trigger box automatically.

        Raises:
            Exception: If the trigger box is not found.
        """
        from serial import Serial
        from serial.tools.list_ports import comports

        if not port:
            for ports in comports():
                if ports.pid == 0x5740 and ports.vid == 0x0483:
                    port = ports.device
                    break
            else:
                raise Exception("Trigger box not found")
        self.dev = Serial(port, timeout=1)

    def sendMarker(self, marker: int):
        """
        Send a marker to the trigger box.

        Args:
            marker: range from `1` to `255`.

        Raises:
            Exception: If the marker is invalid.
        """
        if not isinstance(marker, int):
            marker = int(marker)
        if marker <= 0 or marker > 255:
            raise Exception("Invalid marker")
        self.dev.write(marker.to_bytes(length=1, byteorder="big", signed=False))

    def close_dev(self):
        self.dev.close()

__init__(port=None)

Parameters:

Name Type Description Default
port str

The serial port of the trigger box. If not given, the function will try to find the trigger box automatically.

None

Raises:

Type Description
Exception

If the trigger box is not found.

Source code in src\eConEXG\triggerBox\triggerbox.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def __init__(self, port: str = None):
    """
    Args:
        port: The serial port of the trigger box. If not given,
            the function will try to find the trigger box automatically.

    Raises:
        Exception: If the trigger box is not found.
    """
    from serial import Serial
    from serial.tools.list_ports import comports

    if not port:
        for ports in comports():
            if ports.pid == 0x5740 and ports.vid == 0x0483:
                port = ports.device
                break
        else:
            raise Exception("Trigger box not found")
    self.dev = Serial(port, timeout=1)

sendMarker(marker)

Send a marker to the trigger box.

Parameters:

Name Type Description Default
marker int

range from 1 to 255.

required

Raises:

Type Description
Exception

If the marker is invalid.

Source code in src\eConEXG\triggerBox\triggerbox.py
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def sendMarker(self, marker: int):
    """
    Send a marker to the trigger box.

    Args:
        marker: range from `1` to `255`.

    Raises:
        Exception: If the marker is invalid.
    """
    if not isinstance(marker, int):
        marker = int(marker)
    if marker <= 0 or marker > 255:
        raise Exception("Invalid marker")
    self.dev.write(marker.to_bytes(length=1, byteorder="big", signed=False))