🔶 C++ Library for Serial Communication with Arduino
Switch branches/tags
Nothing to show
Clone or download
Latest commit c3de733 Sep 3, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
ArduinoCodes Create receiveData.ino May 20, 2016
include Update SerialPort.h May 21, 2016
src improve isConnected method Sep 3, 2018
.gitignore Initial commit May 20, 2016
LICENSE.md Update and rename LICENSE to LICENSE.md May 29, 2016
README.md Update README.md Jul 7, 2016
SerialPort.cbp Serial Port library May 20, 2016
SerialPort.depend Serial Port library May 20, 2016
main.cpp feat(autoConnect) Sep 3, 2018

README.md

SerialPort

C++ Library for Serial Communication with following criteria

  • Plain C++ Compatible
  • Windows Supported
  • Include and Run Type Library
  • supports softwareserial
  • supports serial event
  • fixed minor bugs

Documentation

Here is a blog post about the library

Initialization

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

char* portName = "\\\\.\\COM20";

//Declare a global object
SerialPort *arduino;

int main(void)
{
  arduino = new SerialPort(portName);
  std::cout << "is connected: " << arduino->isConnected() << std::endl;
}

Sending Data

#define DATA_LENGTH 255

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

char* portName = "\\\\.\\COM20";

//Declare a global object
SerialPort *arduino;

//Here '\n' is a delimiter 
char *sendString = "Hello World\n"; 

int main(void)
{
  arduino = new SerialPort(portName);
  if (arduino->isConnected()){
    bool hasWritten = arduino->writeSerialPort(sendString, DATA_LENGTH);
    if (hasWritten) std::cout << "Data Written Successfully" << std::endl;
    else std::cout << "Data was not written" << std::endl;
  }
}

Receiving Data

#define DATA_LENGTH 255

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

char* portName = "\\\\.\\COM20";

//Declare a global object
SerialPort *arduino;

//Here '\n' is a delimiter 
char receivedString[DATA_LENGTH];

int main(void)
{
  arduino = new SerialPort(portName);
  if (arduino->isConnected()){
    int hasRead = arduino->readSerialPort(receivedString, DATA_LENGTH);
    if (hasRead) printf("%s", receivedString);
    else printf("Error occured reading data");
  }
}