#define ARDUINO_WAIT_TIME 2000

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

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(char *portName);
        // close the connection
        // NOTA: for some reason you can't connect again before exiting
        // the program and running it again
        ~Serial();
        // 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(char *buffer, unsigned int nbChar);
        // check if we are actually connected
        bool IsConnected();
};