Einzelnen Beitrag anzeigen

HaGü

Registriert seit: 18. Apr 2006
Ort: Cochem
19 Beiträge
 
#3

Re: Relaiskarte K8056 von Velleman seriell ansteuern

  Alt 22. Mai 2006, 16:14
Hallo Klaus,

öffnen und schliessen mach ich mit inpout32.dll.
Habe aber auch die "TurboPower Async Professional" installiert.
Mein Listing bis jetzt wäre:
Delphi-Quellcode:
unit Relaiskarte1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    Datei1: TMenuItem;
    beenden1: TMenuItem;
    Relais1: TMenuItem;
    allean1: TMenuItem;
    alleaus1: TMenuItem;
    RadioGroup1: TRadioGroup;
    RadioGroup2: TRadioGroup;
    RadioGroup3: TRadioGroup;
    RadioGroup4: TRadioGroup;
    RadioGroup5: TRadioGroup;
    RadioGroup6: TRadioGroup;
    RadioGroup7: TRadioGroup;
    RadioGroup8: TRadioGroup;
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure beenden1Click(Sender: TObject);
    procedure allean1Click(Sender: TObject);
    procedure alleaus1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);


  private
    { Private-Deklarationen }


  public
    { Public-Deklarationen }
  end;
var
  Form1: TForm1;
  ComHandle: THandle;
  f: TextFile;
  s: string;

implementation
{$R *.dfm}
{Funktionen aus "inpout32.dll" laden:}
procedure Out32(Addresse:Integer; Wert:byte);stdcall;export; external 'INPOUT32.DLL';
function Inp32(Addresse:Integer):Byte;stdcall;export; external 'INPOUT32.DLL';



procedure TForm1.beenden1Click(Sender: TObject);
begin
     RadioGroup1.ItemIndex:= 1;
     RadioGroup2.ItemIndex:= 1;
     RadioGroup3.ItemIndex:= 1;
     RadioGroup4.ItemIndex:= 1;
     RadioGroup5.ItemIndex:= 1;
     RadioGroup6.ItemIndex:= 1;
     RadioGroup7.ItemIndex:= 1;
     RadioGroup8.ItemIndex:= 1;
  FileClose(ComHandle);
  close;
end;

procedure TForm1.allean1Click(Sender: TObject);

begin

     RadioGroup1.ItemIndex:= 0;
     RadioGroup2.ItemIndex:= 0;
     RadioGroup3.ItemIndex:= 0;
     RadioGroup4.ItemIndex:= 0;
     RadioGroup5.ItemIndex:= 0;
     RadioGroup6.ItemIndex:= 0;
     RadioGroup7.ItemIndex:= 0;
     RadioGroup8.ItemIndex:= 0;
end;

procedure TForm1.alleaus1Click(Sender: TObject);
begin
     RadioGroup1.ItemIndex:= 1;
     RadioGroup2.ItemIndex:= 1;
     RadioGroup3.ItemIndex:= 1;
     RadioGroup4.ItemIndex:= 1;
     RadioGroup5.ItemIndex:= 1;
     RadioGroup6.ItemIndex:= 1;
     RadioGroup7.ItemIndex:= 1;
     RadioGroup8.ItemIndex:= 1;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
 {evtl. geöffnete Schnittstelle schließen:}
 CloseHandle(ComHandle);
 {COM2 per API-Funktion (CreateFile) öffnen:}
 ComHandle := CreateFile('COM2', GENERIC_READ or GENERIC_WRITE,
                           0, nil, OPEN_EXISTING, 0, 0);
 {Hinweis, ob Schnittstelle geöffnet werden konnte:}
 if ComHandle = INVALID_HANDLE_VALUE then
  begin
   beep;
   Label1.Caption := 'Fehler beim Öffnen von COM2';
  end
  else
   Label1.Caption := 'COM2 geöffnet';
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
   EscapeCommFunction(ComHandle, SETDTR);
   EscapeCommFunction(ComHandle, SETRTS);
   EscapeCommFunction(ComHandle, SETBREAK);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
   EscapeCommFunction(ComHandle, CLRDTR);
   EscapeCommFunction(ComHandle, CLRRTS);
   EscapeCommFunction(ComHandle, CLRBREAK);
end;





end.
  Mit Zitat antworten Zitat