Author Topic: Having issues with VB and updating form from serial device...  (Read 15408 times)

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Hi All,

I'm really more of a C# programmer than VB (I got lumbered with it) and am trying to find a method of using Invoke or BeginInvoke to access data coming back from the serial port.  I am now trying a method suggested by a friend (who is a VB guru!) to use SyncLock for reading data and not causing a thread race condition. This would seem to hold the data in a waiting loop while reading the data to a string until a condition is met (carriage return & or line feed, set period of times, etc.).  Can I get an opinion on this as I do not want to use Thread.Sleep() due to the likelihood of this either breaking or locking the machine.
Glenn
   

EagleWolf

  • Member
  • ***
  • Posts: 8
Re: Having issues with VB and updating form from serial device...
« Reply #1 on: March 06, 2014, 08:11:02 pm »
Not to seem snide, but my personal preference is to NOT (I repeat NOT) use .NET language
(Only because .NET to me is another layer upon Layer (possibly on top of another layer) of whizz-bang types of things
that bear no fruit when really trying to understand something?)

This said (and I did not understand most the "Buzz-Words" that you used) the serial port should really in my opinion only be read by a thread when no other function is expecting an answer. (Aka, only turn it on if not calling one of your functions)

Also waiting on a certain reply is only valid if the response you expect is guaranteed by the device you are talking to. (but what if the device issues an error code while you only got part of the response you expected?)

It all depends on what you are doing? vs what you expect? and is it possible to break your code? (regardless of the language)

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Having issues with VB and updating form from serial device...
« Reply #2 on: March 23, 2014, 12:26:11 pm »
Why not read the data as it arrives and take action when you get the needed terminator?