Author |
|
ficklma1 Groupie
Joined: December 08 2007 Location: United States
Online Status: Offline Posts: 59
|
Posted: December 15 2007 at 18:05 | IP Logged
|
|
|
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 |
|
|
bhlonewolf Senior Member
Joined: March 29 2007
Online Status: Offline Posts: 198
|
Posted: December 15 2007 at 19:14 | IP Logged
|
|
|
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 |
|
|
ficklma1 Groupie
Joined: December 08 2007 Location: United States
Online Status: Offline Posts: 59
|
Posted: December 15 2007 at 21:14 | IP Logged
|
|
|
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 |
|
|
bhlonewolf Senior Member
Joined: March 29 2007
Online Status: Offline Posts: 198
|
Posted: December 15 2007 at 22:57 | IP Logged
|
|
|
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 |
|
|
ficklma1 Groupie
Joined: December 08 2007 Location: United States
Online Status: Offline Posts: 59
|
Posted: December 17 2007 at 14:42 | IP Logged
|
|
|
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 |
|
|
bhlonewolf Senior Member
Joined: March 29 2007
Online Status: Offline Posts: 198
|
Posted: December 17 2007 at 16:08 | IP Logged
|
|
|
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 |
|
|
ficklma1 Groupie
Joined: December 08 2007 Location: United States
Online Status: Offline Posts: 59
|
Posted: December 17 2007 at 16:29 | IP Logged
|
|
|
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 |
|
|
ficklma1 Groupie
Joined: December 08 2007 Location: United States
Online Status: Offline Posts: 59
|
Posted: December 17 2007 at 16:34 | IP Logged
|
|
|
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 |
|
|
bhlonewolf Senior Member
Joined: March 29 2007
Online Status: Offline Posts: 198
|
Posted: December 17 2007 at 17:29 | IP Logged
|
|
|
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 |
|
|
bhlonewolf Senior Member
Joined: March 29 2007
Online Status: Offline Posts: 198
|
Posted: December 17 2007 at 17:31 | IP Logged
|
|
|
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 |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: December 17 2007 at 21:45 | IP Logged
|
|
|
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 |
|
|