| optoMDC

Public Member Functions | Public Attributes | List of all members
optoKummenberg.connections.Connection Class Reference

## Public Member Functions
def | __init__ (self, str or None port, int baudrate, float inter_byte_timeout, bool comm_lock, float timeout, bool verbose)
def | __exit__ (self, exc_type, exc_val, exc_tb)
def | send (self, bytes data)
def | receive (self, int length=None, bytes terminator=None)
def | connect (self)
def | disconnect (self)

## Public Attributes
| verbose
| last_sent

## Detailed Description

    Connection object from which to connect/disconnect and send/receive data.

    For Serial Communication, See Also: PySerial API Documentation
        https://pyserial.readthedocs.io/en/latest/pyserial_api.html
    or use help(serial).

    Parameters
    ----------
    port : str or None
        The port is immediately opened on object creation, when a port is given.
        It is not opened when port is None and a successive call to open() is required.
        port is a device name: depending on operating system. e.g. /dev/ttyUSB0 on GNU/Linux or COM3 on Windows.
    baudrate : int
        The parameter baudrate can be one of the standard values:
        50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200.
        These are well supported on all platforms.
        Standard values above 115200, such as:
        230400, 460800, 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000, 4000000
        also work on many platforms and devices.
    comm_lock : bool = True
        Communication is disabled if this parameter is True, which is default. This prevents sending and receiving over
        the channel.
    timeout : float
        timeout = None: wait forever / until requested number of bytes are received
        timeout = 0: non-blocking mode, return immediately in any case, returning zero or more,
            up to the requested number of bytes
        timeout = x: set timeout to x seconds (float allowed) returns immediately when the requested
            number of bytes are available, otherwise wait until the timeout expires and return all
            bytes that were received until then.
    verbose : bool
        Verbose serial output for debugging/etc. If true, output generated even without parse_error/failures.

    Raises
    ------
    SerialException
        Unable to establish connection over given port.

    Notes
    -----
    To prevent communication issues, make sure that the comm_lock is False for only one device at a time.

    Examples
    --------
    Instantiate a connection on COM3, with baud rate 9600

    >>> con = Connection('COM3', 9600, verbose=True)
    Establishing Connection via port [COM3]...
    Connected.

## Constructor & Destructor Documentation

## ◆ __init__()

def optoKummenberg.connections.Connection.__init__ | ( |  | self,
|  | str or None | port,
|  | int | baudrate,
|  | float | inter_byte_timeout,
|  | bool | comm_lock,
|  | float | timeout,
|  | bool | verbose
| ) |  |

## Member Function Documentation

## ◆ __exit__()

def optoKummenberg.connections.Connection.__exit__ | ( |  | self,
|  |  | exc_type,
|  |  | exc_val,
|  |  | exc_tb
| ) |  |

## ◆ connect()

def optoKummenberg.connections.Connection.connect | ( |  | self | ) |

    Establish serial connection over port. Will reattempt up to 3 times.

    Parameters
    ----------
    none

    Returns
    -------
    none

    Raises
    ------
    SerialException

## ◆ disconnect()

def optoKummenberg.connections.Connection.disconnect | ( |  | self | ) |

    Terminates the connection with a given _board.

    Returns
    -------
    none

    Raises
    ------
    none

    Examples
    --------
    >>> con.disconnect()
    Flushing input-output buffers...
    Closing Connection...
    Disconnected.

## ◆ receive()

def optoKummenberg.connections.Connection.receive | ( |  | self,
|  | int | length = `None`,
|  | bytes | terminator = `None`
| ) |  |

    Receive bytes array over connection.

    Parameters
    ----------
    length : int, optional
        Return given number of bytes.
    terminator : bytes, optional
        The communication will proceed until the terminator is received.
        The remaining data will still exist in the firmware buffer.

    Returns
    -------
    bytes array
        Encoded byte array returned.

    Raises
    ------
    none

    Examples
    --------
    Assuming the 'gopro' command was just sent, a response will be transmitted by the MRE2 firmware.

    >>> con.receive()
    Received: b'OK\r\n'

## ◆ send()

def optoKummenberg.connections.Connection.send | ( |  | self,
|  | bytes | data
| ) |  |

    Send bytes array over connection.

    Parameters
    ----------
    data : bytes
        Bytes object to send.

    Returns
    -------
    none

    Raises
    ------
    none

    Notes
    -----
    Bytes must be properly encoded, see example.

    Examples
    --------
    First line: Set _board to pro mode.
    Second Line: Set value (0x10) of USB/UART (0x50) OF (0x00) registers to 0.
    Third Line: Same as above, without using encoder.

    >>> con = Connection('COM12', 9600, verbose=True)
    Establishing Connection via port [COM3]...
    Connected.
    >>> con._comm_lock = False
    >>> con.send('gopro\r\n'.encode())
    DEBUG: Sending 'b'gopro\r\n''
    >>> con.send(con.encode(0x10,0x5000,0))
    DEBUG: Sending 'b'~\x00\x10\x06P\x00\x00\x00\x00\x00\x00\x00~''
    >>> con.send(b'~\x00\x10\x06P\x00\x00\x00\x00\x00\x00\x00~')
    DEBUG: Sending 'b'~\x00\x10\x06P\x00\x00\x00\x00\x00\x00\x00~''

## Member Data Documentation

## ◆ last_sent

optoKummenberg.connections.Connection.last_sent

## ◆ verbose

optoKummenberg.connections.Connection.verbose

The documentation for this class was generated from the following file:

- C:/Users/johnathon.barhydt/PycharmProjects/138-882-00_optoMDC/src/main/python/optoKummenberg/connections.py