I'm using the serial part of the library through a ttystream. I can't seem to find a way to get a character or determine if there is one waiting without my program blocking.
Here is a quick program to illustrate the problem:
#include "cc++/serial.h"
#include <iostream.h>
using namespace ost;
main() {
ttystream modem("/dev/cuaa0");
if (!modem) {
cerr << "Unable to open modem\n";
return 0;
}
while (1) {
cout << "Going to wait\n";
char c=modem.get();
cout << "Got a (" << c << ")\n";
}
}
When run it outputs:
./test
Going to wait
Got a (A)
Going to wait
Got a (T)
Going to wait
Got a (Z)
Going to wait
)ot a (
Going to wait
)ot a (
Going to wait
Got a (
)
Going to wait
Got a (O)
Going to wait
Got a (K)
Going to wait
)ot a (
Going to wait
Got a (
)
Going to wait
This tells me that it's blocking on the get() call. How can I tell if there are chars waiting?
-Michael
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm using the serial part of the library through a ttystream. I can't seem to find a way to get a character or determine if there is one waiting without my program blocking.
Here is a quick program to illustrate the problem:
#include "cc++/serial.h"
#include <iostream.h>
using namespace ost;
main() {
ttystream modem("/dev/cuaa0");
if (!modem) {
cerr << "Unable to open modem\n";
return 0;
}
modem.setSpeed(38400);
modem.setCharBits(8);
modem.setParity(Serial::parityNone);
modem.setStopBits(1);
modem.setFlowControl(Serial::flowHard);
modem.toggleDTR(500);
modem.interactive(true);
modem << "ATZ\r";
while (1) {
cout << "Going to wait\n";
char c=modem.get();
cout << "Got a (" << c << ")\n";
}
}
When run it outputs:
./test
Going to wait
Got a (A)
Going to wait
Got a (T)
Going to wait
Got a (Z)
Going to wait
)ot a (
Going to wait
)ot a (
Going to wait
Got a (
)
Going to wait
Got a (O)
Going to wait
Got a (K)
Going to wait
)ot a (
Going to wait
Got a (
)
Going to wait
This tells me that it's blocking on the get() call. How can I tell if there are chars waiting?
-Michael
shouldn't
while (modem.isPending(pendingInput, suitableTimeout)) {
cout << "not waiting for nobody!" << endl;
char c;
modem.get(c);
cout << "got a (" << c << ")" << endl;
}
do the trick?