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.

149 lines
5.0 KiB

  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include "windows.h"
  6. void __cdecl main(int argc,char *argv[]) {
  7. HANDLE hFile;
  8. COMMPROP mp;
  9. DWORD testbaud;
  10. char *MyPort = "COM1";
  11. if (argc > 1) {
  12. MyPort = argv[1];
  13. }
  14. printf("Using port %s\n",MyPort);
  15. if ((hFile = CreateFile(
  16. MyPort,
  17. GENERIC_READ | GENERIC_WRITE,
  18. 0,
  19. NULL,
  20. CREATE_ALWAYS,
  21. FILE_ATTRIBUTE_NORMAL,
  22. NULL
  23. )) != ((HANDLE)-1)) {
  24. printf("We successfully opened the %s port.\n",MyPort);
  25. //
  26. // Get the state of the comm port and then
  27. // adjust the values to our liking.
  28. //
  29. if (!GetCommProperties(
  30. hFile,
  31. &mp
  32. )) {
  33. printf("Couldn't get comm properties: %d\n",GetLastError());
  34. exit(1);
  35. } else {
  36. printf("PacketLength: %d\n",mp.wPacketLength);
  37. if (mp.wPacketLength != sizeof(COMMPROP)) {
  38. printf("Packet length is not sizeof(COMMPROP))\n",sizeof(COMMPROP));
  39. }
  40. printf("PacketVersion: %d\n",mp.wPacketVersion);
  41. if (mp.dwServiceMask != SP_SERIALCOMM) {
  42. printf("Bad Service mask: %x\n",mp.dwServiceMask);
  43. }
  44. printf("MaxTxQueue: %d\n",mp.dwMaxTxQueue);
  45. printf("MaxRxQueue: %d\n",mp.dwMaxRxQueue);
  46. printf("MaxBaud: %d\n",mp.dwMaxBaud);
  47. if (mp.dwProvSubType != PST_RS232) {
  48. printf("Bad subtype: %x\n",mp.dwProvSubType);
  49. }
  50. if (mp.dwProvCapabilities != (PCF_DTRDSR |
  51. PCF_RTSCTS |
  52. PCF_RLSD |
  53. PCF_PARITY_CHECK |
  54. PCF_XONXOFF |
  55. PCF_SETXCHAR |
  56. PCF_TOTALTIMEOUTS |
  57. PCF_INTTIMEOUTS
  58. )) {
  59. printf("Bad capabilities: %x\n",mp.dwProvCapabilities);
  60. }
  61. if (mp.dwSettableParams != (SP_PARITY |
  62. SP_BAUD |
  63. SP_DATABITS |
  64. SP_STOPBITS |
  65. SP_HANDSHAKING |
  66. SP_PARITY_CHECK |
  67. SP_RLSD)) {
  68. printf("Bad settable parameters: %x\n",mp.dwSettableParams);
  69. }
  70. testbaud = BAUD_075 |
  71. BAUD_110 |
  72. BAUD_134_5 |
  73. BAUD_150 |
  74. BAUD_300 |
  75. BAUD_600 |
  76. BAUD_1200 |
  77. BAUD_1800 |
  78. BAUD_2400 |
  79. BAUD_4800 |
  80. BAUD_7200 |
  81. BAUD_9600 |
  82. BAUD_14400 |
  83. BAUD_19200;
  84. if (mp.dwMaxBaud == BAUD_38400) {
  85. testbaud |= BAUD_38400;
  86. } else if (mp.dwMaxBaud == BAUD_56K) {
  87. testbaud |= (BAUD_38400 | BAUD_56K);
  88. } else if (mp.dwMaxBaud == BAUD_128K) {
  89. testbaud |= (BAUD_56K | BAUD_38400 | BAUD_128K);
  90. }
  91. if (testbaud != mp.dwSettableBaud) {
  92. printf("Bad Settable baud rate: %x\n",mp.dwSettableBaud);
  93. }
  94. if (mp.wSettableData != (DATABITS_5 |
  95. DATABITS_6 |
  96. DATABITS_7 |
  97. DATABITS_8)) {
  98. printf("Bad settable data bits: %x\n",mp.wSettableData);
  99. }
  100. if (mp.wSettableStopParity != (STOPBITS_10 |
  101. STOPBITS_15 |
  102. STOPBITS_20 |
  103. PARITY_NONE |
  104. PARITY_ODD |
  105. PARITY_EVEN |
  106. PARITY_MARK |
  107. PARITY_SPACE)) {
  108. printf("Bad settable stop/parity: %x\n",mp.wSettableStopParity);
  109. }
  110. printf("Current TX queue: %d\n",mp.dwCurrentTxQueue);
  111. printf("Current RX queue: %d\n",mp.dwCurrentRxQueue);
  112. printf("ProvSepc1: %x\n",mp.dwProvSpec1);
  113. printf("ProvSepc2: %x\n",mp.dwProvSpec2);
  114. printf("ProvChar[1]: %x\n",mp.wcProvChar[1]);
  115. }
  116. } else {
  117. DWORD LastError;
  118. LastError = GetLastError();
  119. printf("Couldn't open the %s device.\n",MyPort);
  120. printf("Status of failed open is: %d\n",LastError);
  121. }
  122. }