Hallo zusammen, versuche seid gerauner Zeit eine RS232 Schnittstelle auszulesen.
Habe mir dafür die Komponente "TurboPower Async Professional" installiert.
Und das folgende Programm übernommen.
"procedure TForm1.ComleseClick(Sender: TObject);
var
lpszNumeCom : PChar;
dwAccessType : DWORD;
dwCreationType : DWORD;
creationDCB : TDCB;
hPort : THandle;
buffer : array[0..80] of char;
actRead : integer;
begin
{Some initial settings: I am working with COM2 in read/write}
lpszNumeCom := com1;
dwAccessType := GENERIC_READ or GENERIC_WRITE;
dwCreationType := OPEN_EXISTING;
hPort := CreateFile(lpszNumeCom,dwAccessType,0,Nil,dwCreationType,0,0);
{here I have the handle for the COM port}
try
if hPort <> INVALID_HANDLE_VALUE then
begin
GetCommState(hport,creationDCB);
creationDCB.BaudRate := 9600;
creationDCB.Parity := EVENPARITY;
creationDCB.ByteSize := 8;
creationDCB.StopBits := ONESTOPBIT;
{Settings for the control type, here I am reading from a Proximity
card reader and use only the RX line}
creationDCB.Flags := creationDCB.Flags + DTR_CONTROL_DISABLE
+ RTS_CONTROL_DISABLE;
if SetCommState(hPort,creationDCB) then
begin
PurgeComm(hPort,PURGE_RXCLEAR);
{Here I actually can read data from COM}
{The next function call will not return until it actually
reads data from the serial port}
ReadFile(hPort,buffer,56,actRead,nil);
PurgeComm(hPort,PURGE_RXCLEAR);
{in buffer you have data readed from the port}
begin
komoutput.caption := buffer.text;
end
end
end;
finally
CloseHandle(hPort);
end;"
Aber es funktioniert leider nicht.
Was muß ich darin ändern, bzw. öffne und schließe ich den port überhaupt? Erweiterungen?
Die Daten meiner auszulesenden Schnittstelle lauten:
"Konfiguration: 8 Databits, 1 Startbit, 1 Stopbit, No parity.
Baudrate: 9600 (default)
Adresse: aa (00-99)
Werteformat: xxxx.x (x= 0-9)
Merkerformat : bbbbbbbb (b= 0/1)"
Hoffe das mir hier jemand helfen kann.