Hello, I am trying to work with serial device connected to mbed via tx and rx. Messages that serial device sends to mbed have variable length an arrives only vhen status changes, so not repeatedly.
My task is that message which arrives is processed and then sent by USB. But I found problem - If nothing arrives, nothing is sent but I want that message via USB is sent repeatedly (say about each 20 ms).
So if nothing is recieved last recieved message have to be send repeatedly until new message is recieved, processed and from this time this new values have to be send repeatedly.
I was thinking about ticker or something like that but nothing was working.
In the code I declare function to recieve message:
void retrieve_message () {
if (serial.readable()) {
serial.scanf("%s", &buff);
}
}
Then function to process data:
void process (){
// process data here
}
Then I use:
int main() {
pc.baud(115200);
serial.baud(115200);
pc.printf("/n/rHello /r/n");
while (1) {
retrieve_message();
process();
hid.send(&processed_data);
}
}
There are many missing lines because I wanted to be easy to see what I do.
Everything works but only when data are recieved from serial device but my task is output data send repeatedly and message recieved from serial have to modify this repeatedly sent values.
Can anybody help me please?
Hello, I am trying to work with serial device connected to mbed via tx and rx. Messages that serial device sends to mbed have variable length an arrives only vhen status changes, so not repeatedly.
My task is that message which arrives is processed and then sent by USB. But I found problem - If nothing arrives, nothing is sent but I want that message via USB is sent repeatedly (say about each 20 ms).
So if nothing is recieved last recieved message have to be send repeatedly until new message is recieved, processed and from this time this new values have to be send repeatedly.
I was thinking about ticker or something like that but nothing was working.
In the code I declare function to recieve message:
Then function to process data:
Then I use:
There are many missing lines because I wanted to be easy to see what I do.
Everything works but only when data are recieved from serial device but my task is output data send repeatedly and message recieved from serial have to modify this repeatedly sent values.
Can anybody help me please?