// C# binding for serial port services in libsimpleio.so
// Copyright (C)2017-2023, Philip Munts dba Munts Technologies.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
using System.Runtime.InteropServices;
namespace IO.Bindings
{
public static partial class libsimpleio
{
///
/// Disable parity checking.
///
public const int SERIAL_PARITY_NONE = 0;
///
/// Request even parity checking.
///
public const int SERIAL_PARITY_EVEN = 1;
///
/// Request odd parity checking.
///
public const int SERIAL_PARITY_ODD = 2;
///
/// Open a Linux serial port device.
///
/// Device node name.
/// Baud rate.
/// Parity setting (0 to 2).
/// Word size setting (5 to 8).
/// Number of stop bits (1 or 2).
/// File descriptor.
/// Error code. Zero upon success or an errno
/// value upon failure.
[DllImport("simpleio")]
public static extern void SERIAL_open(string devname, int baudrate,
int parity, int databits, int stopbits, out int fd, out int error);
///
/// Close a Linux serial port device.
///
/// File descriptor.
/// Error code. Zero upon success or an errno
/// value upon failure.
[DllImport("simpleio")]
public static extern void SERIAL_close(int fd, out int error);
///
/// Send data to a Linux serial port device.
///
/// File descriptor.
/// Source buffer.
/// Source buffer size.
/// Number of bytes actually sent.
/// Error code. Zero upon success or an errno
/// value upon failure.
[DllImport("simpleio")]
public static extern void SERIAL_send(int fd, byte[] buf, int bufsize,
out int count, out int error);
///
/// Receive data from a Linux serial port device.
///
/// File descriptor.
/// Destination buffer.
/// Destination buffer size.
/// Number of bytes actually received.
/// Error code. Zero upon success or an errno
/// value upon failure.
[DllImport("simpleio")]
public static extern void SERIAL_receive(int fd, byte[] buf,
int bufsize, out int count, out int error);
}
}