function TForm1.seqread(p:pointer): integer;
var
Sendbuffer :
String;
rData :
String;
rText :
String;
rDataword : word;
zeit :
String;
i : integer;
x : Char;
BinString :
String;
ADDString :
String;
dc: HDC;
begin
dc := GetDC(Form1.Handle);
if MasterStatus = true
then
begin
Timer1.Enabled := false;
Sendbuffer := ('
01100100010100000000') + #13#10;
//Status
SerialPortNG1.SendString(sendBuffer);
// Send String
while SerialPortNG1.SendInProgress
do
begin
Application.ProcessMessages;
end;
Repeat
pause(10);
rData := SerialPortNG1.ReadNextClusterAsString();
//empfangene Daten lesen
if (rData = '
')
and (Timer2.Enabled = false)
then
Timer2.Enabled := true;
until rData <> '
';
Timer2.Enabled := false;
rText := Copy(rdata, 13, 4);
// Status Value
rDataword := StrToInt('
$'+rText);
BinString := '
';
for i := 1
to 4
do //Hex to Bin
begin
x := rtext[i];
case x
of
'
0': ADDString := '
0000';
'
1': ADDString := '
0001';
'
2': ADDString := '
0010';
'
3': ADDString := '
0011';
'
4': ADDString := '
0100';
'
5': ADDString := '
0101';
'
6': ADDString := '
0110';
'
7': ADDString := '
0111';
'
8': ADDString := '
1000';
'
9': ADDString := '
1001';
'
A': ADDString := '
1010';
'
B': ADDString := '
1011';
'
C': ADDString := '
1100';
'
D': ADDString := '
1101';
'
E': ADDString := '
1110';
'
F': ADDString := '
1111';
end;
BinString := BinString + AddString;
end;
// for
//Bit reading Status
if BinString[16] = '
1'
then //Status Error
begin
StatusError := true;
MasterStatus := false;
end;
if BinString[9] = '
1'
then //Three or One phase?
begin
OnePhaseImage.visible := false;
ThreePhaseImage.visible := true;
PhaseLabel.Caption := '
Three phase';
end
else
begin
ThreePhaseImage.visible := false;
OnePhaseImage.visible := true;
PhaseLabel.caption := '
One phase';
end;
if BinString[10] = '
1'
then //Line 1 First?
begin
L2Image.Visible := false;
L1Image.Visible := true;
end
else
begin
L1Image.Visible := false;
L2Image.Visible := true;
end;
// End of Status
//Begin of Error
if StatusError = true
then
begin
Sendbuffer := ('
01100100010200000000') + #13#10;
//Status
SerialPortNG1.SendString(sendBuffer);
// Send String
while SerialPortNG1.SendInProgress
do
begin
Application.ProcessMessages;
end;
Repeat
pause(10);
rData := SerialPortNG1.ReadNextClusterAsString();
if (rData = '
')
and (Timer2.Enabled = false)
then
Timer2.Enabled := true;
until rData <> '
';
Timer2.Enabled := false;
rText := Copy(rdata, 13, 4);
// Error Value
rDataword := StrToInt('
$'+rText);
BinString := '
';
for i := 1
to 4
do
begin
x := rtext[i];
//Hex to BIn
case x
of
'
0': ADDString := '
0000';
'
1': ADDString := '
0001';
'
2': ADDString := '
0010';
'
3': ADDString := '
0011';
'
4': ADDString := '
0100';
'
5': ADDString := '
0101';
'
6': ADDString := '
0110';
'
7': ADDString := '
0111';
'
8': ADDString := '
1000';
'
9': ADDString := '
1001';
'
A': ADDString := '
1010';
'
B': ADDString := '
1011';
'
C': ADDString := '
1100';
'
D': ADDString := '
1101';
'
E': ADDString := '
1110';
'
F': ADDString := '
1111';
end;
BinString := BinString + AddString;
end;
// for
if BinString[6] = '
1'
then //Line 2 to high?
begin
Label10.Visible := true;
Shape5.Visible := true;
end;
if BinString[5] = '
1'
then //Line 1 to high?
begin
Label9.Visible := true;
Shape4.Visible := true;
end;
if BinString[4] = '
1'
then //Line 2 to low?
begin
Label8.Visible := true;
Shape3.Visible := true;
end;
if BinString[3] = '
1'
then //Line 1 to low?
begin
Label7.Visible := true;
Shape2.Visible := true;
end;
if BinString[2] = '
1'
then //Error Infrared CRC?
begin
Label6.Visible := true;
Shape1.Visible := true;
end;
if BinString[1] = '
1'
then //Error Infrared Watchdog
begin
Label5.Visible := true;
Shape6.Visible := true;
end;
end;
//if Status Error
//begining of Temp Measure
Sendbuffer := ('
01100100001800000000') + #13#10;
//Status
SerialPortNG1.SendString(sendBuffer);
// Send String
while SerialPortNG1.SendInProgress
do
begin
Application.ProcessMessages;
end;
Repeat
pause(10);
rData := SerialPortNG1.ReadNextClusterAsString();
if (rData = '
')
and (Timer2.Enabled = false)
then
Timer2.Enabled := true;
until rData <> '
';
Timer2.Enabled := false;
rText := Copy(rdata, 13, 4);
// Status Value
rDataword := StrToInt('
$'+rText);
zeit := DateTimeToStr(now);
Series1.Add(rdataword, zeit, clTeeColor);
end;
// if Master Status
Timer1.Enabled := true;
ReleaseDC(Form1.Handle,
dc);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
id : cardinal;
begin
BeginThread(
nil, 0, addr(TForm1.seqread),
nil, 0, id);
//Thread erzeugen
end;