Example of using scanf() in an MQX task?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Example of using scanf() in an MQX task?

858 次查看
davepfaltzgraff
Senior Contributor I

I would like to set up a task running under MQX that would "listen" for user input via the virtual COM port. Until the user inputs something, this task is to remain in the idle state.

Since scanf() likes to work on a string, I may need to use a variation of getc() and do my own character handling. But, I'd be OK with that as long as the task remains idle until input is available.

Is there a good example of this?

Thanks

0 项奖励
回复
2 回复数

619 次查看
soledad
NXP Employee
NXP Employee

Hello David,

Could you please check the below thread?

Please let me know if this helps!!!

Has anyone modified the MQX serial driver to include a timeout?


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复

619 次查看
davepfaltzgraff
Senior Contributor I

Hi Sol,

The link you pointed to is interesting and may be useful sometime in the future. What I did to take care of the problem is just what I suggested in the original post. Since the getchar() blocks for the next character, I just let the task accumulate an appropriate string and than pass that through sscanf(). Since I am not concerned about timeouts (yet), it works for me.

My problem was in looking at fscanf() as compared to the combo of getcchar()/sscanf().

Thanks for your input.

0 项奖励
回复