Pause code for 2 seconds...

R

Ryan Evans

I'm sending a string of information to another program
and I need to pause the transmission for two seconds.
How would I do that?

This is what I have...

Chan = DDEInitiate("WinWedge", "Com1") ' initiate DDE
channel with wedge
DDEExecute Chan, "[SEND(" & "@" & ")]" ' send String out
the serial port

I NEED A TWO SECOND PAUSE RIGHT HERE!

DDEExecute Chan, "[SEND(" & strSpout & " %e " &
strBinStamp & " %e GO %e" & ")]"
DDETerminate Chan ' terminate the link

Thanks for any help.
 
R

Ryan J Evans

I tried the code and it pauses it for two seconds,
however it pauses the whole function for two seconds, it
doesn't just pause after the line I input the code at.
Is there an easy fix for that or am I just doing
something wrong?

Thanks
 
B

Bruce M. Thompson

Are you sure that you need to pause, or would inserting a "DoEvents"
effectively allow the prior line of code to complete execution? My
experiences with WinWedge and the examples I have seen seem to indicate that
neither is necessary.
 
B

Bruce M. Thompson

The guy that is programming the indicator I will send the
data to says he wants (in ASCII) "@" followed by a 2
second pause and then "x %e y %e GO %e" where x and y are
variables.

How would I use a "DoEvents"? I'm not real strong in
writing code so have patience with me.

Well, if he feels that he needs a 2 second pause, I suppose that you could
use a form-level variable, a Do loop to wait for the value to be set to a
certain value and the form's "Timer" event to set the variable's value after
the passage of 2000 milliseconds (2 seconds). Of course, you would still
need to insert a DoEvents into the loop to allow any background processing
to take place.

Just for the sake of clarity here, let's go back to an earlier statement you
made in response to my initial suggestion:
I tried the code and it pauses it for two seconds,
however it pauses the whole function for two seconds, it
doesn't just pause after the line I input the code at.

No matter how you do this, you will still be pausing the whole "function"
for two seconds. You can't "send" a 2 second pause. If it's a matter of
waiting for some background processing to take place, then the Do loop
approach should work, but it seems that the device would not be held up by
the computer once it has received its data (and I'm a little rusty on DDE)
unless it needs a command to tell it to continue with the data it has
already received. You may need to terminate the link after sending the first
string, then insert your 2 second pause and re-establish the link to send
the second string. The following function appears at TalTech's site (you
probably have already seen this) and sends a single string to the serial
port:

'************FUNCTION START
Function SendString (StringVar$)
' The Wedge must be running and activated for COM1 for this code to work
chan = DDEInitiate("WinWedge", "Com1") ' initiate DDE channel with wedge
DDEExecute chan, "[SEND(" + StringVar$ + ")]" ' send String out the
serial port
DDETerminate chan ' terminate the link
End Function
'************FUNCTION END

I would simply implement this function (save it to a standard module, not a
module behind a form or report, if it needs to be available from multiple
forms, etc.) once for each string sent to the port (it replaces all of the
DDE code in your routine example) and insert my 2 second pause between the
two (using my first approach). So now you would have:

'**********CODE SNIPPET START
SendString "@"
'Your 2 second pause goes here
Call sSleep(2000)
SendString strSpout & " %e " & strBinStamp & " %e GO %e"
'**********CODE SNIPPET END

Does this help?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top