Revision: 10551 https://osdn.net/projects/ttssh2/scm/svn/commits/10551 Author: zmatsuo Date: 2023-01-31 01:09:28 +0900 (Tue, 31 Jan 2023) Log Message: ----------- ハードフロー(RTS/CTS)ができるよう修正 - タイムアウト値を修正 - オーバーフロー制御の設定を見直し - 'v' verbose on/off - 'D' ダイアログで設定した後、verbose=on時は設定値が表示されるようにした - 'o' open後、verbose=on時は設定値が表示されるようにした Modified Paths: -------------- branches/ttcomtester/tools/ttcomtester/device_com.cpp branches/ttcomtester/tools/ttcomtester/deviceope.h branches/ttcomtester/tools/ttcomtester/main.cpp -------------- next part -------------- Modified: branches/ttcomtester/tools/ttcomtester/device_com.cpp =================================================================== --- branches/ttcomtester/tools/ttcomtester/device_com.cpp 2023-01-30 14:52:31 UTC (rev 10550) +++ branches/ttcomtester/tools/ttcomtester/device_com.cpp 2023-01-30 16:09:28 UTC (rev 10551) @@ -103,30 +103,14 @@ SetupComm(h, CommInQueSize, CommOutQueSize); PurgeComm(h, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR); - COMMTIMEOUTS ctmo; - r = GetCommTimeouts(h, &ctmo); - assert(r == TRUE); - printf("Maximum time between read chars %d\n", ctmo.ReadIntervalTimeout); - printf("read Multiplier of characters %d\n", ctmo.ReadTotalTimeoutMultiplier); - printf("read Constant in milliseconds %d\n", ctmo.ReadTotalTimeoutConstant); - printf("write Multiplier of characters %d\n", ctmo.WriteTotalTimeoutMultiplier); - printf("write Constant in milliseconds %d\n", ctmo.WriteTotalTimeoutConstant); - if (p->commtimeouts_setted) { r = SetCommTimeouts(h, &p->commtimeouts); assert(r == TRUE); } - else { - // Tera Term \x82\xAA\x90ݒ肵\x82Ă\xA2\x82\xE9\x83p\x83\x89\x83\x81\x81[\x83^ -#if 0 - memset(&ctmo, 0, sizeof(ctmo)); - ctmo.ReadIntervalTimeout = MAXDWORD; - ctmo.WriteTotalTimeoutConstant = 500; - r = SetCommTimeouts(h, &ctmo); - assert(r == TRUE); -#endif - } + r = GetCommTimeouts(h, &p->commtimeouts); + assert(r == TRUE); + if (p->dcb_setted) { if (p->dcb.XonChar == p->dcb.XoffChar) { p->dcb.XonChar = 0x11; @@ -140,6 +124,9 @@ } } + r = GetCommState(h, &p->dcb); + assert(r == TRUE); + SetCommMask(h, 0); SetCommMask(h, EV_RXCHAR); @@ -451,6 +438,12 @@ retval = ERROR_SUCCESS; break; } + case GET_COM_DCB: { + DCB *dcb = va_arg(ap, DCB *); + *dcb = p->dcb; + retval = ERROR_SUCCESS; + break; + } case SET_COM_TIMEOUTS: { COMMTIMEOUTS *commtimeouts = va_arg(ap, COMMTIMEOUTS *); p->commtimeouts = *commtimeouts; @@ -458,6 +451,12 @@ retval = ERROR_SUCCESS; break; } + case GET_COM_TIMEOUTS: { + COMMTIMEOUTS *commtimeouts = va_arg(ap, COMMTIMEOUTS *); + *commtimeouts = p->commtimeouts; + retval = ERROR_SUCCESS; + break; + } case SET_CHECK_LINE_STATE_BEFORE_SEND: { int check_line_state = va_arg(ap, int); p->check_line_state_before_send = check_line_state; @@ -479,6 +478,8 @@ if (r == TRUE) { r = SetCommConfig(p->h, &cc, size); assert(r == TRUE); + r = GetCommState(p->h, &p->dcb); + assert(r == TRUE); } break; } Modified: branches/ttcomtester/tools/ttcomtester/deviceope.h =================================================================== --- branches/ttcomtester/tools/ttcomtester/deviceope.h 2023-01-30 14:52:31 UTC (rev 10550) +++ branches/ttcomtester/tools/ttcomtester/deviceope.h 2023-01-30 16:09:28 UTC (rev 10551) @@ -37,7 +37,9 @@ SET_PORT_NAME, GET_RAW_HANDLE, SET_COM_DCB, + GET_COM_DCB, SET_COM_TIMEOUTS, + GET_COM_TIMEOUTS, SET_CHECK_LINE_STATE_BEFORE_SEND, GET_CHECK_LINE_STATE_BEFORE_SEND, OPEN_CONFIG_DIALOG, Modified: branches/ttcomtester/tools/ttcomtester/main.cpp =================================================================== --- branches/ttcomtester/tools/ttcomtester/main.cpp 2023-01-30 14:52:31 UTC (rev 10550) +++ branches/ttcomtester/tools/ttcomtester/main.cpp 2023-01-30 16:09:28 UTC (rev 10551) @@ -41,6 +41,7 @@ "'l' disp line state\n" "'L' check line state before sending\n" "'D' open device dialogbox\n" + "'v' verbose on/off\n" " send mode\n" "':' go command mode\n" ); @@ -101,6 +102,14 @@ printf("Fill for now. %d\n", p->wReserved1); } +void dumpCOMMTIMEOUTS(const COMMTIMEOUTS *p) +{ + printf("Maximum time between read chars %d\n", p->ReadIntervalTimeout); + printf("read Multiplier of characters %d\n", p->ReadTotalTimeoutMultiplier); + printf("read Constant in milliseconds %d\n", p->ReadTotalTimeoutConstant); + printf("write Multiplier of characters %d\n", p->WriteTotalTimeoutMultiplier); + printf("write Constant in milliseconds %d\n", p->WriteTotalTimeoutConstant); +} int wmain(int argc, wchar_t *argv[]) { @@ -112,7 +121,7 @@ bool verbose = false; wchar_t *ini_base = L"ttcomtester.ini"; - int arg_rts = RTS_CONTROL_DISABLE; + const wchar_t *arg_rts = L"off"; wchar_t *prog = argv[0]; wchar_t *arg_device_name = NULL; @@ -146,13 +155,13 @@ break; case L'r': { if (wcscmp(optarg_w, L"off") == 0) { - arg_rts = RTS_CONTROL_DISABLE; + arg_rts = L"off"; } else if (wcscmp(optarg_w, L"on") == 0) { - arg_rts = RTS_CONTROL_ENABLE; + arg_rts = L"on"; } else if (wcscmp(optarg_w, L"hs") == 0) { - arg_rts = RTS_CONTROL_HANDSHAKE; - } else if (wcscmp(optarg_w, L"on") == 0) { - arg_rts = RTS_CONTROL_TOGGLE; + arg_rts = L"hs"; + } else if (wcscmp(optarg_w, L"toggle") == 0) { + arg_rts = L"toggle"; } else { printf("check rts option"); exit(1); @@ -197,25 +206,72 @@ device_ope const *ope = dev->ope; ope->ctrl(dev, SET_PORT_NAME, device_name); - - DCB dcb; - memset(&dcb, 0, sizeof(dcb)); // 100% build\x82\xB5\x82Ă\xAD\x82\xEA\x82Ȃ\xA2\x82悤\x82\xBE - dcb.DCBlength = sizeof(dcb); - BOOL r = BuildCommDCBW(com_param, &dcb); - dcb.fRtsControl = arg_rts; - if (r == FALSE) { - DWORD e = GetLastError(); - wchar_t b[128]; - swprintf_s(b, _countof(b), L"BuildCommDCBW('%s')", com_param); - DispErrorStr(b, e); - goto finish; - } if (verbose) { printf("param='%ls'\n", com_param); - dumpDCB(&dcb); } - ope->ctrl(dev, SET_COM_DCB, &dcb); + { + DCB dcb; + memset(&dcb, 0, sizeof(dcb)); // 100% build\x82\xB5\x82Ă\xAD\x82\xEA\x82Ȃ\xA2\x82悤\x82\xBE + dcb.DCBlength = sizeof(dcb); + BOOL r = BuildCommDCBW(com_param, &dcb); + if (wcscmp(arg_rts, L"off") == 0) { + dcb.fRtsControl = RTS_CONTROL_DISABLE; + dcb.fOutxCtsFlow = FALSE; + } else if (wcscmp(arg_rts, L"on") == 0) { + dcb.fRtsControl = RTS_CONTROL_ENABLE; + dcb.fOutxCtsFlow = FALSE; + } else if (wcscmp(arg_rts, L"hs") == 0) { + dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; + dcb.fOutxCtsFlow = TRUE; + } else if (wcscmp(arg_rts, L"toggle") == 0) { + dcb.fRtsControl = RTS_CONTROL_TOGGLE; + //dcb.fOutxCtsFlow = TRUE; //?? + } + if (r == FALSE) { + DWORD e = GetLastError(); + wchar_t b[128]; + swprintf_s(b, _countof(b), L"BuildCommDCBW('%s')", com_param); + DispErrorStr(b, e); + goto finish; + } + ope->ctrl(dev, SET_COM_DCB, &dcb); + } + + { + COMMTIMEOUTS timeouts; + memset(&timeouts, 0, sizeof(timeouts)); +#if 0 + // Tera Term \x82\xAA\x90ݒ肵\x82Ă\xA2\x82\xE9\x83p\x83\x89\x83\x81\x81[\x83^ + timeouts.ReadIntervalTimeout = MAXDWORD; + timeouts.WriteTotalTimeoutConstant = 500; +#endif +#if 0 + // CODE PROJECT \x82̒l + // https://www.codeproject.com/articles/3061/creating-a-serial-communication-on-win + timeouts.ReadIntervalTimeout = 3; + timeouts.ReadTotalTimeoutMultiplier = 3; + timeouts.ReadTotalTimeoutConstant = 2; + timeouts.WriteTotalTimeoutMultiplier = 3; + timeouts.WriteTotalTimeoutConstant = 2; +#endif +#if 0 + // PuTTY\x82̒l + timeouts.ReadIntervalTimeout = 1; + timeouts.ReadTotalTimeoutMultiplier = 0; + timeouts.ReadTotalTimeoutConstant = 0; + timeouts.WriteTotalTimeoutMultiplier = 0; + timeouts.WriteTotalTimeoutConstant = 0; +#endif + // \x8D\xA1\x89\xF1\x92\xF1\x88Ă\xB7\x82\xE9\x92l + timeouts.ReadIntervalTimeout = 1; + timeouts.ReadTotalTimeoutMultiplier = 0; + timeouts.ReadTotalTimeoutConstant = 0; + timeouts.WriteTotalTimeoutMultiplier = 0; + timeouts.WriteTotalTimeoutConstant = 1; + ope->ctrl(dev, SET_COM_TIMEOUTS, &timeouts); + } + printf( "':' switch mode\n" "' '(space) key usage\n" @@ -251,6 +307,14 @@ else { DispErrorStr(L"open()", e); } + if (verbose) { + DCB dcb; + ope->ctrl(dev, GET_COM_DCB, &dcb); + dumpDCB(&dcb); + COMMTIMEOUTS timeouts; + ope->ctrl(dev, GET_COM_TIMEOUTS, &timeouts); + dumpCOMMTIMEOUTS(&timeouts); + } break; } case 'c': { @@ -266,27 +330,25 @@ for(size_t i = 0; i < send_len; i++) { send_data[i] = (unsigned char)i; } - size_t sended_len; - DWORD e = ope->write(dev, send_data, send_len, &sended_len); + size_t sent_len; + DWORD e = ope->write(dev, send_data, send_len, &sent_len); if (e == ERROR_SUCCESS) { - printf("sent\n"); + printf("sent %zu bytes\n", sent_len); } else if (e == ERROR_IO_PENDING) { - size_t sended_len_total = sended_len; + size_t sent_len_total = sent_len; while(1) { - r = ope->wait_write(dev, &sended_len); -#if 0 - if (r == ERROR_SUCCESS) { - printf("sent\n"); + DWORD r = ope->wait_write(dev, &sent_len); + if (r != ERROR_SUCCESS) { + printf("send error\n"); } -#endif - sended_len_total += sended_len; - printf("send size %zu(%zu)/%zu\n", sended_len_total, sended_len, send_len); + sent_len_total += sent_len; + printf("send size %zu(%zu)/%zu\n", sent_len_total, sent_len, send_len); Sleep(100); } } else { - DispErrorStr(L"open()", e); + DispErrorStr(L"write()", e); } free(send_data); break; @@ -392,8 +454,18 @@ } case 'D': { ope->ctrl(dev, OPEN_CONFIG_DIALOG); + if (verbose) { + DCB dcb; + ope->ctrl(dev, GET_COM_DCB, &dcb); + dumpDCB(&dcb); + } break; } + case 'v': { + verbose = verbose ? false : true; + printf("verbose %s\n", verbose?"on":"off"); + break; + } case ':': { printf("\nsend mode\n"); command_mode = false; @@ -413,11 +485,11 @@ else { if (state == STATE_OPEN) { char send_text[2]; - size_t sended_len; + size_t sent_len; send_text[0] = (char)c; - DWORD e = ope->write(dev, send_text, 1, &sended_len); + DWORD e = ope->write(dev, send_text, 1, &sent_len); if (e == ERROR_SUCCESS) { - printf("send %02x, %zu byte\n", c, sended_len); + printf("send %02x, %zu byte\n", c, sent_len); } else { DispErrorStr(L"write() error", e);