|
-
February 7th, 2009, 01:22 PM
#9
Re: VB2005 Serial Port Read Drop Off
No the program was working fine but if a block of code was running when the data came into the port. Let's say for example it was only 4 bytes that I was expecting which would complete very quickly. Also for example the user clicked on something about the the same time the data was arriving although slightly before it arrived the event would not fire. If additional data came in later then the event would fire and the previous data would be there in the buffer waiting and readable but if those 4 bytes were waiting on a response then the response would never be sent as the code would not run.
Adding a timer completely eliminates any possibility that this can happen. If the program is busy when the timer should fire that event also will not fire but the next cycle will see that there is data in the port and retrieve it correctly.
Another issue is when you are getting large blocks of data but also need to receive small blocks of data. The event fires when the data is coming in but has not yet completed. It is possible that while reading data that there is more data coming in that would cause the event to fire but the event is currently running so it can not fire a second time. Code added at the end of the event to check the inbuffer can minimize this possibility but it is still possible though unlikely that data could arrive after the buffercount is returned as 0 but the routine has not exited yet.
Using a timer set at 200 the worst case senario is that there is a 200 milisecond delay in retrieving the first and/or last byte of data where as using the on comm event it is possible not to get the data at all.
On another note if the comm routines are running in thier own thread the odds of running into such issue are greatly reduced but even in such a case I would still add a timer to make sure I get all the data.
Last edited by DataMiser; February 7th, 2009 at 01:26 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|