Unosquare
    Show / Hide Table of Contents

    Class Uart

    Provides access to hardware based UART (Serial Port).

    Inheritance
    Object
    Uart
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unosquare.PiGpio.NativeMethods
    Syntax
    public static class Uart

    Methods

    SerClose(UIntPtr)

    This function closes the serial device associated with handle.

    Declaration
    public static ResultCode SerClose(UIntPtr handle)
    Parameters
    Type Name Description
    UIntPtr handle

    =0, as returned by a call to SerOpen(String, UartRate).

    Returns
    Type Description
    ResultCode

    Returns 0 if OK, otherwise PI_BAD_HANDLE.

    SerDataAvailable(UIntPtr)

    This function returns the number of bytes available to be read from the device associated with handle.

    otherwise PI_BAD_HANDLE.

    Declaration
    public static int SerDataAvailable(UIntPtr handle)
    Parameters
    Type Name Description
    UIntPtr handle

    =0, as returned by a call to SerOpen(String, UartRate).

    Returns
    Type Description
    Int32

    Returns the number of bytes of data available (>=0) if OK, otherwise PI_BAD_HANDLE.

    SerOpen(String, UartRate)

    This function opens a serial device at a specified baud rate and with specified flags. The device name must start with /dev/tty or /dev/serial.

    The baud rate must be one of 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, or 230400.

    No flags are currently defined. This parameter should be set to zero.

    Declaration
    public static UIntPtr SerOpen(string sertty, UartRate baud)
    Parameters
    Type Name Description
    String sertty

    the serial device to open.

    UartRate baud

    the baud rate in bits per second, see below.

    Returns
    Type Description
    UIntPtr

    Returns a handle (>=0) if OK, otherwise PI_NO_HANDLE, or PI_SER_OPEN_FAILED.

    SerRead(UIntPtr, Byte[], UInt32)

    This function reads up count bytes from the the serial port associated with handle and writes them to buf.

    If no data is ready zero is returned.

    Declaration
    public static int SerRead(UIntPtr handle, byte[] buffer, uint count)
    Parameters
    Type Name Description
    UIntPtr handle

    =0, as returned by a call to SerOpen(String, UartRate).

    Byte[] buffer

    an array to receive the read data.

    UInt32 count

    the maximum number of bytes to read.

    Returns
    Type Description
    Int32

    Returns the number of bytes read (>0=) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or PI_SER_READ_NO_DATA.

    SerReadByte(UIntPtr)

    This function reads a byte from the serial port associated with handle.

    If no data is ready PI_SER_READ_NO_DATA is returned.

    Declaration
    public static int SerReadByte(UIntPtr handle)
    Parameters
    Type Name Description
    UIntPtr handle

    =0, as returned by a call to SerOpen(String, UartRate).

    Returns
    Type Description
    Int32

    Returns the read byte (>=0) if OK, otherwise PI_BAD_HANDLE, PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED.

    SerWrite(UIntPtr, Byte[], UInt32)

    This function writes count bytes from buf to the the serial port associated with handle.

    PI_SER_WRITE_FAILED.

    Declaration
    public static ResultCode SerWrite(UIntPtr handle, byte[] buffer, uint count)
    Parameters
    Type Name Description
    UIntPtr handle

    =0, as returned by a call to SerOpen(String, UartRate).

    Byte[] buffer

    the array of bytes to write.

    UInt32 count

    the number of bytes to write.

    Returns
    Type Description
    ResultCode

    Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or PI_SER_WRITE_FAILED.

    SerWriteByte(UIntPtr, UInt32)

    This function writes bVal to the serial port associated with handle. PI_SER_WRITE_FAILED.

    Declaration
    public static ResultCode SerWriteByte(UIntPtr handle, uint byteValue)
    Parameters
    Type Name Description
    UIntPtr handle

    =0, as returned by a call to SerOpen(String, UartRate).

    UInt32 byteValue

    The byte value.

    Returns
    Type Description
    ResultCode

    Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or PI_SER_WRITE_FAILED.

    Comments

    Back to top Copyright © 2017-2019 Unosquare