Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

void Serial::Main (  ) [virtual]

User override function for the main execution routine of the thread. A descendent class must provide the code that will be executed in the thread within this function.

Note that the correct way for a thread to terminate is to return from this function.

Implements PThread.

Definition at line 109 of file serial.cxx.

References PTrace::Blocks, PSerialChannel::Close(), PTrace::FileAndLine, PProcess::GetArguments(), PProcess::GetManufacturer(), PProcess::GetName(), PProcess::GetOSHardware(), PProcess::GetOSName(), PProcess::GetOSVersion(), PProcess::GetVersion(), PTrace::Initialise(), PThread::Sleep(), PTrace::Thread, PTrace::Timestamp, and PThread::WaitForTermination().

{

 PConfigArgs args(GetArguments());

// Example command line is :
// serial --hardwareport 0 --baud 4800 --parity odd --stopbits 1 --databits 8 --flowcontrol XonXoff

  args.Parse(
#if PTRACING
             "t-trace."              "-no-trace."
             "o-output:"             "-no-output."
#endif
#ifdef PMEMORY_CHECK
             "-setallocationbreakpoint:"
#endif
             "-baud:"
             "-databits:"
             "-parity:"
             "-stopbits:"
             "-flowcontrol:"
             "-hardwareport:"
             "v-version."
             "h-help."
          , FALSE);

#if PMEMORY_CHECK
  if (args.HasOption("setallocationbreakpoint"))
    PMemoryHeap::SetAllocationBreakpoint(args.GetOptionString("setallocationbreakpoint").AsInteger());
#endif

  PStringStream progName;
  progName << "Product Name: " << GetName() << endl
           << "Manufacturer: " << GetManufacturer() << endl
           << "Version     : " << GetVersion(TRUE) << endl
           << "System      : " << GetOSName() << '-'
           << GetOSHardware() << ' '
           << GetOSVersion();
  cout << progName << endl;

  if (args.HasOption('v'))
    return;


#if PTRACING
  PTrace::Initialise(args.GetOptionCount('t'),
                     args.HasOption('o') ? (const char *)args.GetOptionString('o') : NULL,
         PTrace::Blocks | PTrace::Timestamp | PTrace::Thread | PTrace::FileAndLine);
#endif

  if (args.HasOption('h')) {
      cout << endl
#if PTRACING
           <<  "-t   --trace                     Debugging. Using more times for more detail" << endl
           <<  "-o   --output                    name of trace output file. If not specified, goes to stdout" << endl
#endif
#ifdef PMEMORY_CHECK
           <<  "     --setallocationbreakpoint   stop program on allocation of memory block number" << endl
#endif
           <<  "     --baud                      Set the data rate for serial comms" << endl
           <<  "     --databits                  Set the number of data bits (5, 6, 7, 8)" << endl
           <<  "     --parity                    Set parity, even, odd or none " << endl
           <<  "     --stopbits                  Set the number of stop bits (0, 1, 2) " << endl
           <<  "     --flowcontrol               Specifiy flow control, (none rtscts, xonxoff)" << endl
           <<  "     --hardwareport              Which serial port to use, 0, 1, 2..." << endl
           <<  "-v   --version                   Print version information and exit" << endl
           <<  "-h   --help                      Write this help out.                   " << endl
           << endl;
      return;
  }


  if (!Initialise(args)) {
      cout << "Failed to initialise the program with args of " << args << endl;
      PThread::Sleep(100);
      return;
  }

  UserInterfaceThread *ui = new UserInterfaceThread(*this);
  SerialInterfaceThread *si = new SerialInterfaceThread(*this);

  ui->WaitForTermination();

  serial.Close();

  si->WaitForTermination();

  delete ui;
  delete si;

  cout << endl << "End of program" << endl << endl;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index