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);
299 GetCommState(g_hdevices, &dcb);
302 dcb.fOutxCtsFlow = 0;
303 dcb.fOutxDsrFlow = 0;
304 dcb.fDtrControl = DTR_CONTROL_DISABLE;
305 dcb.fDsrSensitivity = FALSE;
306 dcb.Parity = NOPARITY;
307 dcb.StopBits = ONESTOPBIT;
309 dcb.BaudRate =
i2baud(baud);
311 SetCommState(g_hdevices, &dcb);
312 #endif // !defined(__MINGW32__) 319 #if !defined(__MINGW32__) 337 g_hdevices = CreateFile(device_name, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
338 if (g_hdevices == INVALID_HANDLE_VALUE)
343 GetCommState(g_hdevices, &g_olddcb);
347 GetCommTimeouts(g_hdevices, &cto);
348 GetCommTimeouts(g_hdevices, &g_oldcto);
349 cto.ReadIntervalTimeout = 0;
350 cto.ReadTotalTimeoutMultiplier = 0;
351 cto.ReadTotalTimeoutConstant = 1000;
352 cto.WriteTotalTimeoutMultiplier = 0;
353 cto.WriteTotalTimeoutConstant = 1000;
354 SetCommTimeouts(g_hdevices, &cto);
355 #endif // !defined(__MINGW32__) 362 #if !defined(__MINGW32__) 373 if (g_hdevices != NULL)
375 SetCommState(g_hdevices, &g_olddcb);
376 SetCommTimeouts(g_hdevices, &g_oldcto);
377 CloseHandle(g_hdevices);
380 #endif // !defined(__MINGW32__) 387 #if !defined(__MINGW32__) 400 ClearCommError(g_hdevices, &ret, &state);
407 if (!ReadFile(g_hdevices, buf, len, &len, NULL))
417 #endif // !defined(__MINGW32__) 422 #if !defined(__MINGW32__) 427 #endif // !defined(__MINGW32__) 439 #if !defined(__MINGW32__) 458 else if (retval == 0)
488 if (!ClearCommError(g_hdevices, &ret, &state))
499 if (timeout_count > 500 / 5)
503 if (!ReadFile(g_hdevices, buf, len, &len, NULL))
508 #endif // !defined(__MINGW32__) 513 retval = serial_event(buf, len, receive_time, data);
522 unsigned char buf[128];
526 encode_len =
encode((
unsigned char *)data, len, buf + 1, 126);
541 #if !defined(__MINGW32__) 547 #endif // !defined(__MINGW32__) 551 #if !defined(__MINGW32__) 557 WriteFile(g_hdevices, buf, len, (LPDWORD)&ret, 0);
558 #endif // !defined(__MINGW32__) 560 if (ret <= 0 && len > 0)
void serial_flush_out(void)
int encode_write(char *data, int len)
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)
void yprintf(ParamOutputLv level, const char *format,...)
void serial_flush_in(void)
int state(YPSpur_state id)
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