using System;
using System.Runtime.InteropServices;
namespace Unosquare.RaspberryIO.Native {
public partial class WiringPi {
#region WiringPi - Serial Port
///
/// 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 Pi’s on-board UART!) and so on,
/// then you need to do some of this the old fashioned way.
///
/// The device.
/// The baud.
/// The result
[DllImport(WiringPiLibrary, EntryPoint = "serialOpen", SetLastError = true)]
public static extern Int32 SerialOpen(String device, Int32 baud);
///
/// Closes the device identified by the file descriptor given.
///
/// The fd.
/// The result
[DllImport(WiringPiLibrary, EntryPoint = "serialClose", SetLastError = true)]
public static extern Int32 SerialClose(Int32 fd);
///
/// Sends the single byte to the serial device identified by the given file descriptor.
///
/// The fd.
/// The c.
[DllImport(WiringPiLibrary, EntryPoint = "serialPutchar", SetLastError = true)]
public static extern void SerialPutchar(Int32 fd, Byte c);
///
/// Sends the nul-terminated string to the serial device identified by the given file descriptor.
///
/// The fd.
/// The s.
[DllImport(WiringPiLibrary, EntryPoint = "serialPuts", SetLastError = true)]
public static extern void SerialPuts(Int32 fd, String s);
///
/// Returns the number of characters available for reading, or -1 for any error condition,
/// in which case errno will be set appropriately.
///
/// The fd.
/// The result
[DllImport(WiringPiLibrary, EntryPoint = "serialDataAvail", SetLastError = true)]
public static extern Int32 SerialDataAvail(Int32 fd);
///
/// 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)
///
/// The fd.
/// The result
[DllImport(WiringPiLibrary, EntryPoint = "serialGetchar", SetLastError = true)]
public static extern Int32 SerialGetchar(Int32 fd);
///
/// This discards all data received, or waiting to be send down the given device.
///
/// The fd.
[DllImport(WiringPiLibrary, EntryPoint = "serialFlush", SetLastError = true)]
public static extern void SerialFlush(Int32 fd);
#endregion
}
}