Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 lines
6.4 KiB

  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "windows.h"
  5. void main(int argc,char *argv[]) {
  6. HANDLE hFile;
  7. char *MyPort = "COM1";
  8. DWORD ValueFromEscape = 0;
  9. DWORD Func;
  10. int scanfval;
  11. if (argc > 1) {
  12. MyPort = argv[1];
  13. }
  14. if ((hFile = CreateFile(
  15. MyPort,
  16. GENERIC_READ | GENERIC_WRITE,
  17. 0,
  18. NULL,
  19. CREATE_ALWAYS,
  20. FILE_ATTRIBUTE_NORMAL,
  21. NULL
  22. )) != ((HANDLE)-1)) {
  23. printf("We successfully opened the %s port.\n",MyPort);
  24. do {
  25. printf("^z=END 1=GETTIMEOUTS 2=SETTIMEOUTS:");
  26. if ((scanfval = scanf("%d",&Func)) == EOF) {
  27. printf("All done\n");
  28. break;
  29. } else if (scanfval != 1) {
  30. printf("Invalid input\n");
  31. } else {
  32. if ((Func >= 1) && (Func <= 2)) {
  33. switch (Func) {
  34. case 1: {
  35. COMMTIMEOUTS OldTimeouts;
  36. if (!GetCommTimeouts(
  37. hFile,
  38. &OldTimeouts
  39. )) {
  40. printf("Error getting timeouts: %d\n",GetLastError());
  41. } else {
  42. printf("ReadIntervalTimeout: %d\n",OldTimeouts.ReadIntervalTimeout);
  43. printf("ReadTotalTimeoutMultiplier: %d\n",OldTimeouts.ReadTotalTimeoutMultiplier);
  44. printf("ReadTotalTimeoutConstant: %d\n",OldTimeouts.ReadTotalTimeoutConstant);
  45. printf("WriteTotalTimeoutMultipler: %d\n",OldTimeouts.WriteTotalTimeoutMultiplier);
  46. printf("WriteTotalTimeoutConstant: %d\n",OldTimeouts.WriteTotalTimeoutConstant);
  47. }
  48. break;
  49. }
  50. case 2: {
  51. COMMTIMEOUTS NewTimeout;
  52. printf("ReadIntervalTimeout[CR Implies use old value]: ");
  53. if ((scanfval = scanf("%d",&NewTimeout.ReadIntervalTimeout)) == EOF) {
  54. printf("All done\n");
  55. exit(1);
  56. } else if (!scanfval) {
  57. NewTimeout.ReadIntervalTimeout = ~0;
  58. } else if (scanfval != 1) {
  59. printf("Bad input\n");
  60. break;
  61. }
  62. printf("ReadTotalTimeoutMultiplier[CR Implies use old value]: ");
  63. if ((scanfval = scanf("%d",&NewTimeout.ReadTotalTimeoutMultiplier)) == EOF) {
  64. printf("All done\n");
  65. exit(1);
  66. } else if (!scanfval) {
  67. NewTimeout.ReadTotalTimeoutMultiplier = ~0;
  68. } else if (scanfval != 1) {
  69. printf("Bad input\n");
  70. break;
  71. }
  72. printf("ReadTotalTimeoutConstant[CR Implies use old value]: ");
  73. if ((scanfval = scanf("%d",&NewTimeout.ReadTotalTimeoutConstant)) == EOF) {
  74. printf("All done\n");
  75. exit(1);
  76. } else if (!scanfval) {
  77. NewTimeout.ReadTotalTimeoutConstant = ~0;
  78. } else if (scanfval != 1) {
  79. printf("Bad input\n");
  80. break;
  81. }
  82. printf("WriteTotalTimeoutMultipler[CR Implies use old value]: ");
  83. if ((scanfval = scanf("%d",&NewTimeout.WriteTotalTimeoutMultiplier)) == EOF) {
  84. printf("All done\n");
  85. exit(1);
  86. } else if (!scanfval) {
  87. NewTimeout.WriteTotalTimeoutMultiplier = ~0;
  88. } else if (scanfval != 1) {
  89. printf("Bad input\n");
  90. break;
  91. }
  92. printf("WriteTotalTimeoutConstant[CR Implies use old value]: ");
  93. if ((scanfval = scanf("%d",&NewTimeout.WriteTotalTimeoutConstant)) == EOF) {
  94. printf("All done\n");
  95. exit(1);
  96. } else if (!scanfval) {
  97. NewTimeout.WriteTotalTimeoutConstant = ~0;
  98. } else if (scanfval != 1) {
  99. printf("Bad input\n");
  100. break;
  101. }
  102. printf("ReadIntervalTimeout: %d\n",NewTimeout.ReadIntervalTimeout);
  103. printf("ReadTotalTimeoutMultiplier: %d\n",NewTimeout.ReadTotalTimeoutMultiplier);
  104. printf("ReadTotalTimeoutConstant: %d\n",NewTimeout.ReadTotalTimeoutConstant);
  105. printf("WriteTotalTimeoutMultipler: %d\n",NewTimeout.WriteTotalTimeoutMultiplier);
  106. printf("WriteTotalTimeoutConstant: %d\n",NewTimeout.WriteTotalTimeoutConstant);
  107. if (!SetCommTimeouts(
  108. hFile,
  109. &NewTimeout
  110. )) {
  111. printf("Error setting timeouts: %d\n",GetLastError());
  112. }
  113. break;
  114. }
  115. }
  116. } else {
  117. printf("Invalid Input\n");
  118. }
  119. }
  120. } while (TRUE);
  121. CloseHandle(hFile);
  122. } else {
  123. DWORD LastError;
  124. LastError = GetLastError();
  125. printf("Couldn't open the %s device.\n",MyPort);
  126. printf("Status of failed open is: %x\n",LastError);
  127. }
  128. }