# -*- coding: utf-8 -*-
"""High level wrapper for Serial resources.

This file is part of PyVISA.

:copyright: 2014-2020 by PyVISA Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.

"""
from .. import attributes, constants
from ..attributes import Attribute
from .messagebased import MessageBasedResource


@MessageBasedResource.register(constants.InterfaceType.asrl, "INSTR")
class SerialInstrument(MessageBasedResource):
    """Communicates with devices of type ASRL<board>[::INSTR]

    Do not instantiate directly, use
    :meth:`pyvisa.highlevel.ResourceManager.open_resource`.

    """

    #: Baud rate of the interface. The default value is 9600.
    baud_rate: Attribute[int] = attributes.AttrVI_ATTR_ASRL_BAUD()

    #: Number of data bits contained in each frame (from 5 to 8).
    data_bits: Attribute[int] = attributes.AttrVI_ATTR_ASRL_DATA_BITS()

    #: Parity used with every frame transmitted and received.
    parity: Attribute[constants.Parity] = attributes.AttrVI_ATTR_ASRL_PARITY()

    #: Number of stop bits used to indicate the end of a frame.
    stop_bits: Attribute[constants.StopBits] = attributes.AttrVI_ATTR_ASRL_STOP_BITS()

    #: Indicates the type of flow control used by the transfer mechanism.
    flow_control: Attribute[
        constants.ControlFlow
    ] = attributes.AttrVI_ATTR_ASRL_FLOW_CNTRL()

    #: Number of bytes available in the low- level I/O receive buffer.
    bytes_in_buffer: Attribute[int] = attributes.AttrVI_ATTR_ASRL_AVAIL_NUM()

    #: If set to True, NUL characters are discarded.
    discard_null: Attribute[bool] = attributes.AttrVI_ATTR_ASRL_DISCARD_NULL()

    #: Manually control transmission.
    allow_transmit: Attribute[bool] = attributes.AttrVI_ATTR_ASRL_ALLOW_TRANSMIT()

    #: Method used to terminate read operations.
    end_input: Attribute[
        constants.SerialTermination
    ] = attributes.AttrVI_ATTR_ASRL_END_IN()

    #: Method used to terminate write operations.
    end_output: Attribute[
        constants.SerialTermination
    ] = attributes.AttrVI_ATTR_ASRL_END_OUT()

    #: Duration (in milliseconds) of the break signal.
    break_length: Attribute[int] = attributes.AttrVI_ATTR_ASRL_BREAK_LEN()

    #: Manually control the assertion state of the break signal.
    break_state: Attribute[
        constants.LineState
    ] = attributes.AttrVI_ATTR_ASRL_BREAK_STATE()

    #: Character to be used to replace incoming characters that arrive with errors.
    replace_char: Attribute[str] = attributes.AttrVI_ATTR_ASRL_REPLACE_CHAR()

    #: XOFF character used for XON/XOFF flow control (both directions).
    xoff_char: Attribute[str] = attributes.AttrVI_ATTR_ASRL_XOFF_CHAR()

    #: XON character used for XON/XOFF flow control (both directions).
    xon_char: Attribute[str] = attributes.AttrVI_ATTR_ASRL_XON_CHAR()

@@ -815,16 +815,40 @@
 5 to 8).
+ The default value is 8.
 %0A    dat
@@ -974,16 +974,62 @@
 eceived.
+ The default value is None (VI_ASRL_PAR_NONE).
 %0A    par
@@ -1164,16 +1164,59 @@
 a frame.
+ The default value is 1 (VI_ASRL_STOP_ONE).
 %0A    sto
@@ -1369,16 +1369,70 @@
 chanism.
+ The default value%0A    #: is None (VI_ASRL_FLOW_NONE).
 %0A    flo
@@ -1735,16 +1735,38 @@
 scarded.
+ The default is False.
 %0A    dis
@@ -1875,16 +1875,43 @@
 mission.
+ The default value is True.
 %0A    all
@@ -2027,32 +2027,150 @@
 read operations.
+ The default method terminates by%0A    #: searching for %22/%22 appending the termination character (VI_ASRL_END_TERMCHAR).
 %0A    end_input: 
@@ -2311,16 +2311,136 @@
 rations.
+ The default method terminates%0A    #: when all requested data is transferred or when an error occurs (VI_ASRL_END_NONE).
 %0A    end
@@ -2588,32 +2588,58 @@
 he break signal.
+ The default value is 250.
 %0A    break_lengt
@@ -2763,16 +2763,65 @@
  signal.
+ The default state is%0A    #: VI_STATE_UNASSERTED.
 %0A    bre
@@ -3004,16 +3004,54 @@
 errors.%0A
+    #: The default character is '%5C0'.%0A
     repl
@@ -3189,24 +3189,64 @@
 irections).%0A
+    #: The default character is '0x13'.%0A
     xoff_cha
@@ -3373,24 +3373,64 @@
 irections).%0A
+    #: The default character is '0x11'.%0A
     xon_char

document the rest of the SerialInstrument attributes' default values