MIP_SDK  latest-2-g34f3e39
MicroStrain Communications Library for embedded systems
serial_port.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #if defined MICROSTRAIN_PLATFORM_WINDOWS
6 
7 #if !defined WIN32_LEAN_AND_MEAN
8 #define WIN32_LEAN_AND_MEAN
9 #endif // !WIN32_LEAN_AND_MEAN
10 
11 #include <windows.h>
12 #else // Unix
13 #include <errno.h>
14 #include <fcntl.h>
15 #include <poll.h>
16 #include <string.h>
17 #include <sys/ioctl.h>
18 #include <termios.h>
19 #include <unistd.h>
20 #endif // MICROSTRAIN_PLATFORM_WINDOWS
21 
22 #include <stdbool.h>
23 #include <stdint.h>
24 #include <stdio.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif // __cplusplus
29 
34 
41 
42 typedef struct serial_port
43 {
44 #if defined MICROSTRAIN_PLATFORM_WINDOWS
45  HANDLE handle;
46 #else // Unix
47  int handle;
48 #endif // MICROSTRAIN_PLATFORM_WINDOWS
49 } serial_port;
50 
51 void serial_port_init(serial_port* port);
52 bool serial_port_open(serial_port* port, const char* port_str, int baudrate);
53 bool serial_port_set_baudrate(serial_port* port, int baudrate);
54 bool serial_port_close(serial_port* port);
55 bool serial_port_write(serial_port* port, const void* buffer, size_t num_bytes, size_t* bytes_written);
56 bool serial_port_read(serial_port* port, void* buffer, size_t num_bytes, int wait_time, size_t* bytes_read);
57 uint32_t serial_port_read_count(serial_port* port);
58 bool serial_port_is_open(const serial_port* port);
59 
63 
64 #ifdef __cplusplus
65 }
66 #endif // __cplusplus
serial_port_is_open
bool serial_port_is_open(const serial_port *port)
Definition: serial_port.c:471
serial_port
struct serial_port serial_port
serial_port_read_count
uint32_t serial_port_read_count(serial_port *port)
Definition: serial_port.c:440
serial_port_close
bool serial_port_close(serial_port *port)
Definition: serial_port.c:313
serial_port_set_baudrate
bool serial_port_set_baudrate(serial_port *port, int baudrate)
Definition: serial_port.c:254
serial_port_init
void serial_port_init(serial_port *port)
Definition: serial_port.c:66
serial_port
Definition: serial_port.h:42
serial_port_read
bool serial_port_read(serial_port *port, void *buffer, size_t num_bytes, int wait_time, size_t *bytes_read)
Definition: serial_port.c:361
serial_port_open
bool serial_port_open(serial_port *port, const char *port_str, int baudrate)
Definition: serial_port.c:71
platform.h
serial_port_write
bool serial_port_write(serial_port *port, const void *buffer, size_t num_bytes, size_t *bytes_written)
Definition: serial_port.c:329
serial_port::handle
int handle
Definition: serial_port.h:47