Skip to content

Instantly share code, notes, and snippets.

@manashmandal
Last active May 22, 2016 12:59
Show Gist options
  • Save manashmandal/e7bc21367b69f14b78ff2856ea59e454 to your computer and use it in GitHub Desktop.
Save manashmandal/e7bc21367b69f14b78ff2856ea59e454 to your computer and use it in GitHub Desktop.
//This code snippet will help you to read data from arduino
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SerialPort.h"
using std::cout;
using std::endl;
/*Portname must contain these backslashes, and remember to
replace the following com port*/
char *port_name = "\\\\.\\COM20";
//String for incoming data
char incomingData[MAX_DATA_LENGTH];
int main()
{
SerialPort arduino(port_name);
if (arduino.isConnected()) cout << "Connection Established" << endl;
else cout << "ERROR, check port name";
while (arduino.isConnected()){
//Check if data has been read or not
int read_result = arduino.readSerialPort(incomingData, MAX_DATA_LENGTH);
//prints out data
puts(incomingData);
//wait a bit
Sleep(10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment