Click here to Skip to main content
12,813,626 members (31,623 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB 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
Updated 16-Jan-13 12:05pm
Sergey Alexandrovich Kryukov 16-Jan-13 17:29pm
What do you think is "real time"? Do you mean "run time"... :-)
SandiegoSSD 16-Jan-13 22:03pm 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?
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.

1 solution

Rate this: bad
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.
Sergey Alexandrovich Kryukov 16-Jan-13 17:30pm
Basically correct but wording is pretty unclear...

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2017
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