I'm writting a VB.Net app that interacts with a CAN bus in order to control some motors that are on it. With the CAN bus I can turn on and off each motor, in normal and reverse mode, and read their current consumption. I have implemented two checkbox for each motor, to make it run normal or reverse, and a textbox where I show the actual current consumption, this is actually working. Now what I want to do is to automatice some tests, for example:
- Run each motor for two seconds in each direction and record it's consumption to see if the values are correct.
To do this I've created a TestMotor class where I send a ref of the two buttons that turns on in normal or reverse each motor. Each test class represents the test of each motor, so if I have 4 motors, I'll create 4 TestMotor objects giving them the two checkboxes that power on that motor.
Finally that TestMotor class have a executeTest which mainly does runs the motor during two seconds in each direction by checking and unchecking the checkboxes. This two secconds delay it's being done with a delay between them.
My problem is that if I run those tests directly on the main thread the Thread.sleep blocks UI thread, but if I create a thread and then execute those tests there those are executing all at the same time.
How would you solve this? I've been trying with async tasks, timers, and now I was going to try some semaphores or something, but a little help about the best way to resolve this would be great.
Some code:
In main class
for each test in test
test.executeTest()
end for
TestMotor class
public sub executeTest()
ckNormal.checked = true
Thread.sleep(2000)
ckNormal.checked = false
ckReverse.checked = true
Thread.sleep(2000)
ckReverse.checked = false
end sub
Thanks!