Dear All, Who know how hyperterminal identifies input state of cpu connected to PC via serial port ? For example when codes in CPU reaches to scanf() func. the hyperterminal switches to input situation and is ready to receive data from user without any extra data exchanging . Regards. Majid
Normal Mode : Connect Time and CPU does any function except input functions ex. getchar() or scanf() That Situation : When CPU reaches to scanf() and waits for serial data from PC In Normal mode We type via keyboard and don't see any char in hyper editbox . But when cpu run an input command , we can see what we are typing and with an Enter key , our chars transferred to CPU Get It ?!
"But when cpu run an input command , we can see what we are typing and with an Enter key , our chars transferred to CPU" This is because scanf() calls getchar() to receive data from the UART. getchar() in turn calls putchar() to echo those characters back out through the UART. Hyperterminal displays those echoed characters. If the 'CPU' is doing something else you won't see the characters you type appear in the hyperterminal window. Most of the format specifiers you use with scanf() delimit their input when a character that is inappropriate for that specifier is received. For instance: scanf("%d",&someint); If you type '123[Enter]' scanf will return control to the calling function when the enter key is pressed, because that character is not valid as part of an integer. Every time a key is pressed that key will be echoed back to hyperterminal. Note that hyperterminal is completely dumb, it just displays characters received by the PC UART and transmits characters you type out through the PC UART.
I think that an (arguably) more conventional means of dealing with user input is to use a simple means of string input (e.g., repetitive getchar()'s until \r) and then parsing the string with sscanf() (or whatever). Sidenote: Hmm, several "means" in there -- I should be a patent attorney.