[ttssh2-commit] [10532] ラインステータスを表示できるようにした

Zurück zum Archiv-Index
scmno****@osdn***** scmno****@osdn*****
2023年 1月 23日 (月) 00:40:52 JST


Revision: 10532
          https://osdn.net/projects/ttssh2/scm/svn/commits/10532
Author:   zmatsuo
Date:     2023-01-23 00:40:52 +0900 (Mon, 23 Jan 2023)
Log Message:
-----------
ラインステータスを表示できるようにした

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-22 02:47:32 UTC (rev 10531)
+++ branches/ttcomtester/tools/ttcomtester/device_com.cpp	2023-01-22 15:40:52 UTC (rev 10532)
@@ -25,6 +25,7 @@
 		STATE_OPEN,
 		STATE_ERROR,
 	} state;
+	bool check_line_state_before_send;
 } comdata_t;
 
 static void *init(void)
@@ -102,10 +103,30 @@
 	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
+	}
+
 	if (p->dcb_setted) {
 		if (p->dcb.XonChar == p->dcb.XoffChar) {
 			p->dcb.XonChar = 0x11;
@@ -326,11 +347,13 @@
 	}
 #endif
 
-	DWORD modem_state;
-	GetCommModemStatus(h, &modem_state);
-	if ((modem_state & MS_CTS_ON) == 0) {
-		*writed = 0;
-		return ERROR_SUCCESS;
+	if (p->check_line_state_before_send) {
+		DWORD modem_state;
+		GetCommModemStatus(h, &modem_state);
+		if ((modem_state & MS_CTS_ON) == 0) {
+			*writed = 0;
+			return ERROR_SUCCESS;
+		}
 	}
 
 #if 0
@@ -435,7 +458,19 @@
 		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;
+		retval = ERROR_SUCCESS;
+		break;
 	}
+	case GET_CHECK_LINE_STATE_BEFORE_SEND: {
+		int *check_line_state = va_arg(ap, int *);
+		*check_line_state = (int)p->check_line_state_before_send;
+		retval = ERROR_SUCCESS;
+		break;
+	}
+	}
 
 	va_end(ap);
 	return retval;

Modified: branches/ttcomtester/tools/ttcomtester/deviceope.h
===================================================================
--- branches/ttcomtester/tools/ttcomtester/deviceope.h	2023-01-22 02:47:32 UTC (rev 10531)
+++ branches/ttcomtester/tools/ttcomtester/deviceope.h	2023-01-22 15:40:52 UTC (rev 10532)
@@ -38,6 +38,8 @@
 	GET_RAW_HANDLE,
 	SET_COM_DCB,
 	SET_COM_TIMEOUTS,
+	SET_CHECK_LINE_STATE_BEFORE_SEND,
+	GET_CHECK_LINE_STATE_BEFORE_SEND,
 } device_ctrl_request;
 
 typedef struct device {

Modified: branches/ttcomtester/tools/ttcomtester/main.cpp
===================================================================
--- branches/ttcomtester/tools/ttcomtester/main.cpp	2023-01-22 02:47:32 UTC (rev 10531)
+++ branches/ttcomtester/tools/ttcomtester/main.cpp	2023-01-22 15:40:52 UTC (rev 10532)
@@ -37,13 +37,15 @@
 		"'d'	DTR 0/1\n"
 		"'x'	XON/XOFF\n"
 		"'e'	echo on/off\n"
-		"'s'    send big data\n"
+		"'s'	send big data\n"
+		"'l'	disp line state\n"
+		"'L'	check line state before sending\n"
 		"   send mode\n"
 		"':'	go command mode\n"
 		);
 }
 
