Scott Hathaway - 2004-04-05

I am trying to write a program to communicate with a device connected by a serial port (/dev/ttys0) to my Linux server. I decided to create a new class called ManagerPort, which inherits from the GNU Common C++ class TTYSession. I have two problems though.

1) To communicate with the device I have to send an 8 byte string, inwhich each byte reprsents a piece of a message.
For example:

Byte | Value
0      200
1      0
2      0
3      130
...
7      45

To acomplish this I created an unsigned character array to hold the values. When I step through the code this seems to bo correct. Is this the proper way to send a byte string message?

2) Upon seding the above mentioned message I should receive a response from the device. In fact the mgr->isPending(Serial::pendingError,1000)
code returns true, but the the program just blocks on the *mgr >> pinbuf line.
Any ideas?

I really appreciate any help that you all can give?

-------------Code--------------------------------
int main()
{

  try
  {
     ManagerPort mgr = new  
                       ManagerPort"/dev/ttyS0");
     mgr->setSpeed(9600);
     mgr->setCharBits(8);
     mgr->setStopBits(1);
     mgr->setParity(Serial::parityNone);

    if(mgr->operator!() == 0)
      cout << "Serial Connection Ready:" << endl;

    unsigned char test[] = {200,0,0,130,176,0,246,45};
    unsigned char * ptest = test;
    *mgr << ptest;

    if(mgr->isPending(Serial::pendingError,1000))
           cout << "Error" << endl;

    if(mgr->isPending(Serial::pendingOutput,100))
    {

      char inbuf[256];
      char * pinbuf = inbuf;
      *mgr >> pinbuf;
       cout << pinbuf;
    }

  }catch(Serial *err)
  {
     cout << "Error:" << err->getErrorNumber() << endl;
     return 1;
  }

  return 0;
}