Hi, I am trying to implement a code that is able to receive input from a serial communication. I believe that it is possible to do this using fstream, but so far I have been unsuccessful. The code below should echo everything received on screen:
Code:
#include <iostream>
#include <fstream>
int main(int argc, const char * argv[])
{
std::string msg = "";
std::cout << "Hello, World!\n";
std::fstream file("/dev/tty.usbserial-A800F2GZ");
if (file.good())
{
while(1){
file >> msg;
std::cout << "Response: " << msg << std::endl;
}
}
return 0;
}
Any ideas?
Currently using: Mac OS X 10.8.5, Xcode 5