//
// Created by Ht on 2021/1/9.
//

#ifndef LIBDEVCPP_WIN32SERIALPORT_H
#define LIBDEVCPP_WIN32SERIALPORT_H

#if defined(WIN32) || defined(CYGWIN)

#include "SerialPort.h"
#include <windows.h>


namespace jedge {

    class JE_API Win32SerialPort :
            public SerialPort {

    protected:
        HANDLE m_hCom = nullptr;							//***serial_test_ran***��HANDLE����int��?
        OVERLAPPED m_ov;
        COMMTIMEOUTS m_CommTimeouts;		    //***serial_test_ran***��ɾ������
        DCB m_dcb;
        DWORD m_dwComm_events;

        bool m_bThread_alive = false;
        HANDLE m_hThr_shut_event = nullptr;
        HANDLE m_hEvent_array[2];

    public:
        explicit Win32SerialPort(const std::string& portName);

        bool initSerialPort(unsigned int nBaud) override;

        bool writeData(uint8_t *buff, int32_t len) override;

    protected:
        void procSerialDataEvent() override;

        void readSerialData() override;

    public:
        bool closeSerialPort() override;
    };

}

#endif //WIN32 CYGWIN

#endif //LIBDEVCPP_WIN32SERIALPORT_H
