RaspberryIO_26/Unosquare.WiringPi/Native/WiringPi.SerialPort.cs

68 lines
3.2 KiB
C#
Raw Normal View History

2019-12-06 21:09:52 +01:00
using System;
using System.Runtime.InteropServices;
namespace Unosquare.WiringPi.Native {
public partial class WiringPi {
/// <summary>
/// This opens and initialises the serial device and sets the baud rate. It sets the port into “raw” mode (character at a time and no translations),
/// and sets the read timeout to 10 seconds. The return value is the file descriptor or -1 for any error, in which case errno will be set as appropriate.
/// The wiringSerial library is intended to provide simplified control suitable for most applications, however if you need advanced control
/// e.g. parity control, modem control lines (via a USB adapter, there are none on the Pis on-board UART!) and so on,
/// then you need to do some of this the old fashioned way.
/// </summary>
/// <param name="device">The device.</param>
/// <param name="baud">The baud.</param>
/// <returns>The result.</returns>
[DllImport(WiringPiLibrary, EntryPoint = "serialOpen", SetLastError = true)]
public static extern Int32 SerialOpen(String device, Int32 baud);
/// <summary>
/// Closes the device identified by the file descriptor given.
/// </summary>
/// <param name="fd">The fd.</param>
/// <returns>The result.</returns>
[DllImport(WiringPiLibrary, EntryPoint = "serialClose", SetLastError = true)]
public static extern Int32 SerialClose(Int32 fd);
/// <summary>
/// Sends the single byte to the serial device identified by the given file descriptor.
/// </summary>
/// <param name="fd">The fd.</param>
/// <param name="c">The c.</param>
[DllImport(WiringPiLibrary, EntryPoint = "serialPutchar", SetLastError = true)]
public static extern void SerialPutchar(Int32 fd, Byte c);
/// <summary>
/// Sends the nul-terminated string to the serial device identified by the given file descriptor.
/// </summary>
/// <param name="fd">The fd.</param>
/// <param name="s">The s.</param>
[DllImport(WiringPiLibrary, EntryPoint = "serialPuts", SetLastError = true)]
public static extern void SerialPuts(Int32 fd, String s);
/// <summary>
/// Returns the number of characters available for reading, or -1 for any error condition,
/// in which case errno will be set appropriately.
/// </summary>
/// <param name="fd">The fd.</param>
/// <returns>The result.</returns>
[DllImport(WiringPiLibrary, EntryPoint = "serialDataAvail", SetLastError = true)]
public static extern Int32 SerialDataAvail(Int32 fd);
/// <summary>
/// Returns the next character available on the serial device.
/// This call will block for up to 10 seconds if no data is available (when it will return -1).
/// </summary>
/// <param name="fd">The fd.</param>
/// <returns>The result.</returns>
[DllImport(WiringPiLibrary, EntryPoint = "serialGetchar", SetLastError = true)]
public static extern Int32 SerialGetchar(Int32 fd);
/// <summary>
/// This discards all data received, or waiting to be send down the given device.
/// </summary>
/// <param name="fd">The fd.</param>
[DllImport(WiringPiLibrary, EntryPoint = "serialFlush", SetLastError = true)]
public static extern void SerialFlush(Int32 fd);
}
2019-12-04 18:57:18 +01:00
}