Class Serial
Exposes methods to read from a serial transmission using bit-banging (software-based UART). Writing requires the use of the GpioWaveAddSerial(UserGpio, UInt32, UInt32, UInt32, UInt32, UInt32, Byte[]) method.
Inherited Members
Namespace: Unosquare.PiGpio.NativeMethods
Syntax
public static class Serial
Methods
GpioSerialRead(UserGpio, Byte[], Int32)
Wrapper for the native Unosquare.PiGpio.NativeMethods.Serial.GpioSerialReadUnmanaged(Unosquare.PiGpio.NativeEnums.UserGpio,System.Byte[],System.UInt32).
Declaration
public static int GpioSerialRead(UserGpio userGpio, byte[] buffer, int readLength)
Parameters
Type | Name | Description |
---|---|---|
UserGpio | userGpio | The user gpio. |
Byte[] | buffer | The buffer. |
Int32 | readLength | Length of the read. |
Returns
Type | Description |
---|---|
Int32 | The amount of bytes read. |
GpioSerialRead(UserGpio, Int32)
Wrapper for the native Unosquare.PiGpio.NativeMethods.Serial.GpioSerialReadUnmanaged(Unosquare.PiGpio.NativeEnums.UserGpio,System.Byte[],System.UInt32).
Declaration
public static byte[] GpioSerialRead(UserGpio userGpio, int readLength)
Parameters
Type | Name | Description |
---|---|---|
UserGpio | userGpio | The user gpio. |
Int32 | readLength | Length of the read. |
Returns
Type | Description |
---|---|
Byte[] | The array containing the bytes that were read. |
GpioSerialReadClose(UserGpio)
This function closes a GPIO for bit bang reading of serial data.
Declaration
public static ResultCode GpioSerialReadClose(UserGpio userGpio)
Parameters
Type | Name | Description |
---|---|---|
UserGpio | userGpio | 0-31, previously opened with GpioSerialReadOpen(UserGpio, UInt32, UInt32). |
Returns
Type | Description |
---|---|
ResultCode | Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO. |
GpioSerialReadInvert(UserGpio, Boolean)
This function configures the level logic for bit bang serial reads.
Use PI_BB_SER_INVERT to invert the serial logic and PI_BB_SER_NORMAL for normal logic. Default is PI_BB_SER_NORMAL.
The GPIO must be opened for bit bang reading of serial data using GpioSerialReadOpen(UserGpio, UInt32, UInt32) prior to calling this function.
Declaration
public static ResultCode GpioSerialReadInvert(UserGpio userGpio, bool invert)
Parameters
Type | Name | Description |
---|---|---|
UserGpio | userGpio | 0-31. |
Boolean | invert | 0-1. |
Returns
Type | Description |
---|---|
ResultCode | Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_GPIO_IN_USE, PI_NOT_SERIAL_GPIO, or PI_BAD_SER_INVERT. |
GpioSerialReadOpen(UserGpio, UInt32, UInt32)
This function opens a GPIO for bit bang reading of serial data.
The serial data is returned in a cyclic buffer and is read using GpioSerialRead(UserGpio, Int32).
It is the caller's responsibility to read data from the cyclic buffer in a timely fashion.
Declaration
public static ResultCode GpioSerialReadOpen(UserGpio userGpio, uint baudRate, uint dataBits)
Parameters
Type | Name | Description |
---|---|---|
UserGpio | userGpio | 0-31. |
UInt32 | baudRate | 50-250000. |
UInt32 | dataBits | 1-32. |
Returns
Type | Description |
---|---|
ResultCode | Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS, or PI_GPIO_IN_USE. |