Add software
This commit is contained in:
29
Software/CubicSDR/external/rs232/README
vendored
Normal file
29
Software/CubicSDR/external/rs232/README
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
Cross-platform serial / RS232 library
|
||||
Version 0.21, 11/10/2015
|
||||
The MIT License (MIT)
|
||||
|
||||
Supported platforms:
|
||||
- Windows (XP / Win7, possibly 8 and 10)
|
||||
- Linux
|
||||
- MacOS X
|
||||
|
||||
Copyright (c) 2007 - 2015 Fr<46>d<EFBFBD>ric Meslin
|
||||
Contact: fredericmeslin@hotmail.com, @marzacdev
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
13
Software/CubicSDR/external/rs232/README.md
vendored
Normal file
13
Software/CubicSDR/external/rs232/README.md
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
# rs232
|
||||
C / C++ RS232 cross-platform serial library
|
||||
Version 0.21, 11/10/2015
|
||||
|
||||
Supported platforms:
|
||||
- Windows (XP / Win7, possibly 8 and 10)
|
||||
- Linux
|
||||
- MacOS X
|
||||
|
||||
Copyright (c) 2013-2015 Fr<46>d<EFBFBD>ric Meslin
|
||||
Email: fredericmeslin@hotmail.com
|
||||
Website: www.fredslab.net
|
||||
Twitter: @marzacdev
|
261
Software/CubicSDR/external/rs232/rs232-linux.cpp
vendored
Normal file
261
Software/CubicSDR/external/rs232/rs232-linux.cpp
vendored
Normal file
@ -0,0 +1,261 @@
|
||||
/*
|
||||
Cross-platform serial / RS232 library
|
||||
Version 0.21, 11/10/2015
|
||||
-> LINUX and MacOS implementation
|
||||
-> rs232-linux.c
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2015 Frédéric Meslin, Florent Touchard
|
||||
Email: fredericmeslin@hotmail.com
|
||||
Website: www.fredslab.net
|
||||
Twitter: @marzacdev
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#if defined(__unix__) || defined(__unix) || \
|
||||
defined(__APPLE__) && defined(__MACH__)
|
||||
|
||||
#define _DARWIN_C_SOURCE
|
||||
|
||||
#include "rs232.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#define __USE_MISC // For CRTSCTS
|
||||
#include <termios.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#define __USE_SVID // For strdup
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
/** Base name for COM devices */
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
static const char * devBases[] = {
|
||||
"tty."
|
||||
};
|
||||
static int noBases = 1;
|
||||
#else
|
||||
static const char * devBases[] = {
|
||||
"ttyACM", "ttyUSB", "rfcomm", "ttyS"
|
||||
};
|
||||
static int noBases = 4;
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
char * port;
|
||||
int handle;
|
||||
} COMDevice;
|
||||
|
||||
#define COM_MAXDEVICES 64
|
||||
static COMDevice comDevices[COM_MAXDEVICES];
|
||||
static int noDevices = 0;
|
||||
|
||||
/*****************************************************************************/
|
||||
/** Private functions */
|
||||
void _AppendDevices(const char * base);
|
||||
int _BaudFlag(int BaudRate);
|
||||
|
||||
/*****************************************************************************/
|
||||
int comEnumerate()
|
||||
{
|
||||
for (int i = 0; i < noDevices; i++) {
|
||||
if (comDevices[i].port) free(comDevices[i].port);
|
||||
comDevices[i].port = NULL;
|
||||
}
|
||||
noDevices = 0;
|
||||
for (int i = 0; i < noBases; i++)
|
||||
_AppendDevices(devBases[i]);
|
||||
return noDevices;
|
||||
}
|
||||
|
||||
void comTerminate()
|
||||
{
|
||||
comCloseAll();
|
||||
for (int i = 0; i < noDevices; i++) {
|
||||
if (comDevices[i].port) free(comDevices[i].port);
|
||||
comDevices[i].port = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int comGetNoPorts()
|
||||
{
|
||||
return noDevices;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int comFindPort(const char * name)
|
||||
{
|
||||
int p;
|
||||
for (p = 0; p < noDevices; p++)
|
||||
if (strcmp(name, comDevices[p].port) == 0)
|
||||
return p;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char * comGetInternalName(int index)
|
||||
{
|
||||
#define COM_MAXNAME 128
|
||||
static char name[COM_MAXNAME];
|
||||
if (index >= noDevices || index < 0)
|
||||
return NULL;
|
||||
sprintf(name, "/dev/%s", comDevices[index].port);
|
||||
return name;
|
||||
}
|
||||
|
||||
const char * comGetPortName(int index) {
|
||||
if (index >= noDevices || index < 0)
|
||||
return NULL;
|
||||
return comDevices[index].port;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int comOpen(int index, int baudrate)
|
||||
{
|
||||
if (index >= noDevices || index < 0)
|
||||
return 0;
|
||||
// Close if already open
|
||||
COMDevice * com = &comDevices[index];
|
||||
if (com->handle >= 0) comClose(index);
|
||||
// Open port
|
||||
printf("Try %s \n", comGetInternalName(index));
|
||||
int handle = open(comGetInternalName(index), O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
if (handle < 0)
|
||||
return 0;
|
||||
printf("Open %s \n", comGetInternalName(index));
|
||||
// General configuration
|
||||
struct termios config;
|
||||
memset(&config, 0, sizeof(config));
|
||||
tcgetattr(handle, &config);
|
||||
config.c_iflag &= ~(INLCR | ICRNL);
|
||||
config.c_iflag |= IGNPAR | IGNBRK;
|
||||
config.c_oflag &= ~(OPOST | ONLCR | OCRNL);
|
||||
config.c_cflag &= ~(PARENB | PARODD | CSTOPB | CSIZE | CRTSCTS);
|
||||
config.c_cflag |= CLOCAL | CREAD | CS8;
|
||||
config.c_lflag &= ~(ICANON | ISIG | ECHO);
|
||||
int flag = _BaudFlag(baudrate);
|
||||
cfsetospeed(&config, flag);
|
||||
cfsetispeed(&config, flag);
|
||||
// Timeouts configuration
|
||||
config.c_cc[VTIME] = 1;
|
||||
config.c_cc[VMIN] = 0;
|
||||
//fcntl(handle, F_SETFL, FNDELAY);
|
||||
// Validate configuration
|
||||
if (tcsetattr(handle, TCSANOW, &config) < 0) {
|
||||
close(handle);
|
||||
return 0;
|
||||
}
|
||||
com->handle = handle;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void comClose(int index)
|
||||
{
|
||||
if (index >= noDevices || index < 0)
|
||||
return;
|
||||
COMDevice * com = &comDevices[index];
|
||||
if (com->handle < 0)
|
||||
return;
|
||||
tcdrain(com->handle);
|
||||
close(com->handle);
|
||||
com->handle = -1;
|
||||
}
|
||||
|
||||
void comCloseAll()
|
||||
{
|
||||
for (int i = 0; i < noDevices; i++)
|
||||
comClose(i);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int comWrite(int index, const char * buffer, size_t len)
|
||||
{
|
||||
if (index >= noDevices || index < 0)
|
||||
return 0;
|
||||
if (comDevices[index].handle <= 0)
|
||||
return 0;
|
||||
int res = write(comDevices[index].handle, buffer, len);
|
||||
if (res < 0)
|
||||
res = 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
int comRead(int index, char * buffer, size_t len)
|
||||
{
|
||||
if (index >= noDevices || index < 0)
|
||||
return 0;
|
||||
if (comDevices[index].handle <= 0)
|
||||
return 0;
|
||||
int res = read(comDevices[index].handle, buffer, len);
|
||||
if (res < 0)
|
||||
res = 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int _BaudFlag(int BaudRate)
|
||||
{
|
||||
switch(BaudRate)
|
||||
{
|
||||
case 50: return B50; break;
|
||||
case 110: return B110; break;
|
||||
case 134: return B134; break;
|
||||
case 150: return B150; break;
|
||||
case 200: return B200; break;
|
||||
case 300: return B300; break;
|
||||
case 600: return B600; break;
|
||||
case 1200: return B1200; break;
|
||||
case 1800: return B1800; break;
|
||||
case 2400: return B2400; break;
|
||||
case 4800: return B4800; break;
|
||||
case 9600: return B9600; break;
|
||||
case 19200: return B19200; break;
|
||||
case 38400: return B38400; break;
|
||||
case 57600: return B57600; break;
|
||||
case 115200: return B115200; break;
|
||||
case 230400: return B230400; break;
|
||||
default : return B0; break;
|
||||
}
|
||||
}
|
||||
|
||||
void _AppendDevices(const char * base)
|
||||
{
|
||||
int baseLen = strlen(base);
|
||||
struct dirent * dp;
|
||||
// Enumerate devices
|
||||
DIR * dirp = opendir("/dev");
|
||||
while ((dp = readdir(dirp)) && noDevices < COM_MAXDEVICES) {
|
||||
if (strlen(dp->d_name) >= baseLen) {
|
||||
if (memcmp(base, dp->d_name, baseLen) == 0) {
|
||||
COMDevice * com = &comDevices[noDevices ++];
|
||||
com->port = (char *) strdup(dp->d_name);
|
||||
com->handle = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dirp);
|
||||
}
|
||||
|
||||
#endif // unix
|
253
Software/CubicSDR/external/rs232/rs232-win.cpp
vendored
Normal file
253
Software/CubicSDR/external/rs232/rs232-win.cpp
vendored
Normal file
@ -0,0 +1,253 @@
|
||||
/*
|
||||
Cross-platform serial / RS232 library
|
||||
Version 0.21, 11/10/2015
|
||||
-> WIN32 implementation
|
||||
-> rs232-win.c
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2015 Fr<46>d<EFBFBD>ric Meslin, Florent Touchard
|
||||
Email: fredericmeslin@hotmail.com
|
||||
Website: www.fredslab.net
|
||||
Twitter: @marzacdev
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include "rs232.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <Windows.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
int port;
|
||||
void * handle;
|
||||
} COMDevice;
|
||||
|
||||
/*****************************************************************************/
|
||||
#define COM_MAXDEVICES 64
|
||||
static COMDevice comDevices[COM_MAXDEVICES];
|
||||
static int noDevices = 0;
|
||||
|
||||
#define COM_MINDEVNAME 16384
|
||||
const char * comPtn = "COM???";
|
||||
|
||||
/*****************************************************************************/
|
||||
const char * findPattern(const char * string, const char * pattern, int * value);
|
||||
const char * portInternalName(int index);
|
||||
|
||||
/*****************************************************************************/
|
||||
int comEnumerate()
|
||||
{
|
||||
// Get devices information text
|
||||
size_t size = COM_MINDEVNAME;
|
||||
char * list = (char *) malloc(size);
|
||||
SetLastError(0);
|
||||
QueryDosDeviceA(NULL, list, size);
|
||||
while (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
||||
size *= 2;
|
||||
char * nlist = (char *) realloc(list, size);
|
||||
if (!nlist) {
|
||||
free(list);
|
||||
return 0;
|
||||
}
|
||||
list = nlist;
|
||||
SetLastError(0);
|
||||
QueryDosDeviceA(NULL, list, size);
|
||||
}
|
||||
// Gather all COM ports
|
||||
int port;
|
||||
const char * nlist = findPattern(list, comPtn, &port);
|
||||
noDevices = 0;
|
||||
while(port > 0 && noDevices < COM_MAXDEVICES) {
|
||||
COMDevice * com = &comDevices[noDevices ++];
|
||||
com->port = port;
|
||||
com->handle = 0;
|
||||
nlist = findPattern(nlist, comPtn, &port);
|
||||
}
|
||||
free(list);
|
||||
return noDevices;
|
||||
}
|
||||
|
||||
void comTerminate()
|
||||
{
|
||||
comCloseAll();
|
||||
}
|
||||
|
||||
int comGetNoPorts()
|
||||
{
|
||||
return noDevices;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
const char * comGetPortName(int index)
|
||||
{
|
||||
#define COM_MAXNAME 32
|
||||
static char name[COM_MAXNAME];
|
||||
if (index < 0 || index >= noDevices)
|
||||
return 0;
|
||||
sprintf(name, "COM%i", comDevices[index].port);
|
||||
return name;
|
||||
}
|
||||
|
||||
int comFindPort(const char * name)
|
||||
{
|
||||
for (int i = 0; i < noDevices; i++)
|
||||
if (strcmp(name, comGetPortName(i)) == 0)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char * comGetInternalName(int index)
|
||||
{
|
||||
#define COM_MAXNAME 32
|
||||
static char name[COM_MAXNAME];
|
||||
if (index < 0 || index >= noDevices)
|
||||
return 0;
|
||||
sprintf(name, "//./COM%i", comDevices[index].port);
|
||||
return name;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int comOpen(int index, int baudrate)
|
||||
{
|
||||
DCB config;
|
||||
COMMTIMEOUTS timeouts;
|
||||
if (index < 0 || index >= noDevices)
|
||||
return 0;
|
||||
// Close if already open
|
||||
COMDevice * com = &comDevices[index];
|
||||
if (com->handle) comClose(index);
|
||||
// Open COM port
|
||||
void * handle = CreateFileA(comGetInternalName(index), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
return 0;
|
||||
com->handle = handle;
|
||||
// Prepare read / write timeouts
|
||||
SetupComm(handle, 64, 64);
|
||||
timeouts.ReadIntervalTimeout = MAXDWORD;
|
||||
timeouts.ReadTotalTimeoutConstant = 0;
|
||||
timeouts.WriteTotalTimeoutConstant = 0;
|
||||
timeouts.ReadTotalTimeoutMultiplier = 0;
|
||||
timeouts.WriteTotalTimeoutMultiplier = 0;
|
||||
SetCommTimeouts(handle, &timeouts);
|
||||
// Prepare serial communication format
|
||||
GetCommState(handle, &config);
|
||||
config.BaudRate = baudrate;
|
||||
config.fBinary = true;
|
||||
config.fParity = 0;
|
||||
config.fErrorChar = 0;
|
||||
config.fNull = 0;
|
||||
config.fAbortOnError = 0;
|
||||
config.ByteSize = 8;
|
||||
config.Parity = 0;
|
||||
config.StopBits = 0;
|
||||
config.EvtChar = '\n';
|
||||
// Set the port state
|
||||
if (SetCommState(handle, &config) == 0) {
|
||||
CloseHandle(handle);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void comClose(int index)
|
||||
{
|
||||
if (index < 0 || index >= noDevices)
|
||||
return;
|
||||
COMDevice * com = &comDevices[index];
|
||||
if (!com->handle)
|
||||
return;
|
||||
CloseHandle(com->handle);
|
||||
com->handle = 0;
|
||||
}
|
||||
|
||||
void comCloseAll()
|
||||
{
|
||||
for (int i = 0; i < noDevices; i++)
|
||||
comClose(i);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int comWrite(int index, const char * buffer, size_t len)
|
||||
{
|
||||
if (index < 0 || index >= noDevices)
|
||||
return 0;
|
||||
COMDevice * com = &comDevices[index];
|
||||
uint32_t bytes = 0;
|
||||
WriteFile(com->handle, buffer, len, (LPDWORD)&bytes, NULL);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
int comRead(int index, char * buffer, size_t len)
|
||||
{
|
||||
if (index < 0 || index >= noDevices)
|
||||
return 0;
|
||||
COMDevice * com = &comDevices[index];
|
||||
uint32_t bytes = 0;
|
||||
ReadFile(com->handle, buffer, len, (LPDWORD)&bytes, NULL);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
const char * findPattern(const char * string, const char * pattern, int * value)
|
||||
{
|
||||
char c, n = 0;
|
||||
const char * sp = string;
|
||||
const char * pp = pattern;
|
||||
// Check for the string pattern
|
||||
while (1) {
|
||||
c = *sp ++;
|
||||
if (c == '\0') {
|
||||
if (*pp == '?') break;
|
||||
if (*sp == '\0') break;
|
||||
n = 0;
|
||||
pp = pattern;
|
||||
}else{
|
||||
if (*pp == '?') {
|
||||
// Expect a digit
|
||||
if (c >= '0' && c <= '9') {
|
||||
n = n * 10 + (c - '0');
|
||||
if (*pp ++ == '\0') break;
|
||||
}else{
|
||||
n = 0;
|
||||
pp = comPtn;
|
||||
}
|
||||
}else{
|
||||
// Expect a character
|
||||
if (c == *pp) {
|
||||
if (*pp ++ == '\0') break;
|
||||
}else{
|
||||
n = 0;
|
||||
pp = comPtn;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Return the value
|
||||
* value = n;
|
||||
return sp;
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
156
Software/CubicSDR/external/rs232/rs232.h
vendored
Normal file
156
Software/CubicSDR/external/rs232/rs232.h
vendored
Normal file
@ -0,0 +1,156 @@
|
||||
/*
|
||||
Cross-platform serial / RS232 library
|
||||
Version 0.21, 11/10/2015
|
||||
-> All platforms header
|
||||
-> rs232.h
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2015 Fr<46>d<EFBFBD>ric Meslin, Florent Touchard
|
||||
Email: fredericmeslin@hotmail.com
|
||||
Website: www.fredslab.net
|
||||
Twitter: @marzacdev
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef RS232_H
|
||||
#define RS232_H
|
||||
|
||||
// TODO: convert to C++ class
|
||||
//#ifdef __cplusplus
|
||||
//extern "C" {
|
||||
//#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Doxywizard specific */
|
||||
/**
|
||||
* \mainpage RS232
|
||||
* \section intro_sec C / C++ RS232 cross-platform serial library
|
||||
* <b>Version 0.21 - 11/10/2015</b>
|
||||
*
|
||||
* Supported platforms:
|
||||
* - Windows (XP / Win7, possibly 8 and 10)
|
||||
* - Linux
|
||||
* - MacOS X
|
||||
*
|
||||
* Copyright (c) 2013-2015 Frédéric Meslin, Florent Touchard <br>
|
||||
* Email: fredericmeslin@hotmail.com <br>
|
||||
* Website: www.fredslab.net <br>
|
||||
* Twitter: \@marzacdev <br>
|
||||
*/
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* \fn int comEnumerate()
|
||||
* \brief Enumerate available serial ports (Serial, USB serial, Bluetooth serial)
|
||||
* \return number of enumerated ports
|
||||
*/
|
||||
int comEnumerate();
|
||||
|
||||
/**
|
||||
* \fn int comGetNoPorts()
|
||||
* \brief Return the number of enumerated ports
|
||||
* \return number of enumerated ports
|
||||
*/
|
||||
int comGetNoPorts();
|
||||
|
||||
/**
|
||||
* \fn int comTerminate()
|
||||
* \brief Release ports and memory resources used by the library
|
||||
*/
|
||||
void comTerminate();
|
||||
|
||||
/**
|
||||
* \fn const char * comGetPortName(int index)
|
||||
* \brief Get port user-friendly name
|
||||
* \param[in] index port index
|
||||
* \return null terminated port name
|
||||
*/
|
||||
const char * comGetPortName(int index);
|
||||
|
||||
/**
|
||||
* \fn const char * comGetInternalName(int index)
|
||||
* \brief Get port operating-system name
|
||||
* \param[in] index port index
|
||||
* \return null terminated port name
|
||||
*/
|
||||
const char * comGetInternalName(int index);
|
||||
|
||||
/**
|
||||
* \fn int comFindPort(const char * name)
|
||||
* \brief Try to find a port given its user-friendly name
|
||||
* \param[in] name port name (case sensitive)
|
||||
* \return index of found port or -1 if not enumerated
|
||||
*/
|
||||
int comFindPort(const char * name);
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* \fn int comOpen(int index, int baudrate)
|
||||
* \brief Try to open a port at a specific baudrate
|
||||
* \brief (No parity, single stop bit, no hardware flow control)
|
||||
* \param[in] index port index
|
||||
* \param[in] baudrate port baudrate
|
||||
* \return 1 if opened, 0 if not available
|
||||
*/
|
||||
int comOpen(int index, int baudrate);
|
||||
|
||||
/**
|
||||
* \fn void comClose(int index)
|
||||
* \brief Close an opened port
|
||||
* \param[in] index port index
|
||||
*/
|
||||
void comClose(int index);
|
||||
|
||||
/**
|
||||
* \fn void comCloseAll()
|
||||
* \brief Close all opened ports
|
||||
*/
|
||||
void comCloseAll();
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* \fn int comWrite(int index, const char * buffer, size_t len)
|
||||
* \brief Write data to the port (non-blocking)
|
||||
* \param[in] index port index
|
||||
* \param[in] buffer pointer to transmit buffer
|
||||
* \param[in] len length of transmit buffer in bytes
|
||||
* \return number of bytes transferred
|
||||
*/
|
||||
int comWrite(int index, const char * buffer, size_t len);
|
||||
|
||||
/**
|
||||
* \fn int comRead(int index, const char * buffer, size_t len)
|
||||
* \brief Read data from the port (non-blocking)
|
||||
* \param[in] index port index
|
||||
* \param[in] buffer pointer to receive buffer
|
||||
* \param[in] len length of receive buffer in bytes
|
||||
* \return number of bytes transferred
|
||||
*/
|
||||
int comRead(int index, char * buffer, size_t len);
|
||||
|
||||
//#ifdef __cplusplus
|
||||
//}
|
||||
//#endif
|
||||
|
||||
#endif // RS232_H
|
Reference in New Issue
Block a user