Passed
Pull Request — master (#34)
by
unknown
03:16
created

PyDMXControl.controllers._serialController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 15
dl 0
loc 38
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A SerialController._send_data() 0 5 1
A SerialController.close() 0 4 1
A SerialController.__init__() 0 11 1
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
import serial as sr
9
import time as tm
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 = sr.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
35
        data = [0] + self.get_frame()
36
        self._port.write(bytearray(data))
37
        self._port.send_break(0.1)
38