1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/**
* Copyright (C) 2019 Johan van der Vyver
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __VOLTRONIC__DEV__SERIAL__H__
#define __VOLTRONIC__DEV__SERIAL__H__
#include "voltronic_dev.h"
/**
* The serial port baud rate configuration
*/
typedef unsigned int baud_rate_t;
/**
* The serial port data bits configuration
*/
typedef enum {
DATA_BITS_FIVE,
DATA_BITS_SIX,
DATA_BITS_SEVEN,
DATA_BITS_EIGHT
} data_bits_t;
/**
* The serial port stop bits configuration
*/
typedef enum {
STOP_BITS_ONE,
STOP_BITS_ONE_AND_ONE_HALF,
STOP_BITS_TWO
} stop_bits_t;
/**
* The serial port parity configuration
*/
typedef enum {
SERIAL_PARITY_NONE,
SERIAL_PARITY_ODD,
SERIAL_PARITY_EVEN,
SERIAL_PARITY_MARK,
SERIAL_PARITY_SPACE
} serial_parity_t;
/**
* Create an opaque pointer to a voltronic device connected over serial
*
* name - The device name, ie. COM1; /dev/usb.serial; etc.
* baud_rate - Baud rate configuration, ie. 2400
* data_bits - Data bits configuration, ie. DATA_BITS_EIGHT
* stop_bits - Stop bits configuration, ie. STOP_BITS_ONE
* parity - Parity configuration, ie. SERIAL_PARITY_NONE
*
* Returns an opaque pointer to a voltronic device or 0 if an error occurred
*
* Function sets errno (POSIX)/LastError (Windows) to approriate error on failure
*/
voltronic_dev_t voltronic_serial_create(
const char* name,
const baud_rate_t baud_rate,
const data_bits_t data_bits,
const stop_bits_t stop_bits,
const serial_parity_t parity);
#endif
|