Merhaba, Arkadaşlar,
Delphi ile seri port üzerinden 9-bit gönderen program yazmak istiyorum. Bunu için mevcut API'leri kullanacağım.Ama 9-bit data nasıl gönderebileceğim konusunda bir çözüme ulaşamadım.
START bit+ STOP bit hariç 9- bit olacak.
Parity bitini aktif yapıp değerini elle değiştirebilirmiyim ? Değiştirebilirisem bunu nasıl yaparım.
Aşağıdaki algoritma ile seri haberleşme yapılabiliyor.
Alıntı Yap
function TForm1.OpenCom(SerLinka : PChar) : boolean;
var
fSuccess : boolean;
dcb : TDCB;
TimeOuts : COMMTIMEOUTS;
begin
hCom := CreateFile(SerLinka,GENERIC_READ or GENERIC_WRITE,0,NIL,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if(hCom = INVALID_HANDLE_VALUE) then begin
Application.MessageBox('Uygunluk hatası !' , ApplicationName, MB_OK);
OpenCom := False;
exit;
end;
fSuccess := GetCommState(hCom, dcb);
if(not fSuccess ) then begin
Application.MessageBox('Okuma hatası !', ApplicationName, MB_OK);
OpenCom := False;
exit;
end;
dcb.BaudRate := 19200; //change of parameters
dcb.ByteSize := 8;
dcb.Parity := NOPARITY;
dcb.StopBits := ONESTOPBIT;
dcb.Flags := $00000001; //only fBinary = 1
fSuccess := SetCommState(hCom, dcb); //write of parameters back
if(not fSuccess) then begin
Application.MessageBox('Yazma hatası !', ApplicationName, MB_OK);
OpenCom := False;
exit;
end;
TimeOuts.ReadIntervalTimeout := 50; //set of timeouts
TimeOuts.ReadTotalTimeoutMultiplier := 50;
TimeOuts.ReadTotalTimeoutConstant := 100;
TimeOuts.WriteTotalTimeoutMultiplier := 50;
TimeOuts.WriteTotalTimeoutConstant := 100;
fSuccess := SetCommTimeouts(hCom,TimeOuts);
if(not fSuccess) then begin
Application.MessageBox('Zaman aşımı !', ApplicationName, MB_OK);
OpenCom := False;
exit;
end;
//clear of buffers
fSuccess := PurgeComm(hCom,PURGE_TXABORT+PURGE_RXABORT+PURGE_TXCLEAR+PURGE_RXCLEAR);
if(not fSuccess) then begin
Application.MessageBox('Buffer hatası !', ApplicationName, MB_OK);
OpenCom := False;
exit;
end;
OpenCom := True;
end;