I'm working with a serial device controller that works like the following:
1. write a cmd to the controller
2. immediately read the cmd back with an ACK/NCK byte attached
3. the serial device controller then transmits the command to a dest device on its network
4. the dest device responds back with a msg (asynchronously )
5. then I can read the dest device response from the controller
i'm currently using serial.datarece ived. I use removehandler for the datareceived method when i'm in steps 1 & 2 above so i can read the response immediately. Then restore addhandler when the msg has been sent so the datareceived event can handle the msgs in step 5.
I use another thread to process the buffer. when i'm expecting a response like in step 4/5 above I add the response to a generic.list.
Overall, in my main thread i use a send and wait approach when transmiting a msg and getting a response. there is a timeout so i don't wait indefinitely. The wait routine looks at the msgs in the generic.list for the expected response and acts accordingly.
My question is how can i break the send and wait routine into two threads so i can continuously send msgs on one thread (for step 1 above) and then match the responses collected (in step 5) to the original msgs sent?
An example would be great, but i wasn't able to find one.
1. write a cmd to the controller
2. immediately read the cmd back with an ACK/NCK byte attached
3. the serial device controller then transmits the command to a dest device on its network
4. the dest device responds back with a msg (asynchronously )
5. then I can read the dest device response from the controller
i'm currently using serial.datarece ived. I use removehandler for the datareceived method when i'm in steps 1 & 2 above so i can read the response immediately. Then restore addhandler when the msg has been sent so the datareceived event can handle the msgs in step 5.
I use another thread to process the buffer. when i'm expecting a response like in step 4/5 above I add the response to a generic.list.
Overall, in my main thread i use a send and wait approach when transmiting a msg and getting a response. there is a timeout so i don't wait indefinitely. The wait routine looks at the msgs in the generic.list for the expected response and acts accordingly.
My question is how can i break the send and wait routine into two threads so i can continuously send msgs on one thread (for step 1 above) and then match the responses collected (in step 5) to the original msgs sent?
An example would be great, but i wasn't able to find one.