serialport.h
#ifndef VN_SERIALPORT_H
#define VN_SERIALPORT_H
#include "vn/int.h"
#include "vn/error.h"
#include "vn/bool.h"
#include "vn/xplat/thread.h"
#include "vn/xplat/criticalsection.h"
#if defined(_WIN32)
/* Disable some warnings for Visual Studio with -Wall. */
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4668)
#pragma warning(disable:4820)
#pragma warning(disable:4255)
#endif
#include <Windows.h>
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#endif
#ifdef __linux__
#include <linux/serial.h>
#elif defined __APPLE__
#include <dirent.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*VnSerialPort_DataReceivedHandler)(void *userData);
#ifdef _WIN32
#pragma warning(push)
#pragma warning(disable : 4820)
#endif
typedef struct
{
#ifdef _WIN32
HANDLE handle;
/* Windows appears to need single-thread access to read/write API functions. */
VnCriticalSection readWriteCS;
#elif (defined __linux__ || defined __APPLE__ || defined __CYGWIN__ || defined __QNXNTO__)
int handle;
#else
#error "Unknown System"
#endif
bool purgeFirstDataBytesWhenSerialPortIsFirstOpened;
VnSerialPort_DataReceivedHandler dataReceivedHandler;
void *dataReceivedHandlerUserData;
VnThread serialPortNotificationsThread;
bool continueHandlingSerialPortEvents;
size_t numberOfReceiveDataDroppedSections;
VnCriticalSection dataReceivedHandlerCriticalSection;
char portName[50];
} VnSerialPort;
#ifdef _WIN32
#pragma warning(pop)
#endif
VnError VnSerialPort_initialize(VnSerialPort *serialport);
VnError VnSerialPort_open(VnSerialPort *serialport, char const *portName, uint32_t baudrate);
VnError VnSerialPort_close(VnSerialPort *serialport);
bool VnSerialPort_isOpen(VnSerialPort *serialport);
VnError VnSerialPort_read(VnSerialPort *serialport, char *buffer, size_t numOfBytesToRead, size_t *numOfBytesActuallyRead);
VnError VnSerialPort_write(VnSerialPort *serialport, char const *data, size_t numOfBytesToWrite);
VnError VnSerialPort_changeBaudrate(VnSerialPort *serialport, uint32_t baudrate);
VnError VnSerialPort_registerDataReceivedHandler(VnSerialPort *serialPort, VnSerialPort_DataReceivedHandler handler, void *userData);
VnError VnSerialPort_unregisterDataReceivedHandler(VnSerialPort *serialPort);
#ifdef __cplusplus
}
#endif
#endif
thread.h
VnSerialPort
Provides access to a serial port.
Definition: serialport.h:48
criticalsection.h
VnCriticalSection
Definition: criticalsection.h:38
VnThread
Structure for working with threads.
Definition: thread.h:40