07-26-2022 06:53 AM
CODE:
InstallComCallback (comno, LWRS_RECEIVE, 20, HELLO, auto_call, read_buf); // auto call for data
void auto_call()
{
printf("example code");
}
In the above code , when comport is open the it will install comcallback and when Hello is detect it will print some statement in the standard i/o then it goes for auto_call fuction and print the statement. Now what i need is when" Hello " command is set for 5 times then my auto_call function should work for 5 times.
for(char i;i <6;i++)
{
InstallComCallback (comno, LWRS_RECEIVE, 20, HELLO, auto_call, read_buf); // auto call for data
}
Required output is
Hello
example code
.
.
.
Hello
example code ( 5 times )
Please guide me in this case .
07-27-2022 09:59 AM
I'm afraid things cannot work this way!
When installing a COM callback with LWRS_RECEIVE according to your code the callback will be fired when there are at least 20 characters in the input queue and won't be fired again until the queue falls below that 20-characters limit again. What you may want to do is continue reading in the callback until the queue gets empty processing all messages received.
On the other hand, while I don't know what your HELLO is, that parameter is not used in case or LWRS_RECEIVE.
Another hint clearly stated in function help is that you can only install one callback per com port, so your loop is useless: only the last callback will be installed on the port and it will remain active until it is explicitly discarded or the port is closed.
Finally, be careful when passing a string in callbackData parameter (I suppose your read_buf actually is a string): if that pointer is no more valid when the callback executes you are likely to get tons of errors and finally crash your app!