SERIAL++ library: simple serial port access

◆ main()

int main ( int  iargc,
char *  argv[] 
)

Definition at line 55 of file portread.cc.

References Options::delimiter, Options::device, PORTREAD_CVSID, PORTREAD_VERSION, serialport::SerialPort::read(), and Options::verbose.

56 {
57 
58  // define usage information
59  char usage_text[]=
60  {
61  PORTREAD_VERSION "\n"
62  "usage: portread [-p device] [-v] [-d delimiter]" "\n"
63  " or: portread --help|-h" "\n"
64  };
65 
66  // define full help text
67  char help_text[]=
68  {
70  };
71 
72  // define commandline options
73  using namespace tfxx::cmdline;
74  static Declare options[]=
75  {
76  // 0: print help
77  {"help",arg_no,"-"},
78  // 1: verbose mode
79  {"v",arg_no,"-"},
80  // 2: device name
81  {"p",arg_yes,"/dev/ttyS0"},
82  // 3: delimiter name
83  {"d",arg_yes,"\r"},
84  {NULL}
85  };
86 
87  // no arguments? print usage...
88  if (iargc<1)
89  {
90  cerr << usage_text << endl;
91  exit(0);
92  }
93 
94  // collect options from commandline
95  Commandline cmdline(iargc, argv, options);
96 
97  // help requested? print full help text...
98  if (cmdline.optset(0))
99  {
100  cerr << usage_text << endl;
101  cerr << help_text << endl;
102  exit(0);
103  }
104 
105  /*
106  // dummy operation: print option settings
107  for (int iopt=0; iopt<2; iopt++)
108  {
109  cout << "option: '" << options[iopt].opt_string << "'" << endl;
110  if (cmdline.optset(iopt)) { cout << " option was set"; }
111  else { cout << "option was not set"; }
112  cout << endl;
113  cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
114  cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
115  cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
116  cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
117  cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
118  cout << " argument (bool): '";
119  if (cmdline.bool_arg(iopt))
120  { cout << "true"; } else { cout << "false"; }
121  cout << "'" << endl;
122  }
123  while (cmdline.extra()) { cout << cmdline.next() << endl; }
124 
125  // dummy operation: print rest of command line
126  while (cmdline.extra()) { cout << cmdline.next() << endl; }
127  */
128 
129  Options opt;
130 
131  opt.verbose=cmdline.optset(1);
132  opt.device=cmdline.string_arg(2);
133  opt.delimiter=cmdline.string_arg(3);
134 
135  serialport::SerialPort port(opt.device);
136 // port.debug(true);
137  std::string text=port.read(opt.delimiter);
138  cout << text << endl;
139 }
std::string delimiter
Definition: portread.cc:52
#define PORTREAD_CVSID
Definition: portread.cc:38
bool verbose
Definition: portread.cc:51
std::string device
Definition: portread.cc:52
#define PORTREAD_VERSION
Definition: portread.cc:36
Here is the call graph for this function: