Code:
### Zum Öffnen der Verbindung ####
procedure TForm1.Starten1Click(Sender: TObject);
var dcb: TDCB;
begin
BuildCommDCB('Com3: baud=9600 parity=N data=8 stop=1', dcb);
if dcb.BaudRate = 9600
then ShowMessage('OK');
Coms := true;
// if (OpenDevice(0) = 0) and (OpenDevice(1) = 1)
// then begin
Com1 := CreateFile(PChar('COM1'), Generic_Read or Generic_Write, 0, nil, Open_Existing, File_Attribute_Normal, 0);
Com3 := CreateFile(PChar('COM3'), Generic_Read or Generic_Write, 0, nil, Open_Existing, File_Attribute_Normal, 0);
Karteladen1.Enabled := false;
Thermikerzeugen1.Enabled := false;
Thermikladen1.Enabled := false;
Startpunktfestlegen1.Enabled := false;
Starten1.Enabled := false;
Pause1.Enabled := true;
Stop1.Enabled := true;
Timer1.Enabled := true;
Timer1Timer(Sender);
// end
// else ShowMessage('ERROR. Could not connect Interface');
end;
### Zum Sende der Daten ###
procedure TForm1.Timer1Timer(Sender: TObject);
procedure ActualizeValues;
var Data: Array[0..1] of Integer;
begin
OpenDevice(0);
ReadAllAnalog(Data[0], Data[1]);
end;
function CreateGPSMessage: String;
var GPSMessage, Temp: String;
begin
DecimalSeparator := '.';
GPSMessage := '$GPGGA,';
Temp := TimeToStr(Now);
while Pos(':', Temp) > 0
do Delete(Temp, Pos(':', Temp), 1);
GPSMessage := GPSMessage + Temp + ',';
GPSMessage := GPSMessage + IntToStr(Position.XPos.Deg) + IntToStr(Position.XPos.Min) + FormatFloat('#.0000', Position.XPos.Sec) + ',N,';
GPSMessage := GPSMessage + IntToStr(Position.YPos.Deg) + IntToStr(Position.YPos.Min) + FormatFloat('#.0000', Position.YPos.Sec) + ',E,1,04,2.7,';
GPSMessage := GPSMEssage + FormatFloat('#.0', Height) + ',M,32.5,M,,*FF';
DecimalSeparator := ',';
CreateGPSMessage := GPSMessage;
end;
procedure SendGPSMessage(GPSMessage: String);
var BytesWritten: Cardinal;
begin
WriteFile(Com3, GPSMessage, Length(GPSMessage), BytesWritten, nil);
if not(BytesWritten = Length(GPSMessage))
then ShowMessage('Error occured while transmitting GPS-Data');
end;
procedure WriteCompass(Course: Byte);
var BytesWritten: Cardinal;
begin
WriteFile(Com1, Course, 1, BytesWritten, nil);
if not(BytesWritten = 1)
then ShowMessage('Error occured while transmitting Compass-Data');
end;
procedure SimulateSensors;
begin
OpenDevice(0);
OutputAllAnalog(Round(Height/256), Round(Height) mod 256);
OpenDevice(1);
OutputAnalogChannel(1, 128);
end;
begin
ActualizeValues;
if Coms
then begin
SendGPSMessage(CreateGPSMessage);
WriteCompass(Round(Direction/360*255));
end;
SimulateSensors;
end;
Ich hoffe mal ihr könnt mir helfen. Schon mal danke
Lesezeichen