unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
JvSimpleXml, JvComponent, JvThread, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP, ExtCtrls, StdCtrls;
type
TService1 =
class(TService)
Timer1: TTimer;
IdHTTP1: TIdHTTP;
JvThread1: TJvThread;
JvXML: TJvSimpleXML;
procedure get_xml();
procedure WriteLogFile(text:
string);
procedure Timer1Timer(Sender: TObject);
procedure JvThread1Execute(Sender: TObject; Params: Pointer);
private
{ Private-Deklarationen }
public
txt_logfile: textFile;
function GetServiceController: TServiceController;
override;
{ Public-Deklarationen }
end;
var
Service1: TService1;
temp1,temp2,luft:real;
watch:boolean;
implementation
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord);
stdcall;
begin
Service1.Controller(CtrlCode);
end;
function TService1.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TService1.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled:=false;
//JvThread1.ThreadDialog := Nil;
//JvThread1.Execute(Self);
WriteLogFile('
lol');
Timer1.Enabled:=true;
end;
procedure TService1.JvThread1Execute(Sender: TObject; Params: Pointer);
var old,new:
string;
begin
{
old:='.';
new:=',';
get_xml();
temp1:=StrToFloat(StringReplace(FloatToStr(temp1),old,new,[rfReplaceAll]));
temp2:=StrToFloat(StringReplace(FloatToStr(temp2),old,new,[rfReplaceAll]));
luft:=StrToFloat(StringReplace(FloatToStr(luft),old,new,[rfReplaceAll]));
WriteLogFile(';' + FloatToStr(temp1) + ';' + FloatToStr(temp2) + ';' + FloatToStr(luft));
}
end;
//##########################################
//# #
//# Procedure zum auslesen der XML-Daten #
//# #
//##########################################
procedure TService1.get_xml();
var dateiname,old,new:
string;
memo:TStringList;
begin
dateiname:='
http://217.69.240.151/xml';
try
memo.Create;
memo.Text:=IdHTTP1.Get(dateiname);
JvXML.LoadFromString(memo.Text);
memo.Free;
old:='
.';
new:='
,';
luft:=StrToFloat(StringReplace(JvXML.Root.Items[0].Items.Value('
t1'),old,new,[rfReplaceAll]));
temp1:=StrToFloat(StringReplace(JvXML.Root.Items[0].Items.Value('
t0'),old,new,[rfReplaceAll]));
temp2:=StrToFloat(StringReplace(JvXML.Root.Items[0].Items.Value('
t2'),old,new,[rfReplaceAll]));
except
// Fehlerbehandlung
end;
end;
//##########################################
//# #
//# Procedure zum Speichern der Daten #
//# in Log-File #
//# #
//##########################################
procedure TService1.WriteLogFile(text:
string);
begin
try
AssignFile(txt_logfile, '
sensor.log');
Append(txt_logfile);
DateSeparator:='
/';
Writeln(txt_logfile, FormatDateTime('
yyyy/mm/dd hh:nn:ss',Now) + text);
Flush(txt_logfile);
CloseFile(txt_logfile);
except
end;
end;
end.