Passed
Push — master ( b12fa8...0be0f8 )
by Matt
01:31
created

SerialController.__init__()   A

Complexity

Conditions 1

Size

Total Lines 11
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 1
nop 4
1
"""
2
 *  PyDMXControl: A Python 3 module to control DMX using uDMX.
3
 *                Featuring fixture profiles, built-in effects and a web control panel.
4
 *  <https://github.com/MattIPv4/PyDMXControl/>
5
 *  Copyright (C) 2018 Matt Cowley (MattIPv4) ([email protected])
6
"""
7
8
from serial import Serial
9
import time
10
11
from ._transmittingController import transmittingController
12
13
14
class SerialController(transmittingController):
15
16
    def __init__(self, port, *args, **kwargs):
17
        """
18
        Serial port interface requires port string to establish connection, e.g. 'COM1' for
19
        windows operating systems.
20
21
        Parameters
22
        ----------
23
        port: Serial port string.
24
        """
25
        self._port = Serial(port=port, baudrate=250000, bytesize=8, stopbits=2)
26
        super().__init__(*args, **kwargs)
27
28
    def close(self):
29
        # Close serial port
30
        self._port.close()
31
        super().close()
32
33
    def _send_data(self):
34
        data = [0] + self.get_frame()
35
        self._port.send_break(100e-6)
36
        time.sleep(10e-6)
37
        self._port.write(bytearray(data))
38