Требуется программист в Зеленограде
- обработка данных с датчиков; ColdFire; 40 тыс. e-mail:jobsmp@pochta.ru |
Для дельфей под винду
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Spin;
.....
Var
dcb :TDCB;
hCom :THANDLE;
dwError :DWORD;
fSuccess :BOOl;
modemstatus:Dword;
// процедура открытия порта
procedure OpenCom;
var Tmp:Pchar;
begin
dwError:=Noerror;
hCom := CreateFile(pchar(Form1.Port.text),
GENERIC_READ or GENERIC_WRITE,
0, (* comm devices must be opened w/exclusive-access *)
Nil, (* no security attrs *)
OPEN_EXISTING, (* comm devices must use OPEN_EXISTING *)
0, (* not overlapped I/O *)
0 (* hTemplate must be NULL for comm devices *)
);
if (hCom = INVALID_HANDLE_VALUE)
then
begin
dwError := GetLastError();
exit;
end;
(*
* Omit the call to SetupComm to use the default queue sizes.
* Get the current configuration.
*)
fSuccess := GetCommState(hCom, dcb);{берем контекст устройства}
if not(fSuccess)
then
begin
dwError := GetLastError();
exit;
end;
with dcb do
begin
DCBlength:=sizeof(Dcb);
BaudRate :=STRtoint(Form1.speed.items[Form1.speed.itemindex]);
ByteSize := STRtoint(Form1.Lenght.items[Form1.Lenght.itemindex]);
Case Form1.Control.itemindex of
0: Parity := NoParity; {бит 9 негенерится}
1: Parity := ODDParity; {бит 9 генерится микросхемой}
2: Parity := EVENPARITY;{бит 9 генерится микросхемой}
3: Parity := MarkPARITY;{бит 9 = 1}
4: Parity := SPACEPARITY;{бит 9 = 0}
end;
case form1.stopbit.itemindex of
0: StopBits := ONESTOPBIT;
1: stopbits := One5STOPBITS;
else StopBits := TWOSTOPBITS;
end;
end;
fSuccess := SetCommState(hCom, dcb);
if not(fSuccess)
then
begin
dwError := GetLastError();
exit;
end;
end;
// процедура закрытия порта
procedure CloseCom;
begin
dwError:=Noerror;
fSuccess := CloseHandle(hCom);
if not(fSuccess)
then
begin
dwError := GetLastError();
exit;
end;
end;