30 #include <sys/types.h> 34 #endif // HAVE_CONFIG_H 51 #if !defined(__MINGW32__) 54 #include <sys/select.h> 55 #include <sys/termios.h> 63 HANDLE g_hdevices = NULL;
65 COMMTIMEOUTS g_oldcto;
67 #endif // !defined(__MINGW32__) 69 #if !defined(__MINGW32__) 175 #endif // !defined(__MINGW32__) 180 #if !defined(__MINGW32__) 191 g_hdevices = CreateFile(device_name, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
192 if (g_hdevices == INVALID_HANDLE_VALUE)
196 CloseHandle(g_hdevices);
197 #endif // !defined(__MINGW32__) 204 strcat((
char *)data, buf);
205 if (strstr((
char *)data,
"\n\n"))
218 #if !defined(__MINGW32__) 219 struct termios newtio;
223 memset(&newtio, 0,
sizeof(newtio));
232 newtio.c_cflag = CS8 | CLOCAL | CREAD | CRTSCTS;
234 ret = cfsetispeed(&newtio,
i2baud(baud));
243 ret = cfsetospeed(&newtio,
i2baud(baud));
252 newtio.c_iflag = IGNPAR;
255 newtio.c_cc[VTIME] = 0;
256 newtio.c_cc[VMIN] = 1;
279 isp = cfgetispeed(&term);
280 osp = cfgetospeed(&term);
302 GetCommState(g_hdevices, &dcb);
305 dcb.fOutxCtsFlow = 0;
306 dcb.fOutxDsrFlow = 0;
307 dcb.fDtrControl = DTR_CONTROL_DISABLE;
308 dcb.fDsrSensitivity = FALSE;
309 dcb.Parity = NOPARITY;
310 dcb.StopBits = ONESTOPBIT;
312 dcb.BaudRate =
i2baud(baud);
314 SetCommState(g_hdevices, &dcb);
315 #endif // !defined(__MINGW32__) 322 #if !defined(__MINGW32__) 340 g_hdevices = CreateFile(device_name, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
341 if (g_hdevices == INVALID_HANDLE_VALUE)
346 GetCommState(g_hdevices, &g_olddcb);
350 GetCommTimeouts(g_hdevices, &cto);
351 GetCommTimeouts(g_hdevices, &g_oldcto);
352 cto.ReadIntervalTimeout = 0;
353 cto.ReadTotalTimeoutMultiplier = 0;
354 cto.ReadTotalTimeoutConstant = 1000;
355 cto.WriteTotalTimeoutMultiplier = 0;
356 cto.WriteTotalTimeoutConstant = 1000;
357 SetCommTimeouts(g_hdevices, &cto);
358 #endif // !defined(__MINGW32__) 365 #if !defined(__MINGW32__) 376 if (g_hdevices != NULL)
378 SetCommState(g_hdevices, &g_olddcb);
379 SetCommTimeouts(g_hdevices, &g_oldcto);
380 CloseHandle(g_hdevices);
383 #endif // !defined(__MINGW32__) 390 #if !defined(__MINGW32__) 403 ClearCommError(g_hdevices, &ret, &state);
410 if (!ReadFile(g_hdevices, buf, len, &len, NULL))
420 #endif // !defined(__MINGW32__) 425 #if !defined(__MINGW32__) 430 #endif // !defined(__MINGW32__) 442 #if !defined(__MINGW32__) 455 tv.tv_sec = timeout_us / 1000000;
456 tv.tv_usec = timeout_us % 1000000;
468 else if (retval == 0)
498 if (!ClearCommError(g_hdevices, &ret, &state))
509 if (timeout_count > 500 / 5)
513 if (!ReadFile(g_hdevices, buf, len, &len, NULL))
518 #endif // !defined(__MINGW32__) 523 retval = serial_event(buf, len, receive_time, data);
532 unsigned char buf[128];
536 encode_len =
encode((
unsigned char *)data, len, buf + 1, 126);
551 unsigned char buf[128];
555 encode_len =
encode((
unsigned char *)data, len, buf + 1, 126);
570 #if !defined(__MINGW32__) 576 #endif // !defined(__MINGW32__) 580 #if !defined(__MINGW32__) 586 WriteFile(g_hdevices, buf, len, (LPDWORD)&ret, 0);
587 #endif // !defined(__MINGW32__) 589 if (ret <= 0 && len > 0)
void serial_flush_out(void)
int encode_write(char *data, int len)
double p(YPSpur_param id, enum motor_id motor)
int serial_change_baudrate(int baud)
ボーレートを変更する
int recieve_throw(char *buf, int len, double t, void *data)
#define COMMUNICATION_END_BYTE
int serial_write(char *buf, int len)
int serial_recieve(int(*serial_event)(char *, int, double, void *), void *data)
int encode_int_write(char *data, int len)
void yprintf(ParamOutputLv level, const char *format,...)
void serial_flush_in(void)
int state(YPSpur_state id)
int option(ParamOptions option)
#define COMMUNICATION_INT_BYTE
int serial_connect(char *device_name)
int serial_tryconnect(char *device_name)
int encode(const unsigned char *src, int len, unsigned char *dst, int buf_max)
エンコード
#define COMMUNICATION_START_BYTE