dsi_serial.hpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except
  4. in compliance with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2016
  6. All rights reserved.
  7. */
  8. #if !defined(DSI_SERIAL_HPP)
  9. #define DSI_SERIAL_HPP
  10. #include "types.h"
  11. #include "dsi_serial_callback.hpp"
  12. //////////////////////////////////////////////////////////////////////////////////
  13. // Public Definitions
  14. //////////////////////////////////////////////////////////////////////////////////
  15. // Error codes.
  16. #define DSI_SERIAL_ENONE ((UCHAR) 0x00)
  17. #define DSI_SERIAL_DEVICE_GONE ((UCHAR) 0x01)
  18. #define DSI_SERIAL_EWRITE ((UCHAR) 0x02)
  19. #define DSI_SERIAL_EREAD ((UCHAR) 0x03)
  20. #define DSI_SERIAL_EOTHER ((UCHAR) 0xFF)
  21. //////////////////////////////////////////////////////////////////////////////////
  22. // Public Class Prototypes
  23. //////////////////////////////////////////////////////////////////////////////////
  24. class DSISerial
  25. {
  26. protected:
  27. DSISerialCallback *pclCallback; // Local pointer to a DSISerialCallback object.
  28. public:
  29. // Constructor and Destructor
  30. DSISerial();
  31. virtual ~DSISerial();
  32. virtual BOOL AutoInit() = 0;
  33. virtual BOOL Init(ULONG ulBaud_, UCHAR ucDeviceNumber_) = 0;
  34. virtual ULONG GetDeviceSerialNumber() = 0;
  35. virtual BOOL GetDeviceUSBInfo(UCHAR /*ucDevice*/, UCHAR* /*pucProductString*/, UCHAR* /*pucSerialString_*/, USHORT /*usBufferSize_*/) { return FALSE; }
  36. virtual BOOL GetDevicePID(USHORT& /*usPid_*/) { return FALSE; }
  37. virtual BOOL GetDeviceVID(USHORT& /*usVid_*/) { return FALSE; }
  38. virtual void SetCallback(DSISerialCallback *pclCallback_);
  39. /////////////////////////////////////////////////////////////////
  40. // Sets the callback object.
  41. // Parameters:
  42. // *pclCallback_: A pointer to a DSISerialCallback object.
  43. /////////////////////////////////////////////////////////////////
  44. virtual BOOL Open(void) = 0;
  45. /////////////////////////////////////////////////////////////////
  46. // Opens up the communication channel with the serial module.
  47. // Returns TRUE if successful. Otherwise, it returns FALSE.
  48. /////////////////////////////////////////////////////////////////
  49. virtual void Close(BOOL bReset = FALSE) = 0;
  50. /////////////////////////////////////////////////////////////////
  51. // Closes down the communication channel with the serial module.
  52. /////////////////////////////////////////////////////////////////
  53. virtual BOOL WriteBytes(void *pvData_, USHORT usSize_) = 0;
  54. /////////////////////////////////////////////////////////////////
  55. // Writes bytes to the serial port.
  56. // Parameters:
  57. // *pvData_: A pointer to a block of data to be queued
  58. // for sending over the serial port.
  59. // usSize_: The length of the block of data that is
  60. // pointed to by *pvData_.
  61. // Returns TRUE if successful. Otherwise, it returns FALSE.
  62. /////////////////////////////////////////////////////////////////
  63. virtual UCHAR GetDeviceNumber(void) = 0;
  64. /////////////////////////////////////////////////////////////////
  65. // Returns the port number communication is on.
  66. /////////////////////////////////////////////////////////////////
  67. };
  68. #endif // !defined(DSI_SERIAL_HPP)