Autor Beitrag
skaven
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41



BeitragVerfasst: Do 14.10.04 14:11 
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.
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Sa 23.10.04 21:03 
Hallo,

habe davon null Ahnung, habe es aber doch schon für meien µC gebraucht. Dafür habe ich TCommPortDeiver von Marco Cocco genommen (gibts bei Torry's). Villeicht hilft das ja mal.

Aber schau dir mal die Zeile an:
"creationDCB.StopBits := ONESTOPBIT;"

ONESTOPBIT - fällt dir was auf? Du hast doch gar keine Stoppbits! Allein deswegen muss es schif gehen :idea:

Über den Rest des Codes kann ich dir nix sagen, weil ich, wie gesagt, von COM-Ports keine ahnung habe :wink:

_________________
Life is a bad adventure, but the graphic is really good!