Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB10.0 VB.NET
Hi guys I have a GUI that constantly talks to a motor encoder thru serial port.
There are cases where I have to manually kill the motor from running, but this also cause the serial port to stop responding.
 
And when this happens my GUI would hang on this line and the whole form would freeze.
strRead1 +=seriPort1.ReadLine()
 
Right before this line I use this to check serial port status
 If seriportMotor.IsOpen = True Then
but obviously it doesn't do its job.
 
I'm wondering whether there's some feature of serialport class or something that can check the status before it tries to read from serial port and cause the form to hang??
Thank you.
Posted 16-Jan-13 12:01pm
Edited 16-Jan-13 12:05pm
v2
Comments
Sergey Alexandrovich Kryukov at 16-Jan-13 17:29pm
   
What do you think is "real time"? Do you mean "run time"... :-)
—SA
SandiegoSSD at 16-Jan-13 22:03pm
   
yes...run time. part of my brain slipped again
Sergey Alexandrovich Kryukov at 16-Jan-13 22:45pm
   
You should do it all in one separate thread. Do you?
—SA
SandiegoSSD at 17-Jan-13 12:30pm
   
It's all in one single thread. After sending the "Go" command to the motor and letting it keep running until told otherwise, a timer starts ticking and every tick event checks whether the motor has turned desired number of revolutions(this is done by sending a query command to the motor encoder unit). So when the motor is manually shut down, the query command ( seriPort1.Write("W" & vbCr)
strRead1 += seriPort1.ReadLine() ) can never finish and freezes the form
Sergey Alexandrovich Kryukov at 17-Jan-13 12:46pm
   
What single thread? The same as UI? It won't work for you, should be another thread for the serial communication.
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Seems like you are reading the port on the same thread as the UI. Try looking into off loading reading the port to a different thread and then just have your UI have a "Loading" text or something until you finish reading the port.
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 16-Jan-13 17:30pm
   
Basically correct but wording is pretty unclear...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,130
1 DamithSL 5,089
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,647
4 Kornfeld Eliyahu Peter 4,409


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100