patrickm Senior Member
Joined: February 22 2007 Location: United States
Online Status: Offline Posts: 188
|
Posted: January 28 2012 at 18:35 | IP Logged
|
|
|
How is receiving data usually done with the PH_Comm.phcomm plugin?
If I setup a trigger on generic plugin, command 1, option 1 there are multiple triggers from the received data with chunks of the received data string in TEMP5.
Is there a way to configure the plugin to set the received bytes trigger threshold or trigger on a received delimiter byte?
I would like to trigger after receiving the whole packet/string.
Patrick
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: February 03 2012 at 09:33 | IP Logged
|
|
|
Patrick,
Sorry to take so long getting back to you.
No current way to configure the plugin to only fire the trigger when a specific delimiter is reached but I've added it to the enhancements list.
Inthe meantime, the way I like to use the COMM plugin is to have a macro fired whenever data is received. In that macro, I search for any delimiters on the incoming data. If I dont find any, I then add the data to a GLOBAL global variable. These variables arent used that often but are perfect for this type of work. These are the variables that are characterized by the form of [GLOBAL1] thru [GLOBAL100]. They're great because they're global throughout PH, can contain virtually unlimited data, and arent stored in the database.
If my delimiter was a carriage return/line feed, my macro would look something like:
10 Set System [LOCAL1] pos(ph_getvar_s(2,5),"~r~n")
20 Goto Label if(ph_getvar_n(1,1) > 0,"FOUND","")
30 Set System [GLOBAL1] ph_getvar_s(3,1) + ph_getvar_s(2,5)
40 End Macro
50 Label FOUND
60 Set System [LOCAL2] ph_getvar_s(3,1) + left(ph_getvar_s(2,5),ph_getvar_n(1,1) + 1)
70 Set System [GLOBAL1] mid(ph_getvar_s(2,5),ph_getvar_n(1,1) + 2)
80 ...
Line 10 searches the incoming received data for the delimiter and sets [LOCAL1] to the position where its found. If not found, [LOCAL1] will be 0.
Line 20 then jumps based on [LOCAL1]. If the delimiter is found, we goto label "FOUND". If [LOCAL1] is 0, we goto label "" which is not valid so we just fall to the next line.
Line 30 is run when we don't find the delimiter. We just append the received data to the [GLOBAL1] variable and wait for the next chunk of data to arrive.
Line 50 is where we come if we find the delimiter.
Line 60. We found the delimiter so were going to build a complete string of our data in [LOCAL2] which consists of everything in [GLOBAL1] plus the data in [TEMP5] up to and including our delimiter. If you don't want the delimiter, then you would want to change the last part to ph_getvar_n(1,1) - 1).
Line 70. We've got our complete data string in [LOCAL2] so now we set [GLOBAL1] to what remains of the data after the delimiter essentially resetting ourselves for the next chunk of data to search for.
Line 80 and beyond is where we would now process our complete data string in [LOCAL2].
Hope this helps,
Dave.
|