UART Serial Connection

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#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
It's been a number of years, but on Linux I have not used std::fstream to talk to serial. I have used code similar to:
http://tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html

The devices were:
/dev/ttyS0
/dev/ttyS1
etc
and I always had to change the permissions on them to allow non-root access.

Sorry I think you will have to ask Mr Google.

My 2c
Topic archived. No new replies allowed.