02.10.2010, 17:34
|
Прохожий
|
|
Регистрация: 02.10.2010
Адрес: В Питере
Сообщения: 14
Версия Delphi: Delphi5
Репутация: 10
|
|
COM - BlueTooth
Решил вот выложить работу с blueTooth
Код:
function PortInit : boolean; //инициализация порта
var
ct: TCommTimeouts;
dcb: TDCB;
comport_arr :^char;
ptmp :^char;
i:integer;
begin
f := Windows.CreateFile(PChar(comport), GENERIC_READ or
GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);
if (f <= 0) or not Windows.SetupComm(f, 2048, 2048)or not
Windows.GetCommState(f, dcb) then exit; //init error
dcb.BaudRate := 9600;
dcb.StopBits := 0;
dcb.Parity := 2;
dcb.ByteSize := 8;
if not Windows.SetCommState(f, dcb)
or not Windows.GetCommTimeouts(f, ct) then exit; //error
ct.ReadTotalTimeoutConstant := 50;
ct.ReadIntervalTimeout := 50;
ct.ReadTotalTimeoutMultiplier := 1;
ct.WriteTotalTimeoutMultiplier := 0;
ct.WriteTotalTimeoutConstant := 10;
if not Windows.SetCommTimeouts(f, ct)
or not Windows.SetCommMask(f, EV_RING + EV_RXCHAR + EV_RXFLAG + EV_TXEMPTY)
then exit; //error
PortInit := true;
end;
function DoneComm: boolean; //закpыть поpт
begin
DoneComm := Windows.CloseHandle(f);
end;
function PostComm(var Buf; size: word): integer; //пеpедача в поpт
var
p: pointer;
i: cardinal;
begin
p := @Buf;
result := 0;
while size > 0 do begin
if not WriteFile(f, p^, 1, i, nil) then exit;
inc(result, i); inc(integer(p)); dec(size);
Application.ProcessMessages;
end;
PostComm := result;
end;
function ReadComm(var Buf; size: word): integer; //пpием из поpта
var
i: cardinal;
ovr: TOverlapped;
begin
fillChar(buf, size, 0);
fillChar(ovr, sizeOf(ovr), 0); i := 0; result := -1;
if not windows.ReadFile(f, buf, size, i, @ovr) then exit;
result := i;
ReadComm := result;
end;
но пишет ошибку минут через 5 работы, кто знает как исправить помогите, заранее благодарен
|