Click here to Skip to main content
15,883,870 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
VB
strRead1 +=seriPort1.ReadLine()


Right before this line I use this to check serial port status
VB
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
Updated 16-Jan-13 11:05am
v2
Comments
Sergey Alexandrovich Kryukov 16-Jan-13 17:29pm    
What do you think is "real time"? Do you mean "run time"... :-)
—SA
SandiegoSSD 16-Jan-13 22:03pm    
yes...run time. part of my brain slipped again
Sergey Alexandrovich Kryukov 16-Jan-13 22:45pm    
You should do it all in one separate thread. Do you?
—SA
SandiegoSSD 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 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

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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900