CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
I'm building a sort of pet project over spring break and I'm running out of time... I don't have a whole lot of programming experience, but I wrote the rest of this program in like two hours and been stuck on this part for two days. I've never done anything with time lapses before and I am apparently not as smart as the time variables in VS.NET, so any help would be greatly appreciated.

I'm trying to output a binary word to hardware for a specified amount of time. The idea is that I need to send a pulse to a motor for each step I want the motor to move, so the pulse needs to have a finite duration and a finite time between pulses for multiple steps.

Thanks!



 
Aug 3, 2004
35
0
0
I don't know how the TimeSpan class works, but just glancing at that code I notice your for loops are a bit screwy. You want to use "==" for comparison not "=". You are basically never entering the loop because you first set the StepDuration to 100, then set it to 0 (which is true) so it exits the loop.
 

KB

Diamond Member
Nov 8, 1999
5,402
386
126
I don't think your code will do what you want it to. The TimeSpan structure is a number representing time ticks. Straight from the SDK doc : "A tick is the smallest unit of time that can be specified, and is equal to 100 nanoseconds". TimeSpans aren't used for time lapses, they are used for determining the time between dates.
For loops aren't guarenteed to take one tick per loop. Instead they run as quickly as the processor will let them. This means your for loop may take 25 nanoseconds to complete or if the processor is busy it may take 1000 nanoseconds.
What you are trying to do is fairly complicated and nothing I have done before. My guess (you would have to try this to see if it does work) would be to create a second thread which sends the pulses, then call Thread.Sleep(TimeSpan) on your main thread. When the main thread completes its sleep for the duration of the TimeSpan passed to it, the main thread then has to Abort the pulse thread. Good luck!
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
Originally posted by: asleepwalking00
I don't know how the TimeSpan class works, but just glancing at that code I notice your for loops are a bit screwy. You want to use "==" for comparison not "=". You are basically never entering the loop because you first set the StepDuration to 100, then set it to 0 (which is true) so it exits the loop.

Uh... what? Last I checked, a for loop's second clause is the test to KEEP GOING. This would be an infinite loop perhaps?

It should be StepDuration > 0 (or >= if he wants to do it when it is 0).

I think you are going to have to deal with timer classes for this one, if you want to do it in any reasonably correct way.
 

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
OK, I implemented two different timers - one that contains the interval for the pulse, the other the time interval of the rest period between pulses. I screwed something up elsewhere in the code so I can't test it until I go through and change it. Hopefully this will work.

 
Aug 3, 2004
35
0
0
Originally posted by: torpid
Originally posted by: asleepwalking00
I don't know how the TimeSpan class works, but just glancing at that code I notice your for loops are a bit screwy. You want to use "==" for comparison not "=". You are basically never entering the loop because you first set the StepDuration to 100, then set it to 0 (which is true) so it exits the loop.

Uh... what? Last I checked, a for loop's second clause is the test to KEEP GOING. This would be an infinite loop perhaps?

Yeah, you're correct. Still not behaving properly though.
 

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
I don't know if anyone is interested, but I got it to work to my satisfaction anyway. The Thread.Sleep() option works pretty well for my particular application, since I'm only looking for times of 1-2 milliseconds and the timing is much more important than anything else. Thanks for all your help - I'm sure I'll have some more dumb questions before too much longer.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |