Last active
May 22, 2016 12:59
-
-
Save manashmandal/e7bc21367b69f14b78ff2856ea59e454 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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