Author |
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: January 21 2005 at 20:29 | IP Logged
|
|
|
Peter,
Well, Ive downloaded the code and taken my first look at it. I probably should have done that first before I said I could interface with no problem .
It does include a DLL, but no documentation on the functions. There is included Pascal source code, but Im not a Pascal expert and at first glance, wasnt able to determine what would be necessary to utilize the DLL from VB.
However, ALL IS NOT LOST! I think Ive come up with a fairly simple way to interface this with PowerHome.
First, download the GamePortTempSources.zip file and unzip (using folder names) into the location of your choice. I saw that there was another file to download (without source I believe), but did not look at this file so it may have all that you need.
After you've downloaded and unzipped the GamePortTempSources.zip file, you'll now have a new "GamePortTemp" directory. Under this directory will be a directory named "DLL". Go to this directory and edit the "GameTemp.ini" file. Under [HTTPServer] section set "Enabled" to 1 and "Port" to a different port than you are using for the PowerHome webserver (if you are using the PowerHome webserver). In my examples below, I set this value to 81. Save and exit the INI file. In this directory, were going to create and save 4 HTML files. I named them "sensor0.htm" thru "sensor3.htm". In each of these files, save the following text:
<html>
<body>
<#TEMPSENSOR channel=0 cycles=500>
</body>
</html>
In the third line, change the channel to the appropriate number.
Now go back to the "GamePortTemp" directory and launch the "GamePortTemp.exe" file. This should be the same monitoring program that you posted a screenshot from. This program uses the gametemp.dll file and includes an HTTP server. We'll now send requests to this server from PowerHome to read the temperatures.
The simple request to get the files from PowerHome would be:
ph_getwburl("http://127.0.0.1:81/sensor0.htm",10)
You can see that were using port 81 and requesting the temperature for sensor 0. This function however returns the raw HTML from the gameport webserver. To get just the temperature, we'll need to strip it out. You can copy and paste the formula below to retrieve just the temperature value:
double(ph_rtne(ph_setvar_s(1,1,ph_getwburl("http://127.0.0.1:81/sensor0.htm",10)) + ph_setvar_a(1,2,pos(ph_getvar_s(1,1),"<BODY>")) + ph_setvar_a(1,3,pos(ph_getvar_s(1,1),"</BODY>"))) + mid(ph_getvar_s(1,1),ph_getvar_n(1,2) + 6,ph_getvar_n(1,3) - ph_getvar_n(1,2) - 7))
You'll need to adjust the ph_getwburl function for the appropriate sensor you're wanting to read.
Let me know how this goes and if you have any problems.
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: January 22 2005 at 02:54 | IP Logged
|
|
|
Well I have been trying to program a little in Turbo-Pascalfor Windows and ZLPORTIO.SYS is the file that makes the actual access to the port...... The file MainFormUnit.pas is the source of the gameport(temp).exe
Each procedure which is declared is a function of the dll Maybe as far as here I am giving you no new data ( )
procedure sensor0MenuClick(Sender: TObject);
procedure sensor1MenuClick(Sender: TObject);
procedure sensor2MenuClick(Sender: TObject);
procedure sensor3MenuClick(Sender: TObject);
these procedurea are declared in order to read the tempature from the Systray. An Object is created and the values below are filled in...
Sensor0Value: TMenuItem;
Sensor1Value: TMenuItem;
Sensor2Value: TMenuItem;
Sensor3Value: TMenuItem;
function GetTempString(channel:integer;ForceFirst:boolean; var Value:double; var TempOK:boolean):string;
This statement is the actual string that gets the tempature values....
(man what am I doing... I am telling a programmer how to read sourcecode...... )
Perhaps this helps a little, if not: Please delete it or better yet: tell me to push off
Peter
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: January 22 2005 at 03:37 | IP Logged
|
|
|
For example:
if you type
rundll32 gametemp.dll localgetgametemperature
then the dll would first check if there's a gameport att. to the system....if not a msgbox is created to say
"sorry, your system is without gameport"
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: January 22 2005 at 07:16 | IP Logged
|
|
|
The code works in the formula evaluator, but if I make a psp with it, it results to a ! Is there a possibility to get only 2 digits behind the . ?
If I wanted to get the values into the control center would that be possble?
Peter
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: January 22 2005 at 08:00 | IP Logged
|
|
|
I have made a psp-page and been able to get the temp.values on screen, however with 13 digits behind the dot....Can this be shortened so that the dot is actually visible and only 2 digits are shown on screen? Would it be possible to get thhis done with ABS()?
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: January 22 2005 at 09:37 | IP Logged
|
|
|
To shorten the number of digits after the decimal, use the string() function...
string( variable, "format")
where "format" is something like "###.##".
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: January 22 2005 at 11:55 | IP Logged
|
|
|
And if I should implement this in the formula given by Dave:
double(ph_rtne(ph_setvar_s(1,1,ph_getwburl("http://127.0.0.1:81/sensor0.htm",10)) + ph_setvar_a(1,2,pos(ph_getvar_s(1,1),"<BODY>")) + ph_setvar_a(1,3,pos(ph_getvar_s(1,1),"</BODY>"))) + mid(ph_getvar_s(1,1),ph_getvar_n(1,2) + 6,ph_getvar_n(1,3) - ph_getvar_n(1,2) - 7))
Should I put the statement string( ....
before the last line: ph_getvar_n(1,3) - ph_getvar_n(1,2) - 7))
so the line should be:
String(ph_getvar_n(1,3) - ph_getvar_n(1,2) - 7)),###.##)
Or am I speaking nonsense now?
or should I implement the string(... right before the Mid Statement?
Like so:
string(mid(ph_getvar_s(1,1),ph_getvar_n(1,2) + 6,ph_getvar_n(1,3) - ph_getvar_n(1,2) - 7)),###.##)
Peter
p.s. Like I told earlier: I have no kwowledge of PSP-programming but I am learning slowly......Sorry
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: January 22 2005 at 22:25 | IP Logged
|
|
|
Wow. That's some tight code! My stab at it would be this...
string( double( ph_rtne( ph_setvar_s( 1, 1, ph_getwburl( "http://127.0.0.1:81/sensor0.htm", 10)) + ph_setvar_a( 1, 2, pos( ph_getvar_s(1, 1), "<BODY>")) + ph_setvar_a( 1, 3, pos( ph_getvar_s( 1, 1),"</BODY>"))) + mid( ph_getvar_s( 1, 1), ph_getvar_n( 1, 2) + 6, ph_getvar_n( 1, 3) - ph_getvar_n( 1, 2) - 7)), "###.##")
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: January 23 2005 at 02:28 | IP Logged
|
|
|
Well I first came up with your stab as well, but when I use that in the code the output will be:
131181215833807, (copy & paste)
but my Idea about the code results in a ! now that I've tried it, so we are not closer then we should be. Another problem I've solved is the autolog funcion in the program, everytime the software takes a masurement it logs the values to LCDtemp.txt, adding a read-only flag to the fileproperties will stop the continuous harddisk-activity, the program doesn't have a routine in it to handle this.
However, this file LCDtemp.txt can be used for PH..... I don't want the continuous HD-activity, so I probably going to use a ramdisk where the gameporttemp.exe, dll and html files are copied to by a Bat-file, and then run on the ramdisk.
But to get back to the problem:
My idea is to get this 131181215833807, and make a 13.11 out of it. When I programmed in TurboBasic I used len$ for it, but since this is not turbobasic... ;-)
Peter
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: January 23 2005 at 06:29 | IP Logged
|
|
|
I've been playing around a bit.... because the string returned was 131181215833807.....adding String(.... resulted in 131.181.215.833.807 so I started to play aound with the mid(... values and came up with this code:
string(double(ph_rtne(ph_setvar_s(1,1,ph_getwburl("http://127.0.0.1:81/sensor0.htm",10)) +
ph_setvar_a(1,2,pos(ph_getvar_s(1,1),"<BODY>")) +
ph_setvar_a(1,3,pos(ph_getvar_s(1,1),"</BODY>"))) + mid(ph_getvar_s(1,1),ph_getvar_n(1,2) +
6,ph_getvar_n(1,3) - ph_getvar_n(1,2) - 17)), "###,##")
Note that the value of thye original code:
- ph_getvar_n(1,2) -7) has been changed to -17
Now I have 5 digits returned and with string(.... "###,##" the output is better, when the 5th digit is other than zero, the output will now be 13.181 (if the last digit was zero the output would be 1.318 (stll a flaw) but we are getting there....
Peter
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: January 23 2005 at 12:58 | IP Logged
|
|
|
Hmm. I wonder what happens if the temp drops below 10? Will there be a leading zero?
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: January 23 2005 at 20:00 | IP Logged
|
|
|
Well Ive done a little more peeking at the source code and found that it's the GlobVarUnit.pas file that has the relevant DLL calls as shown below:
function GetGameTemperatureDLL(channel:integer;cycles:dword):double; stdcall; external DLLPath+'GameTemp.dll' name 'GetGameTemperature';
function GetCalibParamLinearDLL(channel:integer):double; stdcall; external DLLPath+'GameTemp.dll' name 'GetCalibParamLinear';
function GetCalibParamConstantDLL(channel:integer):double; stdcall; external DLLPath+'GameTemp.dll' name 'GetCalibParamConstant';
procedure SetCalibParamLinearDLL(channel:integer;Value:double); stdcall; external DLLPath+'GameTemp.dll' name 'SetCalibParamLinear';
procedure SetCalibParamConstantDLL(channel:integer;Value:double); stdcall; external DLLPath+'GameTemp.dll' name 'SetCalibParamConstant';
procedure CalibrateSensorDLL(channel:integer;MeasTemp0,MeasTemp1,PreciseTemp0,PreciseTemp1:double); stdcall; external DLLPath+'GameTemp.dll' name 'CalibrateSensor';
I'll play around with it some more and see if I can put a little something together in VB. What makes it hard is that my development machine doesnt have a gameport (notebook PC) and I'll have to code something up and move it to another machine to try and test it.
In any event, I havent given up completely, just will take a little longer with the lack of documentation .
To solve your other problem...just use the round() function after the double function. Like this:
string(round(double(ph_rtne(ph_setvar_s(1,1,ph_getwburl("http://127.0.0.1:81/sensor0.htm",10)) + ph_setvar_a(1,2,pos(ph_getvar_s(1,1),"<BODY>")) + ph_setvar_a(1,3,pos(ph_getvar_s(1,1),"</BODY>"))) + mid(ph_getvar_s(1,1),ph_getvar_n(1,2) + 6,ph_getvar_n(1,3) - ph_getvar_n(1,2) - 7)),2))
You can see that the round function takes two parameters...the first is the double that we want to round, the second is the number of decimal places we want to round to...in the example above, it's 2. I then convert the whole kit and caboodle to a string. You could then save this to a global variable for later use. I would also probably make a timed event fire so that once every 30 seconds or so, you execute the formula above to get the latest value.
HTH,
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: January 24 2005 at 06:00 | IP Logged
|
|
|
Here is the output when dave's new code is implemted:
The other output is dave's code when the ph_setvar_n(1,2) - 17)),2)) (-and not 7, 17 was my idea- )
Sensor0_test: 190027728982816 (ph_setvar_n(1,2)-7)),2))
Sensor0_test1: 19002 (ph_setvar_n(1,2)-17)),2))
If I add a string function, like this:
string(round(double(ph_rtne(ph_setvar_s(1,1,ph_getwburl("http://127.0.0.1:81/sensor0.htm",10))+ ph_setvar_a(1,2,pos(ph_getvar_s(1,1),"<BODY>")) +
ph_setvar_a(1,3,pos(ph_getvar_s(1,1),"</BODY>"))) + mid(ph_getvar_s(1,1),ph_getvar_n(1,2) +
6,ph_getvar_n(1,3) - ph_getvar_n(1,2) - 17)),2), "###,##")
(line one has to end with a plus sign but it doesn't seem to get on the screen)
then the output is 19,002
When perfecting the project I accidenatlly killed one sensor, so if I can't resolder it, I have to make due with 3 sensors....
Peter
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: January 24 2005 at 06:48 | IP Logged
|
|
|
Now with the code in these pages, I've made a quick page named peter.psp:
the names of the sensors are going to be renamed as soon as the sensors are in their final place.... perhaps A small photo with the values under the photo or something like that....
Like it?
Peter
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: January 24 2005 at 07:03 | IP Logged
|
|
|
Looking good!
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: January 25 2005 at 13:53 | IP Logged
|
|
|
Quote: I'll play around with it some more and see if I can put a little something together in VB. What makes it hard is that my development machine doesnt have a gameport (notebook PC) and I'll have to code something up and move it to another machine to try and test it.
In any event, I havent given up completely, just will take a little longer with the lack of documentation .
I have sent this guy an e-mail but it seems he doesn't like to receive thankyou's and information requests.... he still hasn't answered....sadly enough
Quote:
I then convert the whole kit and caboodle to a string. You could then save this to a global variable for later use. I would also probably make a timed event fire so that once every 30 seconds or so, you execute the formula above to get the latest value.
So I have to make a global Variable in PH first, let say sensor0 ... sensor3 then I have to add ph_setglobal_s(... and add it to the formula already existing....How should I do this? like so:?
ph_setglobal_s(sensor0, string(round(double(ph_rtne(ph_setvar_s(1,1,ph_getwburl("http://127.0.0.1:81/sensor0.htm",10)) + ph_setvar_a(1,2,pos(ph_getvar_s(1,1),"<BODY>")) + ph_setvar_a(1,3,pos(ph_getvar_s(1,1),"</BODY>"))) + mid(ph_getvar_s(1,1),ph_getvar_n(1,2) + 6,ph_getvar_n(1,3) - ph_getvar_n(1,2) - 7)),2), "###,##"))
What is the purpose of saving the formula outcome to a G.V.? To make it easier to hook into a formula or psp-page? Im looking forward to the VB-script you're working on....However the PSP-page I have created with you and tonyno's help can be something to be a little proud of in regarding to my knowlegde of PSP-language ...
Oh well, looking forward to your results, once this whole porject is working I will make a few web-pages of this project on my site with a copyright notice for the softwarepart to TonyNo, Me and Dave...
Peter
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: January 25 2005 at 15:25 | IP Logged
|
|
|
Peter,
The webpage is looking good .
Yep, by storing the result in a global variable, it makes referencing it within other code a lot easier. However, if you are using the above formula in a PSP page, then the GV wont help you and you would need to add another function to extract the global to use in your PSP page. Depending upon how often and how many places you access the temps will determine the best course of action. If you are only accessing the temps within a webpage then no sense in using the GV.
If it was me, I would set a timed event to once a minute and assign the temperature to a GV such as your "SENSOR0". I would then reference this GV from within the PSP page using this sample formula: <%{SENSOR0}%>. I could also create a trigger on the GV and do additional processing if the temperature is outside of certain limits, etc.
If you were going to assign the temp to a GV, then the proper formula would be:
ph_setglobal_a("SENSOR0",round(double(ph_rtne(ph_setvar_s(1,1,ph_getwburl("http://127.0.0.1:81/sensor0.htm",10)) + ph_setvar_a(1,2,pos(ph_getvar_s(1,1),"<BODY>")) + ph_setvar_a(1,3,pos(ph_getvar_s(1,1),"</BODY>"))) + mid(ph_getvar_s(1,1),ph_getvar_n(1,2) + 6,ph_getvar_n(1,3) - ph_getvar_n(1,2) - 7)),2))
In my example, the output of my formula will be a double number with 2 decimal places. Because it's a number we use the ph_setglobal_a (any) rather than the ph_setglobal_s (string). Note that we capitalize the GV name and enclose it within quotes.
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: February 09 2005 at 05:05 | IP Logged
|
|
|
TonyNo wrote:
Hmm. I wonder what happens if the temp drops below 10? Will there be a leading zero? |
|
|
well, as I exspected: The outside temp has dropped below zero and there is NO leading zero, so the only thing left is to change the formula......
Peter
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: February 09 2005 at 05:35 | IP Logged
|
|
|
just to show you how the temp-readings are looking right now, here's a screenshot. As you see: No leading zero
Sometimes the last digit of the read-temperature is a zero and is not there, so the formula reads a temperature which is e.g. 67.9 c when the actual temperature should be 6.79 c How to solve this could involve a formula combined with a case or if statement. The first temp is the server-room-temp. The second is the outside-temp, and the third is the solar-boiler-water-temp.
When digit's aren't read, this is what it looks like:
perhaps you now have an idea what I meant by "is not there"
the actual temps were 19,1 and 10
Peter
Edited by krommetje
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: February 09 2005 at 11:40 | IP Logged
|
|
|
Peter,
I don't think I fully understand what is going on, but Im sure it's because of my inability to see the actual returned data.
Would it be possible for you to post the raw code returned from the following statement:
ph_getwburl("http://127.0.0.1:81/sensor0.htm", 10)
both for when it seems to work and when it doesnt work ("is not there")? If I have both examples to work with of the raw returned data, then I should be able to come up with a simple formula that will work for you.
Let me know,
Dave.
|
Back to Top |
|
|
|
|