summaryrefslogtreecommitdiff
path: root/examples/IPC_SAP/DEV_SAP/writer/writer.cpp
blob: 68a4e8bd6ec66fb8890eaa8b070d596fe0abfc70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// $Id$

#include "ace/DEV_Connector.h"
#include "ace/TTY_IO.h"

ACE_RCSID(writer, writer, "$Id$")

int 
main (int argc, char *argv[])
{
  if (argc < 2)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "usage: %s device-filename\n",

                       argv[0]), 1);

  ACE_TTY_IO write_dev;
  ACE_DEV_Connector con;

  if (con.connect (write_dev,
                   ACE_DEV_Addr (argv[1])) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,

                       "%p\n",
                       argv[1]),
                      1);

  ACE_TTY_IO::Serial_Params myparams;
  myparams.baudrate = 9600;
  myparams.parityenb = 1;
  myparams.paritymode = "EVEN";
  myparams.databits = 8;
  myparams.stopbits = 1;
  myparams.readtimeoutmsec = 200;
  myparams.ctsenb = 0;
  myparams.rcvenb = 1;

  if (write_dev.control (ACE_TTY_IO::SETPARAMS,
                         &myparams) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "control"),
                      1);

  ACE_DEBUG ((LM_DEBUG,
              "enter character to send, q terminates :\n"));

  for (char writeto;
       ACE_OS::read (ACE_STDIN, &writeto, 1) != -1;
       )
    {
      ssize_t bytes_written =
        write_dev.send_n ((void *) &writeto,
                          1);

      if (bytes_written != 1)
	ACE_ERROR_RETURN ((LM_ERROR,
                           "%p\n",
                           "send"),
                          1);
      if (writeto == 'q')
	break;
    }

  if (write_dev.close () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "close"),
                      1);
  return 0;
}