Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: PH Socket plugin Problems Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
PCarp
Newbie
Newbie
Avatar

Joined: June 21 2011
Location: United States
Online Status: Offline
Posts: 16
Posted: February 27 2014 at 14:44 | IP Logged Quote PCarp

I am using the PH Socket plugin to get information from a device that has information about the electrical usage in my home.

Socket plugin setup info: PH_Socket.phsocket 10.0.1.60:8002
I am reading the information with: ph_getvar_s(2,5)

The problem that I have is when the trigger fires it fires twice and runs two incidences of the macro that reads the ascii information . If I disable the trigger in the macro and only one incidence of the macro runs then the information is not complete. This causes a problem with the formula thatI am using. If I don't disable the trigger in the macro it will fire twice and will run the macro each time. The second time the macro is run the information is complete.

The file is over 800 characters long and the info that I need is toward the back of the file. For a temporary solution I use the ph_killmacrowait ("GEM") in the macro.

Thanks Paul
Back to Top View PCarp's Profile Search for other posts by PCarp
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: March 03 2014 at 10:36 | IP Logged Quote dhoward

Paul,

I took a look at the source code and then best I can come up with is that since the read info is so long, its firing the socket twice to get the message in a couple of chunks. However, I would expect the first time the macro is run, the [TEMP5] variable would contain the first chunk and the second time the macro is run, the [TEMP5] variable contains the second chunk (and contains the data of interest to you). Based upon your description though, it sounds as if the first time the macro runs, you get the first chunk and the second time the macro runs you get the complete message including the first chunk.

In any event, assuming the complete data is roughly the same length with each call, I would think the best way to handle this is to check the length of [TEMP5] in the Boolean formula of the trigger.

Say the first time the macro runs, you get 600 bytes of data. The second time the macro runs, you get 850 bytes of data. You could place this formula in the Boolean field:

len(ph_getvar_s(2,5)) > 800

and the trigger will only execute the macro if the length of the data is over 800 bytes. You could also do variations of this formula by searching for a particular unique string portion that would only occur in the complete message.

I think this would give you cleaner results than killing the macro.

Hope this helps and let me know how it goes.

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

Joined: June 21 2011
Location: United States
Online Status: Offline
Posts: 16
Posted: March 03 2014 at 15:52 | IP Logged Quote PCarp

That did help. I still never get the entire file but the tail end of the file is always there.

The information that I need is towards the end of the file so I am good to go.

Thanks
Back to Top View PCarp's Profile Search for other posts by PCarp
 

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