Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome General
 PowerHome Messageboard : PowerHome General
Subject Topic: send ph_ to socket server via code? Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
ficklma1
Groupie
Groupie


Joined: December 08 2007
Location: United States
Online Status: Offline
Posts: 59
Posted: December 15 2007 at 18:05 | IP Logged Quote ficklma1

Hi PH'ers,

I've just started to use PH and I'm exploring the use of the PH Socket Server and need so help. Is it possible to send a message to the PH Socket Server via some VB code? What would some sample VB code look like? I want to bypass calling the PHSSCmd.exe, because I don't want to shell out of my program, I just want to have a subroutine in VB to send PH formulas to the PH Socket Server.
Back to Top View ficklma1's Profile Search for other posts by ficklma1
 
bhlonewolf
Senior Member
Senior Member


Joined: March 29 2007
Online Status: Offline
Posts: 198
Posted: December 15 2007 at 19:14 | IP Logged Quote bhlonewolf

I thought the source code to that app was available to download, so you could simply modify it to your liking. I posted a .NET DLL you can use here:

http://www.power-home.com/forum/forum_posts.asp?TID=1508&PN= 1

Basically just reference it in your project and it makes the socket calls for you -- regardless, it's all pretty simple!

Back to Top View bhlonewolf's Profile Search for other posts by bhlonewolf
 
ficklma1
Groupie
Groupie


Joined: December 08 2007
Location: United States
Online Status: Offline
Posts: 59
Posted: December 15 2007 at 21:14 | IP Logged Quote ficklma1

Do you have an example of what the code would look like withing VB.NET using your .dll sending a ph_insteon() formula?

Thanks
Back to Top View ficklma1's Profile Search for other posts by ficklma1
 
bhlonewolf
Senior Member
Senior Member


Joined: March 29 2007
Online Status: Offline
Posts: 198
Posted: December 15 2007 at 22:57 | IP Logged Quote bhlonewolf

Not VB.NET, but C# -- shouldn't be a problem to translate:

PowerHomeSocketClient.SocketClient client = new PowerHomeSocketClient.SocketClient();

client.RequestType = PowerHomeSocketClient.SocketRequestType.FORMULA;

client.SendRequest(@"ph_setglobal_a ( ""CUR_TEMP"", 50 )");

The SendRequest method returns a string if you need a response...

Edited by bhlonewolf - December 15 2007 at 22:58
Back to Top View bhlonewolf's Profile Search for other posts by bhlonewolf
 
ficklma1
Groupie
Groupie


Joined: December 08 2007
Location: United States
Online Status: Offline
Posts: 59
Posted: December 17 2007 at 14:42 | IP Logged Quote ficklma1

Is there a way I can test your .dll without coding something? How do you set the .settings file?

I want to make sure it's communicating with my IP, User, Password and Port.

Thanks
Back to Top View ficklma1's Profile Search for other posts by ficklma1
 
bhlonewolf
Senior Member
Senior Member


Joined: March 29 2007
Online Status: Offline
Posts: 198
Posted: December 17 2007 at 16:08 | IP Logged Quote bhlonewolf

ficklma1 wrote:
Is there a way I can test your .dll without coding something? How do you set the .settings file?

I want to make sure it's communicating with my IP, User, Password and Port.

Thanks


Nope, it's a library so needs to get plugged into another app, like a console or winform. It would be real easy to plug it into a console app that would run based on command line parameters, but then, that's what dave's example is for :) I didn't look at this code but it likely works the same way.
Back to Top View bhlonewolf's Profile Search for other posts by bhlonewolf
 
ficklma1
Groupie
Groupie


Joined: December 08 2007
Location: United States
Online Status: Offline
Posts: 59
Posted: December 17 2007 at 16:29 | IP Logged Quote ficklma1

bhlonewolf,

Thanks for all of your help. I think I have some code that will work. I'm just not sure about the app or PowerHomeSocketClient xml for the settings, i.e. IP, port, etc. Does this file need to be the same name as your .dll and also can I just edit this file and change my IP and port? Will is pick up the changes?
Back to Top View ficklma1's Profile Search for other posts by ficklma1
 
ficklma1
Groupie
Groupie


Joined: December 08 2007
Location: United States
Online Status: Offline
Posts: 59
Posted: December 17 2007 at 16:34 | IP Logged Quote ficklma1

In your example:
client.SendRequest(@"ph_setglobal_a ( ""CUR_TEMP"", 50 )");

What is the @ sign used for? Is it for the double quotes?

Sorry for all of the questions, I'm a newbie to PH and some of this coding in C#.
Back to Top View ficklma1's Profile Search for other posts by ficklma1
 
bhlonewolf
Senior Member
Senior Member


Joined: March 29 2007
Online Status: Offline
Posts: 198
Posted: December 17 2007 at 17:29 | IP Logged Quote bhlonewolf

Oh hey no problem, I'm happy to help any way I can. If you need help getting a console app together let me know.

The "@" sign in C# is actually unneeded in this context (I copied it from my actual application where it is needed) and all it does is instruct the compiler to treat everything between the quotes as literal. In this case, you still need to escape quotes by doubling them up.

Without it, \t would be a tab, \n would be a newline, \" a quote, etc. I very often do the @ when I know I'm assembling a literal string, even if it's not technically needed...
Back to Top View bhlonewolf's Profile Search for other posts by bhlonewolf
 
bhlonewolf
Senior Member
Senior Member


Joined: March 29 2007
Online Status: Offline
Posts: 198
Posted: December 17 2007 at 17:31 | IP Logged Quote bhlonewolf

Oh -- and yes, just edit the xml file manually. If you wanted to programmatically change the port, I could bake that functionality in, but it's not there currently. I kind of figured it would likely be a configure once type of thing, easier than assigning it in code each time you make a socket call...
Back to Top View bhlonewolf's Profile Search for other posts by bhlonewolf
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: December 17 2007 at 21:45 | IP Logged Quote dhoward

ficklma1,

The Socket Server protocol is very easy to integrate into your custom programming. If you go to the download page and get the PHSSCmd_Setup.exe and install it, you'll get a good idea of how to do it. Just be sure to do a custom install and install the sourcecode as it seems that most people just do the typical install and that doesnt include the source. This source is in VB6.

HTH,

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