AnsweredAssumed Answered

poll stdin

Question asked by Adrian Rockall on Sep 7, 2015
Latest reply on Oct 19, 2015 by Adrian Rockall

I'm using KDS 3.0 with KSDK 1.2 and MQX built with IAR.

I want to poll the stdin port to see if a character has been received so I can process code in a loop until the user presses a key in the console. I am using the shell to launch the code hence why I'm using stdin rather than other methods to access the ports.


So far the only way I can find to do this is to modify the nio_tty.c file so the nio_tty_ioctll function supports IO_IOCTL_CHAR_AVAIL as follows:

        case IOCTL_ABORT:

            retval = _nio_vioctl(devc->fd, error, IOCTL_ABORT, ap);


          //Added support for checking if characters are available

        case IO_IOCTL_CHAR_AVAIL:

            retval = _nio_vioctl(devc->fd, error, IO_IOCTL_CHAR_AVAIL, ap);



Then in my code I can use:

  if ((_nio_ioctl( stdin->_FD, &err, IO_IOCTL_CHAR_AVAIL, &cnt ) == 0) && (cnt > 0) && (fgetc( stdin ) == 27 ))





Have I missed another currently supported method or can this be added to the KSDK / MQX by freescale in the next update?


Best regards,