473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

delay between events...

hello all...
this is my first post... :)

i need to send specific characters on rs232 at specified intervals...


i call the 1st sub and it sends something on rs232 using trysend sub and for the delay i've used a variable timercnt1 ... u set timercnt1 to 50 and enable the timer.... as the timer ticks it counts down and at 0 it shuts off...

Expand|Select|Wrap|Line Numbers
  1.     Private Sub stdlengthcmdsend()
  2.         ' motor1 start at full speed
  3.         trysend("9" & "1")
  4.         timercnt1 = 50
  5.         Timer1.Enabled = True
  6.         While timercnt1 <> 0
  7.             ' delay
  8.         End While
  9.         'WriteMessage("while end" & Chr(13), True)
  10.  
  11.         'motor stop 
  12.         ' in this time it wud've covered the dstance...
  13.         trysend("q")
  14.         trysend("3")
  15.  
  16.     End Sub
  17.  
  18.     Private Sub timer1_tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  19.         ' For 5 seconds 50 ticks
  20.         If timercnt1 = 0 Then
  21.             Timer1.Enabled = False
  22.             'oCP.Write(Encoding.ASCII.GetBytes(textinbox & Chr(13)))
  23.             'WriteMessage("time up" & Chr(13), True)
  24.         End If
  25.         timercnt1 = timercnt1 - 1
  26.     End Sub
and now..... the problem with this is....
it simply hangs... nothign happens.. and i believe nothing is sent on rs232 second time when it has to... i guess its stuck in the while loop

i've checked out the sleep option....
but the problem with that is... my form has grafix that have to be drawn.. so if u go in sleep once they're lost...

please suggest alternatives...

thanks :)
Apr 1 '08 #1
5 1734
Killer42
8,435 Expert 8TB
My advice is to put a DoEvents inside that While loop.

Note though, that this advice is based on my knowledge of VB6. Dunno how closely the versions match in this regard.
Apr 1 '08 #2
Killer42
8,435 Expert 8TB
Do you really need your code to stop and wait for the 5 seconds, or do you just need the output to be sent at that rate?

What I'm thinking is, why not just queue any data and continue on your way, and have the timer take things off the queue each 5 seconds and send them?
Apr 1 '08 #3
!NoItAll
297 100+
Mr Killer is right - set the timer interval to 5000 and put your code inside the timer event.
Apr 2 '08 #4
Do you really need your code to stop and wait for the 5 seconds, or do you just need the output to be sent at that rate?

What I'm thinking is, why not just queue any data and continue on your way, and have the timer take things off the queue each 5 seconds and send them?
i didnt quite understand what u meant by queuing here...
if i write the 2 sets of instructions in 2 different timer tick events and when i enable them wont they clash? .... coz here m controlling a robot and have to send the instructions only one after another...and the interval is also not constant for each set

newaz i've got an idea using multiple timers for each set procedure and by calling the next one from the previous timer itself.. .. if that works i'll share it with u all...

thanks
-BlueStag
Apr 2 '08 #5
Killer42
8,435 Expert 8TB
What I was thinking was something like this...

You have an array to hold the instructions to be sent. Each entry holds whatever information you need to send for that instruction, plus an indicator of the minimum gap required before (or is it after?) that instruction.

You create a routine to add an instruction to the "queue" (array). All it does is take the instruction you pass it, and add it onto the end of the queue.

You have a single timer which ticks once per second, or ten times a second, or whatever turns out to be appropriate. Each time it ticks, it checks the next item in the queue (if any). It checks whether at least the minimum required time has elapsed since the last instruction was sent. If not, it does nothing. Otherwise, it sends the next instruction, and removes it from the queue. And sets an indicator saying what time it was sent.

Does that make more sense?

So your code could be saying things along the lines of "send instruction ABC and wait at least 5 seconds before the next one", by calling the "add to queue" routine. Or depending on how the robot works, it might be more like "send instruction ABC after a pause of at least 5 seconds since the last one".

The basic idea is to keep the coding fairly simple. You have a queue with two simple actions - the "add to queue" routine to put things on the queue, and the timer tick to take them off.
Apr 3 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Graham Allwood | last post by:
Hi, I have an assemly that is delay signed during the dev work and then it is resigned later when we perform a release build. In the same solution I have a setup project that uses the PRIMARY...
1
by: Ricky | last post by:
Hi, I am trying to create this rollover bar menu with js and it works fine until it has to disappear I wanted it to disappear after the mouseout function and after a little delay but instead it...
20
by: Doug Thews | last post by:
I ran into an interesting re-pain delay after calling the Abort() method on a thread, but it only happens the very first time I call it. Every time afterward, there is no delay. I've got a...
8
by: Jason Shohet | last post by:
Lets say I want a button to execute 10 seconds after I press it, not immediately. Any ideas how to cause that, in a code-behind. IMO its only server side code, I don't think javascript needs to...
18
by: Max | last post by:
This is a follow-up on my previous thread concerning having the program wait for a certain date and time and then executing some code when it gets there. My question is; can I use the Sleep...
6
by: Woody Splawn | last post by:
Is there a way in vb.net to delay the firing of certain code till after everything else has run? That is, I have an event with some code in it that needs to run AFTER everything else has run...
1
by: David Veeneman | last post by:
I want to introduce a one-second delay into the MouseHover event of a label. In other words, I want the user to have to hover over a label for one second before the label's MouseHover event...
9
by: Tushar | last post by:
Followup-To: microsoft.public.dotnet.general Does anyone know when is this event raised, is it: 1) When the file is created but may not have been closed 2) When the file is created AND it has...
2
by: taaz | last post by:
I'm developing the Delay Audiometry feedback. My Step are... Recording -> Playing... these are on different events. I've used the mcisendstring()for manipulation of audio & made the functions ...
7
by: agsupriya86 | last post by:
Hi, I need to add some delay function to my code where on clicking the exit button some text needs to be displayed on the text area.. Right now the text is not not appearing coz there s no dealy...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.