optoKummenberg

Loading...
Searching...
No Matches
optoKummenberg.connections.Connection Class Reference

## Public Member Functions
| __init__ (self, str or None port, int baudrate, float inter_byte_timeout, bool comm_lock, float timeout, bool verbose=False, bool ethernet=False, str ip_address=None, int ethernet_port=5000)
| connect_serial (self)
| connect_ethernet (self)
| disconnect (self)
| flush (self)
| send (self, bytes data)
| receive (self, int length=500, bytes terminator=None)
| is_connected (self)

## Public Attributes
| verbose = verbose
| last_sent = None

## Static Protected Member Functions
| _read (serial_connection, int length=None, bytes terminator=None)

## Protected Attributes
| _port = port
| _baudrate = baudrate
| _inter_byte_timeout = inter_byte_timeout
| _comm_lock = comm_lock
| _timeout = timeout
| _is_ethernet = ethernet
| _ip_address = ip_address
| _ethernet_port = ethernet_port
| _ethernet_socket = None
| _serial_conn = None
| _settings = None

## 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]...

    Next example...
    >>> con = Connection(ip_address='10.0.89.25')
    Establish Connection via Ethernet

## Constructor & Destructor Documentation

## ◆ __init__()

optoKummenberg.connections.Connection.__init__ | ( |  | self,
|  | str or None | port,
|  | int | baudrate,
|  | float | inter_byte_timeout,
|  | bool | comm_lock,
|  | float | timeout,
|  | bool | verbose = False,
|  | bool | ethernet = False,
|  | str | ip_address = None,
|  | int | ethernet_port = 5000 )

## Member Function Documentation

## ◆ _read()

optoKummenberg.connections.Connection._read | ( |  | serial_connection,
|  | int | length = None,
|  | bytes | terminator = None )
| static protected

## ◆ connect_ethernet()

optoKummenberg.connections.Connection.connect_ethernet | ( |  | self | ) |

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

## ◆ connect_serial()

optoKummenberg.connections.Connection.connect_serial | ( |  | self | ) |

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

## ◆ disconnect()

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

    Terminates the connection with a given _board.

## ◆ flush()

optoKummenberg.connections.Connection.flush | ( |  | self | ) |

## ◆ is_connected()

optoKummenberg.connections.Connection.is_connected | ( |  | self | ) |

## ◆ receive()

optoKummenberg.connections.Connection.receive | ( |  | self,
|  | int | length = 500,
|  | 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.

## ◆ send()

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

    Send bytes array over connection.

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

    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

## ◆ _baudrate

optoKummenberg.connections.Connection._baudrate = baudrate
| protected

## ◆ _comm_lock

optoKummenberg.connections.Connection._comm_lock = comm_lock
| protected

## ◆ _ethernet_port

optoKummenberg.connections.Connection._ethernet_port = ethernet_port
| protected

## ◆ _ethernet_socket

optoKummenberg.connections.Connection._ethernet_socket = None
| protected

## ◆ _inter_byte_timeout

optoKummenberg.connections.Connection._inter_byte_timeout = inter_byte_timeout
| protected

## ◆ _ip_address

optoKummenberg.connections.Connection._ip_address = ip_address
| protected

## ◆ _is_ethernet

optoKummenberg.connections.Connection._is_ethernet = ethernet
| protected

## ◆ _port

optoKummenberg.connections.Connection._port = port
| protected

## ◆ _serial_conn

optoKummenberg.connections.Connection._serial_conn = None
| protected

## ◆ _settings

optoKummenberg.connections.Connection._settings = None
| protected

## ◆ _timeout

optoKummenberg.connections.Connection._timeout = timeout
| protected

## ◆ last_sent

optoKummenberg.connections.Connection.last_sent = None

## ◆ verbose

optoKummenberg.connections.Connection.verbose = verbose

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

- C:/git/142-421-00_optoKummenberg/src/main/python/optoKummenberg/connections.py