none
SerialPort message frame detection RRS feed

  • General discussion

  • Using .NET 4.0 on Windows 8.1 (x64).

    I need to detect message frames in a "semi-real-time fashion", i.e. the only way to detect message frames are by detecting a mandatory minimum silent interval between messages.

    The real need is to detect silent intervals of down to 2 ms, however for most practical purposes an interval of e.g. 50 ms is sufficient.

    I found two ways of achieving this by using Serialport, briefly described as:

    1: By using ReadByte() and handling the port's TimeoutException.
    2: By disabling port timeout (Serialport.InfiniteTimeout) and detecting the silence by a System.Threading.Timer callback.

    For both methods I have to turn off driver's FIFO buffer, if not, timing problems will occur.

    Both methods work just fine (it seems like the Exception method has more accurate timing though, does it use a better timer internally ?), cpu load is pretty much the same and the Exception method makes it slightly easier (only one thread involved).

    The Exception method throws an Exception (of course) which is reported in the output window ("A first chance exception of type 'System.TimeoutException' occurred in System.dll"), a little bit annoying during debugging (can be disabled, but that would disable other exceptions from being reported in the output window as well, or perhaps it is possible to disable only this one programmatically ?).

    Anyone has some opinion which is "best" (or perhaps some other reading mechanism) ?

    I ask because there are numerous of statements out there saying that exceptions should only be used by handling errors due to non-controllable environment, not as a part of a "normal" execution flow, perhaps something important I ignore in my code which hits me back later ?

    (Indeed I am considering this frame detection as a "normal" execution flow.)

    Sunday, December 22, 2013 2:52 PM

All replies

  • Hi EuroEager,

    This link explains what a first chance exception is. http://blogs.msdn.com/b/davidklinems/archive/2005/07/12/438061.aspx.

    If you want to pinpoint where the exceptions are occurring, you can select the Debug->Exceptions menu item, and in the dialog that appears, check the first checkbox for "Common Language Runtime Exceptions". This will make the debugger break as soon as an exception occurs instead of only breaking on unhandled exceptions.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, December 23, 2013 6:00 AM
    Moderator
  • What I really asked about was some opinions regarding use of TimeoutException for normal execution or not.
    Monday, December 30, 2013 8:03 AM