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.

192 lines
3.3 KiB

  1. //
  2. // Test the get modem output signals ioctl.
  3. //
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <time.h>
  8. #include "nt.h"
  9. #include "ntrtl.h"
  10. #include "nturtl.h"
  11. #include "windows.h"
  12. #include "ntddser.h"
  13. //
  14. // This program assumes that it is using a loopback connector.
  15. //
  16. #define MAX_CHECK 100000
  17. ULONG CheckValues[MAX_CHECK];
  18. ULONG ReadValues[MAX_CHECK];
  19. void main(int argc,char *argv[]) {
  20. HANDLE hFile;
  21. DCB MyDcb;
  22. ULONG mask;
  23. ULONG retSize;
  24. char *MyPort = "COM1";
  25. if (argc > 1) {
  26. MyPort = argv[1];
  27. }
  28. if ((hFile = CreateFile(
  29. MyPort,
  30. GENERIC_READ | GENERIC_WRITE,
  31. 0,
  32. NULL,
  33. CREATE_ALWAYS,
  34. FILE_ATTRIBUTE_NORMAL,
  35. NULL
  36. )) == ((HANDLE)-1)) {
  37. printf("Couldn't open the port %s\n",MyPort);
  38. exit(1);
  39. }
  40. if (!GetCommState(
  41. hFile,
  42. &MyDcb
  43. )) {
  44. printf("We couldn't get the comm state\n");
  45. exit(1);
  46. }
  47. //
  48. // Set the baud to 19200 and the data bits to 8
  49. // (We want 8 so that we don't lose any of our data.)
  50. //
  51. MyDcb.fDtrControl = DTR_CONTROL_DISABLE;
  52. MyDcb.fRtsControl = DTR_CONTROL_DISABLE;
  53. if (!SetCommState(
  54. hFile,
  55. &MyDcb
  56. )) {
  57. printf("We couldn't set the comm state\n");
  58. exit(1);
  59. }
  60. if (!EscapeCommFunction(
  61. hFile,
  62. CLRDTR
  63. )) {
  64. printf("We couldn't clear the dtr\n");
  65. exit(1);
  66. }
  67. if (!EscapeCommFunction(
  68. hFile,
  69. CLRRTS
  70. )) {
  71. printf("We couldn't clear the rts\n");
  72. exit(1);
  73. }
  74. if (!DeviceIoControl(
  75. hFile,
  76. IOCTL_SERIAL_GET_DTRRTS,
  77. NULL,
  78. 0,
  79. &mask,
  80. sizeof(mask),
  81. &retSize,
  82. NULL
  83. )) {
  84. printf("We couldn't call the iocontrol\n");
  85. exit(1);
  86. }
  87. if (mask & (SERIAL_DTR_STATE | SERIAL_RTS_STATE)) {
  88. printf("One of the bits is still set: %x\n",mask);
  89. exit(1);
  90. }
  91. if (!EscapeCommFunction(
  92. hFile,
  93. SETRTS
  94. )) {
  95. printf("We couldn't set the rts\n");
  96. exit(1);
  97. }
  98. if (!DeviceIoControl(
  99. hFile,
  100. IOCTL_SERIAL_GET_DTRRTS,
  101. NULL,
  102. 0,
  103. &mask,
  104. sizeof(mask),
  105. &retSize,
  106. NULL
  107. )) {
  108. printf("We couldn't call the iocontrol\n");
  109. exit(1);
  110. }
  111. if (!(mask & SERIAL_RTS_STATE)) {
  112. printf("rts is not set: %x\n",mask);
  113. exit(1);
  114. }
  115. if (!EscapeCommFunction(
  116. hFile,
  117. SETDTR
  118. )) {
  119. printf("We couldn't set the DTR\n");
  120. exit(1);
  121. }
  122. if (!DeviceIoControl(
  123. hFile,
  124. IOCTL_SERIAL_GET_DTRRTS,
  125. NULL,
  126. 0,
  127. &mask,
  128. sizeof(mask),
  129. &retSize,
  130. NULL
  131. )) {
  132. printf("We couldn't call the iocontrol\n");
  133. exit(1);
  134. }
  135. if (!(mask & SERIAL_DTR_STATE)) {
  136. printf("dtr is not set: %x\n",mask);
  137. exit(1);
  138. }
  139. }