bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with commoncpp serial


From: I-Real - Mark Ebbers
Subject: Problem with commoncpp serial
Date: Fri, 11 Dec 2009 13:37:27 +0100
User-agent: Thunderbird 2.0.0.23 (X11/20090817)

Hello,

For a project I'm using Commoncpp and its Serial support. But I'm seeing some weird behavior when reading from a serial device (modem).
Sometimes after a while, isPending(pendingInput) gives back true and then using uflow for reading one character, results in a EOF. (and this results in a loop) How is this possible? (The device did not send anything). Is it an error on the serial port?

How is this possible? Do I something wrong, is it a bug or is it some problem with my system?

My system:
Linux Ubuntu 9.04
Commoncpp 1.7.3
GCC 4.3.3
Onboard serial port and usb to serialconverter.
Siemens and Wavecom modem.

Output of the test program:
43 - +
67 - C
82 - R
69 - E
71 - G
58 - :
32 - 
49 - 1
13 -
10 -

13 -
10 -

43 - +
87 - W
73 - I
78 - N
68 - D
58 - :
32 - 
52 - 4
13 -
10 -

-1 - �
-1 - �
-1 - �  <-------- how is this possible??
-1 - �
-1 - �

I have made a little example to demonstrate the problem.

main.cc
#include <stdlib.h>
#include "Modem.h"

/*
 *
 */
int main(int argc, char** argv)
{

    Modem modem("/dev/ttyS0");
    modem.run();


    return (EXIT_SUCCESS);
}

Modem.h
#ifndef _MODEM_H
#define    _MODEM_H

#include <cc++/serial.h>

class Modem : ost::ttystream {
public:
    Modem(std::string device);
    virtual ~Modem();

    void run();
private:

};

#endif    /* _MODEM_H */

Modem.cc
#include "Modem.h"

Modem::Modem(std::string device) : ost::ttystream((char*)device.c_str())
{
    interactive(true);
    if (setSpeed(9600)) std::cout << getErrorString() <<std:: endl;
    if (setCharBits(8)) std::cout << getErrorString() << std::endl;
    if (setParity(ost::Serial::parityNone)) std::cout << getErrorString() << std::endl;
    if (setStopBits(1)) std::cout << getErrorString() << std::endl;
    if (setFlowControl(ost::Serial::flowHard)) std::cout << getErrorString() << std::endl;
}

Modem::~Modem()
{
}

void Modem::run()
{
    while(1){
        while(isPending(ost::Serial::pendingInput)){       
            int ch = uflow();
            std::cout << (int)ch << " - " << (char)ch << std::endl;
        }
        sleep(1);
    }   
}






Met vriendelijke groet,
Mark Ebbers

I-Real
Postbus 593
7000 AN Doetinchem
T: +31 (0)314 366600
F: +31 (0)314 363410
E: address@hidden
I: www.i-real.nl



reply via email to

[Prev in Thread] Current Thread [Next in Thread]