-void DispErrorStr(wchar_t *str, DWORD err)
+void DispErrorStr(const wchar_t *str, DWORD err)
 {
 	wchar_t *buf;
 	DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM |
@@ -50,7 +52,7 @@
 		FORMAT_MESSAGE_ALLOCATE_BUFFER |
 		FORMAT_MESSAGE_IGNORE_INSERTS;
 	FormatMessageW(flags, 0, err, 0, (LPWSTR) & buf, 0, NULL);
-	wprintf(L"%s %d=%s", str, err, buf);
+	wprintf(L"%s %d,0x%x %s", str, err, err, buf);
 	LocalFree(buf);
 }
 
@@ -213,7 +215,10 @@
 	}
 	ope->ctrl(dev, SET_COM_DCB, &dcb);
 
-	printf("':'		switch mode\n");
+	printf(
+		"':'		switch mode\n"
+		"' '(space)	key usage\n"
+		);
 	bool quit_flag = false;
 	bool receive_pending = false;
 	bool command_mode = true;
@@ -221,6 +226,7 @@
 	bool xon = true;
 	bool dtr = true;
 	bool echo_mode = false;
+	bool check_line_state = true;
 	enum {
 		STATE_CLOSE,
 		STATE_OPEN,
@@ -260,11 +266,11 @@
 						send_data[i] = (unsigned char)i;
 					}
 					size_t sended_len;
-					r = ope->write(dev, send_data, send_len, &sended_len);
-					if (r == ERROR_SUCCESS) {
+					DWORD e = ope->write(dev, send_data, send_len, &sended_len);
+					if (e == ERROR_SUCCESS) {
 						printf("sent\n");
 					}
-					else {
+					else if (e == ERROR_IO_PENDING) {
 						size_t sended_len_total = sended_len;
 						while(1) {
 							r = ope->wait_write(dev, &sended_len);
@@ -278,6 +284,9 @@
 							Sleep(100);
 						}
 					}
+					else {
+						DispErrorStr(L"open()", e);
+					}
 					free(send_data);
 					break;
 				}
@@ -296,7 +305,7 @@
 						printf("RTS=0, %d\n", b);
 						if (b == 0) {
 							DWORD err = GetLastError();
-							printf("error=0x%08d\n", err);
+							DispErrorStr(L"EscapeCommFunction()", err);
 						}
 					}
 					else {
@@ -305,7 +314,7 @@
 						printf("RTS=1, %d\n", b);
 						if (b == 0) {
 							DWORD err = GetLastError();
-							printf("error=0x%08d\n", err);
+							DispErrorStr(L"EscapeCommFunction()", err);
 						}
 					}
 					break;
@@ -353,6 +362,33 @@
 					}
 					break;
 				}
+				case 'l': {
+					HANDLE h;
+					ope->ctrl(dev, GET_RAW_HANDLE, &h);
+					DWORD modem_state;
+					BOOL b = GetCommModemStatus(h, &modem_state);
+					if (b == FALSE) {
+						DWORD err = GetLastError();
+						DispErrorStr(L"GetCommModemStatus()", err);
+					}
+					else {
+						printf("CTS %s / DSR %s / RING %s / RLSD %s / 0x%02x\n",
+							   (modem_state & MS_CTS_ON) == 0 ? "OFF" : "ON ",
+							   (modem_state & MS_DSR_ON) == 0 ? "OFF" : "ON ",
+							   (modem_state & MS_RING_ON) == 0 ? "OFF" : "ON ",
+							   (modem_state & MS_RLSD_ON) == 0 ? "OFF" : "ON ",
+							   modem_state
+							);
+					}
+					break;
+				}
+				case 'L': {
+					int i = check_line_state ? 0 : 1;
+					printf("check line state before sending %s\n", i == 0 ? "off" : "on");
+					ope->ctrl(dev, SET_CHECK_LINE_STATE_BEFORE_SEND, i);
+					check_line_state = i;
+					break;
+				}
 				case ':': {
 					printf("\nsend mode\n");
 					command_mode = false;


ttssh2-commit メーリングリストの案内
Zurück zum Archiv-Index