Author |
|
patrickm Senior Member
Joined: February 22 2007 Location: United States
Online Status: Offline Posts: 188
|
Posted: November 30 2010 at 15:10 | IP Logged
|
|
|
I am using the ph_picmd command to communicate with various hardware and software in my system using triggers for the return data from queries and commands. This seems a bit disjointed when trying to interact with a device.
Right now I have several seperate macros dealing with the same device. Is there a way of doing the following that will actually set VARIABLE with the response from DEVICE?
ph_setglobal_s("VARIABLE",ph_picmd(5,"DEVICE",1,0,0,"paramet er ?~r~n",""))
VARIABLE is set to zero as ph_picmd just returns a zero.
I have also tried to do it this way with similar results:
ph_setglobal_s("VARIABLE", ph_sendsocketdata1("192.168.1.1",23,3,"parameter ?\013\010"))
VARIABLE gets set to an empty or null state.
I would like to be able to query and control the device from within the same macro without having resort to a wait after the ph_picmd and the returned data triggering the same macro with conditional jumps and all that.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: November 30 2010 at 19:25 | IP Logged
|
|
|
Have you tried just setting a global with the value in a macro line?
Set Gobal YourGlobal ph_picmd(5,"DEVICE",1,0,0,"paramet er ?~r~n","")
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: November 30 2010 at 20:15 | IP Logged
|
|
|
Patrick,
The short answer is no. ph_sendsocketdata1 wont work because it only returns when the connection is closed (typical only on http type of connections) or on sendcomplete (data would not yet be received). The good news is that the upcoming beta has a new flag option that will return on data receive.
The ph_picmd function I assume you're using the Raw socket plugin. The Raw socket plugin is designed to not hold up processing (PowerHome would essentially be hung while waiting for data to be returned) and instead fires a trigger when data is received. I understand the desire to have everything encapsulated within a single macro and the other good news is that you can even with this methodology.
The way I do this is similar to the following:
10 Goto Label ph_getvar_s(1,1)
20 ...your normal processing
30 Formula Immediate ph_picmd(5,"DEVICE",1,0,0,"parameter?~r~n","")
40 End Macro
50 Label RECEIVEDATA
60 ph_setglobal_s("VARIABLE",ph_getvar_s(1,2))
70 ...the rest of your processing
80 ...etc
In the trigger that is fired by the Raw socket plugin, make the action a formula with something like the following:
ph_macroparm("YOUR MACRO ID","RECEIVEDATA",ph_getvar_s(2,5),0,0,0)
The way this works is that if the macro is called normally or with a blank value in LOCAL1 or any value in LOCAL1 that does not match "RECEIVEDATA", the macro runs as normal and starts your normal processing at line 20. When you get to the ph_picmd function, the next line ends the macro execution and other processing can continue. When the data is received, you call the same original macro but with parms and set the LOCAL1 variable to "RECEIVEDATA" and LOCAL2 to the received data (which I believe is in TEMP5 if I remember correctly). The same macro will launch, this time it will jump to the RECEIVEDATA label and set the Global variable to the received data that you passed in LOCAL2 and the macro continues on as normal. This concept can be extended so that a single macro can contain multiple sections identified by various labels with an Exit Macro command ending that particular section. Everything in the same macro with the same level of readability but with the benefit of not hanging the program waiting on socket data.
Hope this helps,
Dave.
|
Back to Top |
|
|
patrickm Senior Member
Joined: February 22 2007 Location: United States
Online Status: Offline Posts: 188
|
Posted: December 01 2010 at 03:40 | IP Logged
|
|
|
Simply Elegant!
It works great. I am using a variable for LOCAL1 and put it all into one macro.
Thank you Dave
|
Back to Top |
|
|
|
|