Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / IPC_SAP / DEV_SAP / reader / reader.cpp
blob58846a92e12daa6b439015793983f3fa3c7f841c
1 #include "ace/DEV_Addr.h"
2 #include "ace/DEV_Connector.h"
3 #include "ace/TTY_IO.h"
5 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
7 if (argc < 2)
8 ACE_ERROR_RETURN ((LM_ERROR,
9 ACE_TEXT ("usage: %s device-filename\n"),
10 argv[0]),
11 1);
13 ACE_TTY_IO read_dev;
14 ACE_DEV_Connector con;
16 if (con.connect (read_dev,
17 ACE_DEV_Addr (argv[1])) == -1)
18 ACE_ERROR_RETURN ((LM_ERROR,
19 ACE_TEXT ("%p\n"),
20 argv[1]),
21 1);
23 ACE_TTY_IO::Serial_Params myparams;
24 // Try to read default parameters
25 if (read_dev.control (ACE_TTY_IO::GETPARAMS, &myparams) == -1)
27 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("GETPARAMS is not supported\n")));
29 else
31 ACE_DEBUG ((LM_DEBUG, ACE_TEXT("GETPARAMS is supported\n")));
34 myparams.baudrate = 19200;
35 myparams.readmincharacters = 0;
36 myparams.readtimeoutmsec = 10*1000; // 10 seconds
38 if (read_dev.control (ACE_TTY_IO::SETPARAMS, &myparams) == -1)
39 ACE_ERROR_RETURN ((LM_ERROR,
40 ACE_TEXT ("%p control\n"),
41 argv[1]),
42 1);
44 // Read till character 'q'.
45 for (char readback = 'x'; readback != 'q'; )
47 ssize_t bytes_read =
48 read_dev.recv ((void *) &readback, 1);
50 if (bytes_read == 1)
51 ACE_DEBUG ((LM_DEBUG,
52 ACE_TEXT ("read: %c\n"),
53 readback));
54 else if (bytes_read == 0)
55 ACE_DEBUG ((LM_DEBUG,
56 ACE_TEXT ("timeout!\n")));
57 else if (bytes_read == -1)
58 ACE_ERROR_RETURN ((LM_ERROR,
59 ACE_TEXT ("%p recv\n"),
60 argv[1]), 1);
63 return 0;