Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 26.12.2011, 18:09   #1
Ghennadiy
Форумчанин
 
Регистрация: 21.08.2009
Сообщений: 153
Сообщение сделать dpr

может кто-то помочь привести этот код в рабочее состояние сделав из него проект на делфи что бы не выдавал ошибки при компиляции?

Код:
function OpenCOMPort: Boolean;
var
  DeviceName: array[0..80] of Char;
  ComFile: THandle;
begin
   { First step is to open the communications device for read/write.
     This is achieved using the Win32 'CreateFile' function.
     If it fails, the function returns false.

     Wir versuchen, COM1 zu öffnen.
     Sollte dies fehlschlagen, gibt die Funktion false zurück.
   }
  StrPCopy(DeviceName, 'COM1:');

  ComFile := CreateFile(DeviceName,
    GENERIC_READ or GENERIC_WRITE,
    0,
    nil,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL,
    0);

  if ComFile = INVALID_HANDLE_VALUE then
    Result := False
  else
    Result := True;
end;


function SetupCOMPort: Boolean;
const
  RxBufferSize = 256;
  TxBufferSize = 256;
var
  DCB: TDCB;
  Config: string;
  CommTimeouts: TCommTimeouts;
begin
   { We assume that the setup to configure the setup works fine.
     Otherwise the function returns false.

     wir gehen davon aus das das Einstellen des COM Ports funktioniert.
     sollte dies fehlschlagen wird der Rückgabewert auf "FALSE" gesetzt.
   }

  Result := True;

  if not SetupComm(ComFile, RxBufferSize, TxBufferSize) then
    Result := False;

  if not GetCommState(ComFile, DCB) then
    Result := False;

  // define the baudrate, parity,...
  // hier die Baudrate, Parität usw. konfigurieren
   
  Config := 'baud=9600 parity=n data=8 stop=1';

  if not BuildCommDCB(@Config[1], DCB) then
    Result := False;

  if not SetCommState(ComFile, DCB) then
    Result := False;

  with CommTimeouts do
  begin
    ReadIntervalTimeout         := 0;
    ReadTotalTimeoutMultiplier  := 0;
    ReadTotalTimeoutConstant    := 1000;
    WriteTotalTimeoutMultiplier := 0;
    WriteTotalTimeoutConstant   := 1000;
  end;

  if not SetCommTimeouts(ComFile, CommTimeouts) then
    Result := False;
end;


{
  The following is an example of using the 'WriteFile' function
  to write data to the serial port.

  Folgendes Beispiel verwendet die 'WriteFile' Funktion, um Daten
  auf den seriellen Port zu schreiben.
}


procedure SendText(s: string);
var
  BytesWritten: DWORD;
begin
   {
     Add a word-wrap (#13 + #10) to the string

     An den übergebenen String einen Zeilenumbruch (#13 + #10) hängen
   }
  s := s + #13 + #10;
  WriteFile(ComFile, s[1], Length(s), BytesWritten, nil);
end;


{
  The following is an example of using the 'ReadFile' function to read
  data from the serial port.
  
  Folgendes Beispiel verwendet die 'ReadFile' Funktion, um Daten
  vom seriellen Port zu lesen.
}


procedure ReadText: string;
var
  d: array[1..80] of Char;
  s: string;
  BytesRead, i: Integer;
begin
  Result := '';
  if not ReadFile(ComFile, d, SizeOf(d), BytesRead, nil) then
  begin
    { Raise an exception }
  end;
  s := '';
  for i := 1 to BytesRead do s := s + d[I];
  Result := s;
end;


procedure CloseCOMPort;
begin
  // finally close the COM Port!
  // nicht vergessen den COM Port wieder zu schliessen!
  CloseHandle(ComFile);
end;
Ghennadiy вне форума Ответить с цитированием
Старый 26.12.2011, 20:42   #2
Ghennadiy
Форумчанин
 
Регистрация: 21.08.2009
Сообщений: 153
Сообщение

вот ошибки получаються
http://zalil.ru/32379260
Ghennadiy вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Error .dpr Fok Общие вопросы Delphi 13 02.08.2019 09:01
*.exe в *.dpr ubun Общие вопросы Delphi 3 08.01.2011 18:11
Ссылка на процедуру из dpr которая в pas Alex Cones Win Api 3 14.11.2009 13:00
Разбить dpr на юниты Alex Cones Общие вопросы Delphi 5 08.11.2009 16:40
Что случилось с DPR? Ash Общие вопросы Delphi 2 05.12.2008 18:35