20 serial->hCom = INVALID_HANDLE_VALUE;
29 COMMTIMEOUTS timeouts;
30 GetCommTimeouts(serial->hCom, &timeouts);
32 timeouts.ReadIntervalTimeout = (timeout == 0) ? MAXDWORD : 0;
33 timeouts.ReadTotalTimeoutConstant = timeout;
34 timeouts.ReadTotalTimeoutMultiplier = 0;
36 SetCommTimeouts(serial->hCom, &timeouts);
43 enum { NameLength = 11 };
44 char adjusted_device[NameLength];
49 _snprintf(adjusted_device, NameLength,
"\\\\.\\%s", device);
50 serial->hCom = CreateFileA(adjusted_device, GENERIC_READ | GENERIC_WRITE,
51 0, NULL, OPEN_EXISTING,
52 FILE_ATTRIBUTE_NORMAL, NULL);
54 if (serial->hCom == INVALID_HANDLE_VALUE) {
61 SetupComm(serial->hCom, 4096 * 8, 4096);
70 serial->current_timeout = 0;
79 if (serial->hCom != INVALID_HANDLE_VALUE) {
80 CloseHandle(serial->hCom);
81 serial->hCom = INVALID_HANDLE_VALUE;
94 baudrate_value = CBR_4800;
98 baudrate_value = CBR_9600;
102 baudrate_value = CBR_19200;
106 baudrate_value = CBR_38400;
110 baudrate_value = CBR_57600;
114 baudrate_value = CBR_115200;
118 baudrate_value = baudrate;
121 GetCommState(serial->hCom, &dcb);
122 dcb.BaudRate = baudrate_value;
124 dcb.Parity = NOPARITY;
126 dcb.StopBits = ONESTOPBIT;
127 SetCommState(serial->hCom, &dcb);
141 if (serial->hCom == INVALID_HANDLE_VALUE) {
145 WriteFile(serial->hCom, data, (DWORD)size, &n, NULL);
156 if (timeout != serial->current_timeout) {
158 serial->current_timeout = timeout;
161 ReadFile(serial->hCom, &data[filled], (DWORD)max_size - filled, &n, NULL);
184 if (serial->hCom == INVALID_HANDLE_VALUE) {
192 read_n = max_size - filled;
193 if (buffer_size < read_n) {
204 if (read_n > buffer_size) {
205 read_n = buffer_size;
214 max_size - filled, serial, timeout);
static int internal_receive(char data[], int max_size, urg_serial_t *serial, int timeout)
static void set_timeout(urg_serial_t *serial, int timeout)
int ring_capacity(const ring_buffer_t *ring)
最大の格納データ数を返す
int ring_write(ring_buffer_t *ring, const char *data, int size)
データの格納
char buffer[RING_BUFFER_SIZE]
int serial_set_baudrate(urg_serial_t *serial, long baudrate)
ボーレートを設定する
int ring_read(ring_buffer_t *ring, char *buffer, int size)
データの取り出し
void serial_close(urg_serial_t *serial)
接続を閉じる
int serial_write(urg_serial_t *serial, const char *data, int size)
データを送信する
static void serial_initialize(urg_serial_t *serial)
int serial_open(urg_serial_t *serial, const char *device, long baudrate)
接続を開く
void ring_initialize(ring_buffer_t *ring, char *buffer, const int shift_length)
初期化
int ring_size(const ring_buffer_t *ring)
格納データ数を返す
int serial_read(urg_serial_t *serial, char *data, int max_size, int timeout)
データを受信する