super, also hier mal eine kurze (!!) beschreibung:
hab 2 edits:
1) gibt den comport an ('com6' in meinem Fall)
2) gibt den Befehl an, den man ans modem senden will (nur mal als test ob alles funktioniert)
Buttons:
1) 'Test Connection' -> code:
Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
var StartIni : TIniFile;
begin
ComPort1.Port:=Edit1.Text;
//Ini File
StartIni:=TIniFile.Create(ChangeFileExt(Application.ExeName,'
.INI'));
try
StartIni.writeString('
Com','
Name',Edit1.Text);
finally
StartIni.Free;
end;
ComPort1.Open;
end;
2) Disconnect (Testzweck) beinhaltet nur Comport1.Close;
3) Write -> sendet das was in Edit2.Text steht an den Port -> code:
Delphi-Quellcode:
procedure TForm1.Button4Click(Sender: TObject);
var Str: String;
begin
//write to port
Str := Edit2.Text;
//ComPort1.WriteStr(Str); // string type variable
ComPort1.Write(Str[1], Length(Str)); // no defined type
ComPort1.TransmitChar(#13);
ShowMessage('Write Data Successfull');
//answer
//read_answer; //das war mein Alternativversuch, wird nicht verwendet
//answer with datapacket
ComDataPacket1.StartString:=#10; //hier angegeben, da es per Optionsmenu als '#13' angegeben wird (alter fehler)
ComDataPacket1.StopString:=#13;
end;
so und jetzt noch die komponenten:
1) TComPort ('ComPort1'):
Delphi-Quellcode:
object ComPort1: TComPort
BaudRate = br9600
Port = 'COM6'
Parity.Bits = prNone
StopBits = sbOneStopBit
DataBits = dbEight
EventChar = #10
Events = [evRxChar, evTxEmpty, evRxFlag, evRing, evBreak, evCTS, evDSR, evError, evRLSD, evRx80Full]
Buffer.InputSize = 4096
Buffer.OutputSize = 4096
FlowControl.OutCTSFlow = True
FlowControl.OutDSRFlow = False
FlowControl.ControlDTR = dtrDisable
FlowControl.ControlRTS = rtsHandshake
FlowControl.XonXoffOut = False
FlowControl.XonXoffIn = False
Timeouts.ReadInterval = 20
Timeouts.ReadTotalMultiplier = 100
Timeouts.ReadTotalConstant = 10000
Timeouts.WriteTotalMultiplier = 2
Timeouts.WriteTotalConstant = 10000
OnError = ComPort1Error
Left = 8
Top = 200
end
2) TComDataPacket -> code:
Delphi-Quellcode:
object ComDataPacket1: TComDataPacket
ComPort = ComPort1
OnPacket = ComDataPacket1Packet
Left = 48
Top = 200
end
und zuletzt noch: OnPacket ->
Delphi-Quellcode:
procedure TForm1.ComDataPacket1Packet(Sender: TObject; const Str: String);
begin
ShowMessage('Packet RX: '+IntToStr(length(str)));
ShowMessage(str);
end;
so das wäre alles... hoffe es hilft dir weiter