procedure PortInit(name:string);
var
ThreadID,lastError:dword;
begin
blockSbuf:=false;
sBuf:='';
//создание и иницализация порта
KolByte:=0;
//создание порта и получение его хэндла
CommHandle := CreateFile(PCHAR(name),GENERIC_READ or GENERIC_WRITE,0,nil,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,0);
if (CommHandle=INVALID_HANDLE_VALUE) then messagebox(0,'инициализации порта','Ошибка',0);
lastError:=GetLastError;
if lastError<>0 then messagebox(0,PCHAR(intToStr(lastError)+' '+intToStr(CommHandle)),'lastError',0);
//построение DCB
GetCommState(CommHandle,DCB);
DCB.BaudRate:=CBR_115200;
DCB.Parity:=NOPARITY;
DCB.ByteSize:=8;
DCB.StopBits:=OneStopBit;
//устанавливаем DCB
SetCommState(CommHandle,DCB);
end;