MIP_SDK  v3.0.0
MicroStrain Communications Library for embedded systems
serial_port.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #ifdef MICROSTRAIN_PLATFORM_WINDOWS
6 #ifndef WIN32_LEAN_AND_MEAN
7 #define WIN32_LEAN_AND_MEAN
8 #endif
9 
10 #include <windows.h>
11 #else
12 #include <poll.h>
13 #include <fcntl.h>
14 #include <errno.h>
15 #include <string.h>
16 #include <unistd.h>
17 #include <termios.h>
18 #include <sys/ioctl.h>
19 #endif
20 
21 #include <stdio.h>
22 #include <stdint.h>
23 #include <stdbool.h>
24 
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
34 
41 
42 typedef struct serial_port
43 {
44 #ifdef MICROSTRAIN_PLATFORM_WINDOWS
45  HANDLE handle;
46 #else //Linux
47  int handle;
48 #endif
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_close(serial_port *port);
54 bool serial_port_write(serial_port *port, const void *buffer, size_t num_bytes, size_t *bytes_written);
55 bool serial_port_read(serial_port *port, void *buffer, size_t num_bytes, int wait_time, size_t *bytes_read);
56 uint32_t serial_port_read_count(serial_port *port);
57 bool serial_port_is_open(const serial_port *port);
58 
62 
63 #ifdef __cplusplus
64 }
65 #endif
serial_port_is_open
bool serial_port_is_open(const serial_port *port)
Definition: serial_port.c:418
serial_port
struct serial_port serial_port
serial_port_read_count
uint32_t serial_port_read_count(serial_port *port)
Definition: serial_port.c:387
serial_port_close
bool serial_port_close(serial_port *port)
Definition: serial_port.c:258
serial_port_init
void serial_port_init(serial_port *port)
Definition: serial_port.c:68
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:307
serial_port_open
bool serial_port_open(serial_port *port, const char *port_str, int baudrate)
Definition: serial_port.c:73
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:274
serial_port::handle
int handle
Definition: serial_port.h:47