Leaked source code of windows server 2003
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.

117 lines
3.0 KiB

  1. /*
  2. *
  3. * REVISIONS:
  4. * TSC17May93: Added SmartSerialPort :: SYSTClosePort()
  5. * TSC31May93: Added define for _theConfigManager, changed SmartSerialPort
  6. * to native NT, added error logging
  7. * rct03Nov93: Broke off from port.cxx
  8. * cad08Dec93: slight interface changes, added constructors
  9. * cad04Jan94: added debug flags
  10. * pcy08Feb94: #if UNIX around theRLock
  11. * rct07Mar94: Re-Added SimpleSerialPort::Close()
  12. * jps14Jul94: commented out INCL_NOPMAPI; put os2.h inside extern "C"
  13. * daf25Nov95: support for PNP cable
  14. * srt24Jan96: Windows specific functions moved into w31port.cxx
  15. * srt24Jan96: added theCableType field initialization on windows
  16. * pav16Jun96: #ifdef !NT constructors that NT doesn't use
  17. * dml17Jun96: Added missing return value for GetCableType
  18. * pcy28Jun96: Initialize file handle so we dont crash
  19. * cgm05Jul96: Changed Simple::Initialize to check Open() error code
  20. * poc28Sep96: Added valuable debugging code.
  21. * mds28Dec97: Initialized FileHandle to INVALID_HANDLE_VALUE in SimpleSerialPort
  22. * constructor (for NT)
  23. */
  24. #include "cdefine.h"
  25. extern "C"{
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. }
  30. #include "serport.h"
  31. #include "_defs.h"
  32. #include "serport.h"
  33. #include "err.h"
  34. #include "cfgmgr.h"
  35. #include "utils.h"
  36. //
  37. // Smart Serial Port class
  38. //-------------------------------------------------------------------------
  39. //++srb
  40. SmartSerialPort::SmartSerialPort(cableTypes aCableType) :
  41. DataBits ("8"),
  42. Parity ("0"),
  43. StopBits ("1"),
  44. BaudRate (2400),
  45. RetryStatus(0),
  46. theWaitTime(40L)
  47. {
  48. theCableType = aCableType;
  49. }
  50. //++srb
  51. SmartSerialPort::SmartSerialPort(TCHAR* aPortName, cableTypes aCableType) :
  52. DataBits ("8"),
  53. Parity ("0"),
  54. StopBits ("1"),
  55. BaudRate (2400),
  56. RetryStatus(0),
  57. theWaitTime(40L)
  58. {
  59. theCableType = aCableType;
  60. #if C_API & C_WIN32
  61. FileHandle=INVALID_HANDLE_VALUE;
  62. #endif
  63. lstrcpyn(theSmartSerialPortName,aPortName, 32);
  64. }
  65. //--------------------------------------------------------------------
  66. INT SmartSerialPort::Open()
  67. {
  68. int ret = SYSTOpenPort();
  69. SetState (OPEN);
  70. return ret;
  71. }
  72. //-----------------------------------------------------------------------------
  73. INT SmartSerialPort::Write(PCHAR command)
  74. {
  75. return SYSTWriteToPort(command);
  76. }
  77. //-----------------------------------------------------------------------------
  78. INT SmartSerialPort::Read(PCHAR buffer, USHORT* size, ULONG timeout)
  79. {
  80. INT err = SYSTReadFromPort(buffer, size, timeout);
  81. return err;
  82. }
  83. //------------------------------------------------------------------------------
  84. INT SmartSerialPort::Close()
  85. {
  86. if (GetState() == OPEN)
  87. SYSTClosePort();
  88. SetState(CLOSED);
  89. return ErrNO_ERROR; //TRUE; (SRT)
  90. }