dsi_serial_libusb.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 in compliance
  4. with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2014
  6. All rights reserved.
  7. */
  8. #if !defined(DSI_SERIAL_LIBUSB_HPP)
  9. #define DSI_SERIAL_LIBUSB_HPP
  10. #include "types.h"
  11. #include "dsi_thread.h"
  12. #include "dsi_serial.hpp"
  13. #include "usb_device_libusb.hpp"
  14. #include "usb_device_handle_libusb.hpp"
  15. //////////////////////////////////////////////////////////////////////////////////
  16. // Public Definitions
  17. //////////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////////
  19. // Public Class Prototypes
  20. //////////////////////////////////////////////////////////////////////////////////
  21. class DSISerialLibusb : public DSISerial
  22. {
  23. private:
  24. DSI_THREAD_ID hReceiveThread; // Handle for the receive thread.
  25. DSI_MUTEX stMutexCriticalSection; // Mutex used with the wait condition
  26. DSI_CONDITION_VAR stEventReceiveThreadExit; // Event to signal the receive thread has ended.
  27. BOOL bStopReceiveThread; // Flag to stop the receive thread.
  28. USBDeviceHandleLibusb* pclDeviceHandle; // Handle to the USB device.
  29. const USBDeviceLibusb* pclDevice;
  30. UCHAR ucDeviceNumber;
  31. ULONG ulBaud;
  32. // Private Member Functions
  33. void ReceiveThread();
  34. static DSI_THREAD_RETURN ProcessThread(void *pvParameter_);
  35. BOOL GetDeviceNumberByVendorId(USHORT usVid_, UCHAR& ucDeviceNumber_);
  36. public:
  37. DSISerialLibusb();
  38. ~DSISerialLibusb();
  39. BOOL Init(ULONG ulBaud_, UCHAR ucDeviceNumber_);
  40. BOOL Init(ULONG ulBaud_, USHORT usVid_);
  41. BOOL Init(ULONG ulBaud_, const USBDeviceLibusb& clDevice_, UCHAR ucDeviceNumber_);
  42. void USBReset();
  43. UCHAR GetNumberOfDevices();
  44. // Methods inherited from the base class:
  45. BOOL AutoInit();
  46. ULONG GetDeviceSerialNumber();
  47. BOOL Open();
  48. void Close(BOOL bReset = FALSE);
  49. BOOL WriteBytes(void *pvData_, USHORT usSize_);
  50. UCHAR GetDeviceNumber();
  51. BOOL GetDeviceUSBInfo(UCHAR ucDevice_, UCHAR* pucProductString_, UCHAR* pucSerialString_, USHORT usBufferSize_);
  52. BOOL GetDevicePID(USHORT& usPid_);
  53. BOOL GetDeviceVID(USHORT& usVid_);
  54. };
  55. #endif // !defined(DSI_SERIAL_LIBUSB_HPP)