Skip to content

Wireless

Source code in src\eConEXG\triggerBox\triggerbox.py
 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
class triggerBoxWireless:
    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 == 0x6001 and ports.vid == 0x0403:
                    port = ports.device
                    break
            else:
                raise Exception("Trigger box not found")
        self.dev = Serial(port, baudrate=115200, timeout=1)
        self.__last_timestamp = time.perf_counter()
        self.__warn = "Marker interval too short, amplifier may fail to receive it. Suggested interval is above 50ms"
        time.sleep(0.1)

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

        Args:
            marker: range from `1` to `255`, `13` is not available and reserved for internal use.

        Raises:
            Exception: If the marker is invalid.
        """
        if time.perf_counter() - self.__last_timestamp < 0.04:
            print(self.__warn)
        if not isinstance(marker, int):
            marker = int(marker)
        if marker == 13 or marker <= 0 or marker > 255:
            raise Exception("Invalid marker")
        marker = marker.to_bytes(length=1, byteorder="big", signed=False)
        self.dev.write(marker + b"\x55\x66\x0d")
        self.__last_timestamp = time.perf_counter()

    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
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 == 0x6001 and ports.vid == 0x0403:
                port = ports.device
                break
        else:
            raise Exception("Trigger box not found")
    self.dev = Serial(port, baudrate=115200, timeout=1)
    self.__last_timestamp = time.perf_counter()
    self.__warn = "Marker interval too short, amplifier may fail to receive it. Suggested interval is above 50ms"
    time.sleep(0.1)

sendMarker(marker)

Send a marker to the trigger box.

Parameters:

Name Type Description Default
marker int

range from 1 to 255, 13 is not available and reserved for internal use.

required

Raises:

Type Description
Exception

If the marker is invalid.

Source code in src\eConEXG\triggerBox\triggerbox.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def sendMarker(self, marker: int):
    """
    Send a marker to the trigger box.

    Args:
        marker: range from `1` to `255`, `13` is not available and reserved for internal use.

    Raises:
        Exception: If the marker is invalid.
    """
    if time.perf_counter() - self.__last_timestamp < 0.04:
        print(self.__warn)
    if not isinstance(marker, int):
        marker = int(marker)
    if marker == 13 or marker <= 0 or marker > 255:
        raise Exception("Invalid marker")
    marker = marker.to_bytes(length=1, byteorder="big", signed=False)
    self.dev.write(marker + b"\x55\x66\x0d")
    self.__last_timestamp = time.perf_counter()