Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Wait and ph_macropramret issues Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: October 30 2008 at 03:25 | IP Logged Quote onhiatus

So I've got a macro that sends a command via a socket, then waits for the response. This is handled by having the data coming in on the socket trigger another macro which then signals the original macro to continue.

Roughly: The macro does something like
1. Send data
2. wait 1 second
3. check to see if data has come back, if not goto 2
4. Finish macro (copy data into [ Local1 ])

The second macro signals the first macro by writing the data to a file.

This works great, except now I want to trigger it from the web using ph_macroparmret(). It's drove me crazy, but what happens is that ph_macroparmret() returns when the called macro terminates - the problem is that waiting terminates the macro and schedules it to restart later so ph_macroparmret() returns as soon as the macro start to wait for the signal.

I can't use delay instead of wait, because the ties up powerhome so the socket trigger never gets services.

Any thoughts on how I can synchronize the two macros over the web?

The only solution I've come up with is way to messy - Have the html page call the first macro, then poll (refresh) the data from the second macro until it is complete. Yuck.

Thanks for your ideas...

Tony (Not No)
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: October 30 2008 at 13:17 | IP Logged Quote dhoward

Tony,

Ive been trying to think of a good way to do this and really don't see a way (without at least suspending the execution queue...PH won't be hung though like with a Delay). It's primarily because the webserver is not running in it's own separate thread and requests are processed through the execution queue like other commands.

How are you sending and receiving data to the socket? ph_sendsocketdata? There are some new functions that may help out. ph_sendsocketdata1 adds a "flags" parameter that gives you some control over when the function returns. There is also a raw Socket plugin now (this does run in it's own thread) and commands to plugins include a timeout parameter. You may be able to rewrite to use the socket plugin and instead of using the macro with a "Wait", use the ph_picmd function with a timeout to retrieve the data. You should be able to make this function wait until the data is returned and then have the webpage rendered. The only problem is that while PH won't be "hung", it won't process any execution queue items until the ph_picmd function returns or times out.

Not sure if this helps or not.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
onhiatus
Senior Member
Senior Member
Avatar

Joined: May 12 2004
Location: United States
Online Status: Offline
Posts: 279
Posted: October 30 2008 at 17:39 | IP Logged Quote onhiatus

I'm using the plug in to try to reduce the load on the main ph thread.

The socket plugin timeout seems only to affect when the data is sent - not when the reply comes back (this can be up to a minute later in my application)

What command to retrieve data? Using the raw socket plug in the only way I see to retrieve data is via a trigger. Am I missing something?

Thanks, Tony
Back to Top View onhiatus's Profile Search for other posts by onhiatus Visit onhiatus's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: November 04 2008 at 11:07 | IP Logged Quote dhoward

Tony,

You've got it right then. I wasnt aware you were using the Socket plugin. In that case, you may want to try the ph_sendsocketdata1 function but if it takes up to a minute before the socket returns the data, that is an awful long time to wait.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum