Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: PH_Comm.phcomm receive data trigger Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
patrickm
Senior Member
Senior Member


Joined: February 22 2007
Location: United States
Online Status: Offline
Posts: 188
Posted: January 28 2012 at 18:35 | IP Logged Quote patrickm

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
Back to Top View patrickm's Profile Search for other posts by patrickm
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: February 03 2012 at 09:33 | IP Logged Quote dhoward

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.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
patrickm
Senior Member
Senior Member


Joined: February 22 2007
Location: United States
Online Status: Offline
Posts: 188
Posted: February 03 2012 at 10:47 | IP Logged Quote patrickm

Thanks Dave,
I will use it this way for now.

Patrick
Back to Top View patrickm's Profile Search for other posts by patrickm
 

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