#ifndef SERIAL_H_INCLUDED
#define SERIAL_H_INCLUDED

//#include <windows.h>
#include <wx/msw/private.h>
#include <cstdlib>
#include <cstdio>

#define ARDUINO_WAIT_TIME 2000

/**
Got from: https://playground.arduino.cc/Interfacing/CPPWindows
**/

class Serial
{
    private:
        //Serial comm handler
        HANDLE hSerial;
        //Connection status
        bool connected;
        //Get various information about the connection
        COMSTAT status;
        //Keep track of last error
        DWORD errors;

    public:
        //Initialize Serial communication with the given COM port
        Serial();
        bool conn(const char *portName, int baud);
        //Close the connection
        ~Serial();
        void disconn();
        //Read data in a buffer, if nbChar is greater than the
        //maximum number of bytes available, it will return only the
        //bytes available. The function return -1 when nothing could
        //be read, the number of bytes actually read.
        int ReadData(char *buffer, unsigned int nbChar);
        //Writes data from a buffer through the Serial connection
        //return true on success.
        bool WriteData(const char *buffer, unsigned int nbChar);
        //Check if we are actually connected
        bool IsConnected();
};

#endif // SERIAL_H_INCLUDED
