Easy to use library for accessing the UART (serial interface). The library use the POSIX
functions from termios
on Linux and FreeBSD. So it should also be possible to use the
library on other *BSD. systems too, but currently not tested. In the UART_open()
function
the library setups the UART interface in raw and none-blocking mode currently on POSIX
compatible systems like Linux and FreeBSD. On Windows the UART library doesn't use
a none-blocking mode, because it's not supported by the used function CreateFile()
. The
library function UART_init()
tests if the user have sufficient permissions to use the UART
interfaces on Linux and FreeBSD. For Linux systems the user which uses the library
should be member from group dialout
and on FreeBSD from group dialer
, otherwise the
UART_init()
fails with the error UART_EPERM
.
Target/Configuration | Status |
---|---|
Linux/Default | |
Linux/Threading Support | |
Windows/Default | |
Windows/Threading Support |
The library is still under development and not fully tested. But most of the functions which are provided from the library should be working. If you investigate issue with the functions from the library please report them to the GitHub issue tracker for this repository.
- Linux
- FreeBSD
- Windows (cross building through MINGW currently)
- Supports up to 512 UART's
- Threading support (experimental)
- Add Visual Studio support (currently only cross building through MINGW is supported)
- Fully complete documentation (is for API version
0.1.x.x
, and therefore not valid)
If you find issues in the library please report them to the GitHub issue tracker for this repository.
- Git
- GNU make
- GNU binutils or LLVM binutils
- GCC or LLVM C compiler (clang)
- GCC-MINGW for cross building for Windows on Linux (target
x86_64-w64-mingw32-
) - Wine (only required if building for Windows)
pdflatex
(only required if the PDF documentation should be build)
$ sudo apt update
$ sudo apt install git wine binutils-mingw-w64-x86-64 gcc-mingw-w64-x86-64
The packages wine
, binutils-mingw-w64-x86-64
and gcc-mingw-w64-x86-64
are required
if building for Windows on Linux.
- Git
- GNU make (FreeBSD's make is currently not supported)
- LLVM binutils
- LLVM C compiler (clang)
pdflatex
(only required if the PDF documentation should be build)
$ pkg update
$ pkg install git
$ pkg install gmake
$ pkg install llvm
With the default configuration, the PDF documentation will not be build. But the API documentation is still available under doc/libUART.rst. Only the LaTeX PDF document will not be build.
$ ./configure
$ make
The created files can be found in the build
directory. The following files will be created:
UART.h
libUART.so
(Symbolic link tolibUART.so.0
)libUART.so.0
(Symbolic link tolibUART.so.0.2
)libUART.so.0.2
libUART.a
To build the library with PDF documentation generation, pass the option --enable-doc
to the
configure
script. The configure
also checks if the required application pdflatex
is
installed for building the PDF documentation.
$ ./configure --enable-doc
$ make
The created files can be found in the build
directory. The following files will be created:
UART.h
libUART.so
(Symbolic link tolibUART.so.0
)libUART.so.0
(Symbolic link tolibUART.so.0.2
)libUART.so.0.2
libUART.a
libUART.pdf
For cross building on Linux for Windows pass the option --target=windows
to
the configure
script.
$ ./configure --target=windows
$ make
The created files can be found in the build
directory. The following files will be created:
UART.h
libUART.dll
libUART.lib
libUART.pdf
if building with option--enable-doc
With the default configuration, the PDF documentation will not be build. But the API documentation is still available under doc/libUART.rst. Only the LaTeX PDF document will not be build.
$ ./configure
$ gmake
The created files can be found in the build
directory. The following files will be created:
UART.h
libUART.so
(Symbolic link tolibUART.so.0
)libUART.so.0
(Symbolic link tolibUART.so.0.2
)libUART.so.0.2
libUART.a
To build the library with PDF documentation generation, pass the option --enable-doc
to the
configure
script. The configure
also checks if the required application pdflatex
is
installed for building the PDF documentation.
$ ./configure --enable-doc
$ gmake
The created files can be found in the build
directory. The following files will be created:
UART.h
libUART.so
(Symbolic link tolibUART.so.0
)libUART.so.0
(Symbolic link tolibUART.so.0.2
)libUART.so.0.2
libUART.a
libUART.pdf
The default install path is under /usr/local
but can changed before building the library
with the configure
script. Pass the option --prefix=/path/to/install
to the script.
$ make install
Depending on the install path it is sometimes required to install the library as root user.
A short example how to use the library.
#include <UART.h>
int main(int c, char *argv[])
{
int ret;
uart_t *uart;
/* Initialize the library */
ret = UART_init();
if (ret != UART_ESUCCESS) {
return 1;
}
/* Open the UART port */
uart = UART_open("/dev/ttyS0", UART_BAUD_115200, "8N1N");
if (!uart) {
return 1;
}
/* Send something over the UART */
UART_puts(uart, "Hello World!\r\n");
/* Close the UART port */
UART_close(uart);
return 0;
}
Example if you want to link statically to the library, if the library isn't installed on your system.
$ gcc -I build -o test test.c build/libUART.a
Example if you want to link dynamically to the library if the library isn't installed on your system.
$ gcc -I build -o test test.c build/libUART.so
The documentation is currently not completed, but will finalize this later too. The current API (Application Programming Interface) can be found here (doc/libUART.rst).