Can anybody help me to solve this strange problem?
This code snippet copied out from QNX6.3 help system, but the select() function always return with zero (timed out) after 5 secs:
(“select timed out” )
Can anyone give a short explanation what can be the problem, please?
Any help are welcome…
It has compiled as follows:
qcc -o console console.c
/*
This example opens a console and a serial port for
read mode, and calls select() with a 5 second timeout.
It waits for data to be available on either descriptor.
*/
That is clear, but when I have changed the tv value to 0 or 1 sec then the problem is ALSO the same.
select() always returned with 0 value (timeout). It is the case 0: code block in switch().
It seems to be there are no any free descriptors.
How is it possible?
Do you actually have a device connected to serial port 1 that’s generating data? Otherwise the selector for /dev/ser1 isn’t going to become ready because there is nothing to read. The same goes for console 1.
Yes, exactly. The example code is included above. Console and serial device only, no other.
I have tried it with and without photon. The result was same.
Yes, the select() always gives back 0 value, if tv.tv_sec = 5 or zero.
There are four serial ports, the Port 1 is enabled (3F8-IRQ4)and Port 2-3-4 are disabled in BIOS. All are unconnected. The mainboard is Advantech PCM-9577F. OS is QNX6.3 SP2 Momentics PE.
On what issue do you wish advice? From your description, the code and hardware are performing as one would expect. If you wish a different outcome, you will have to explain why. You could remove the timeout, and then the select will wait forever or until there is some input.
If you want select to return with actual data from the serial port then you need to attach a serial device. The simplest one you can attach is an old serial mouse.
Then run your program and move the mouse or press a mouse button and select will return with one of the selectors active (the one for the serial port).
The purpose of select is to wait on data from several sources. If none of those sources (serial, console) have any data it will wait forever. Since you specified a timeout value (5 seconds), the forever part ends up being 5 seconds.