説明を見る。00001 #ifndef URG_SERIAL_H
00002 #define URG_SERIAL_H
00003
00016 #ifdef __cplusplus
00017 extern "C" {
00018 #endif
00019
00020 #include "urg_detect_os.h"
00021
00022 #if defined(URG_WINDOWS_OS)
00023 #include <windows.h>
00024 #else
00025 #include <termios.h>
00026 #endif
00027 #include "urg_ring_buffer.h"
00028
00029
00030 enum {
00031 RING_BUFFER_SIZE_SHIFT = 7,
00032 RING_BUFFER_SIZE = 1 << RING_BUFFER_SIZE_SHIFT,
00033
00034 ERROR_MESSAGE_SIZE = 256,
00035 };
00036
00037
00039 typedef struct
00040 {
00041 #if defined(URG_WINDOWS_OS)
00042 HANDLE hCom;
00043 int current_timeout;
00044 #else
00045 int fd;
00046 struct termios sio;
00047 #endif
00048
00049 ring_buffer_t ring;
00050 char buffer[RING_BUFFER_SIZE];
00051 char has_last_ch;
00052 char last_ch;
00053 } urg_serial_t;
00054
00055
00057 extern int serial_open(urg_serial_t *serial, const char *device, long baudrate);
00058
00059
00061 extern void serial_close(urg_serial_t *serial);
00062
00063
00065 extern int serial_set_baudrate(urg_serial_t *serial, long baudrate);
00066
00067
00069 extern int serial_write(urg_serial_t *serial, const char *data, int size);
00070
00071
00073 extern int serial_read(urg_serial_t *serial,
00074 char *data, int max_size, int timeout);
00075
00076
00078 extern int serial_readline(urg_serial_t *serial,
00079 char *data, int max_size, int timeout);
00080
00081
00083 extern int serial_error(urg_serial_t *serial,
00084 char *error_message, int max_size);
00085
00086 #ifdef __cplusplus
00087 }
00088 #endif
00089
00090 #endif