OpenQNX :: The QNX Community Portal

Aug 08, 2008 - 12:39 AM
Google
  Web openqnx.com   
     Create an account Home · Submit News · QNX Forums · QNX Download · Search   
_
Main Menu
Who's Online
There are 34 unlogged users and 0 registered users online.

You can log-in or register for a user account here.

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
bmclean
Post subject: QNX6 does not support CONIO.H functions  PostPosted: May 15, 2008 - 04:27 PM
New Member


Joined: May 15, 2008
Posts: 9

There are a couple of functions that CONIO.H provided that QNX6 no longer supports. I need the abilities that getch() and kbhit() provided in my code, and I have tried to make the read() and tcischars() functions work with stdin, but these functions are looking for a file pointer and not a device. How should I approach this problem?

If anyone knows of function within qnx6 that respond in the same way as getch() and kbhit(), please reply.
 
 View user's profile Send private message  
Reply with quote Back to top
ysinitsky
Post subject: RE: QNX6 does not support CONIO.H functions  PostPosted: May 16, 2008 - 08:20 PM
Senior Member


Joined: Dec 14, 2005
Posts: 103

Hello Bmclean,
Please consider the following sample code which provides the required functionality.
Thanks,
Yuriy
---------
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>
int main(int argc, char** argv)
{
int bytes_to_read;
char buf [ BUFSIZ ];
struct termios termios_p;
// Set raw mode:
if (tcgetattr( 1, &termios_p ) == -1 )
{
perror ("tcgetattr");
return (-1);
}
if (cfmakeraw( &termios_p ) == -1 )
{
perror ("cfmakeraw");
return (-1);
}
if (tcsetattr( 1, TCSADRAIN, &termios_p )== -1)
{
perror ("tcsetattr");
return (-1);
}
for ( ; ; )
{
bytes_to_read = tcischars( 1); // kbhit
if (bytes_to_read == -1 )
{
perror ("tcischars");
return (-1);

}

if (bytes_to_read >0 )
{
fprintf (stderr, "kbhit %d", bytes_to_read);
read( 1, buf, bytes_to_read ) ; // getch()
}
}
return 0;
}
 
 View user's profile Send private message  
Reply with quote Back to top
bmclean
Post subject: RE: QNX6 does not support CONIO.H functions  PostPosted: May 20, 2008 - 12:59 PM
New Member


Joined: May 15, 2008
Posts: 9

This function does emulate the getch() and kbhit() functions, and I see if you save the termios struct before making it "raw" tou can restore it latter.

Thanks.

BMcLean


Last edited by bmclean on May 23, 2008 - 01:31 PM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
rgallen
Post subject: Re: RE: QNX6 does not support CONIO.H functions  PostPosted: May 22, 2008 - 05:31 PM
QNX Master


Joined: Jul 11, 2002
Posts: 600

bmclean wrote:
This function does emulate the getch() and kbhit() functions, but it causes the “\n” new line to insert the line feed only, missing the carriage return. I would imagine that there is some parameter in the termios struct that can change this, but I don’t know what this would be.


I think OPOST might be what you're looking for.

btw: these functions only ever appeared in QNX because the Watcom compiler (which came from DOS) brought them with it. There really is no place in an RTOS for a kbhit() function (select on READ is the proper solution).
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
All logos and trademarks in this site are property of their respective owners. The comments are property of their posters.
Powered by OpenQNX: The QNX Community Portal Site
QNX and the QNX logo are registered trademarks of QNX Software Systems.