Главная Новые темы Список тем Задать вопрос Поиск  

Форум "Delphi"


Паскаль, Делфи


 #0 Vitar © 28.09.06 08:28:45 - 20.10.06 16:49:52

LPT - порт



Как к ниму правильно добраться ??? Цитата

 #1 Deep © 28.09.06 10:37:09

зависит от виндовса    
 #2 Vitar © 29.09.06 09:26:17

NT -интерисует!!! чтоб быть точнее 2000, ХР...
 #3 kostjan 11.10.06 09:07:41

v spravke,cherez poisk- modul',funkcii...

отправлено с мобилки
 #4 Inventor 20.10.06 16:49:52

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    GroupBox1: TGroupBox;
    StaticText1: TStaticText;
    ComboBox1: TComboBox;
    StaticText2: TStaticText;
    StaticText3: TStaticText;
    StaticText4: TStaticText;
    StaticText5: TStaticText;
    StaticText6: TStaticText;
    StaticText7: TStaticText;
    GroupBox2: TGroupBox;
    StaticText8: TStaticText;
    ComboBox2: TComboBox;
    StaticText9: TStaticText;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    CheckBox1: TCheckBox;
    Panel1: TPanel;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
    Lpt : TLptPortConnection;
  public
    { Public declarations }
    function GetCurrentPort : byte;     // ×èò&#224­;åò ñïè&#241­;îê ComboBox1 è âîç&#226­;ðàù&#224­;åò ñîî&#242­;âåò&#241­;òâó&#254­;ùèé íîì&#229­;ð ïîð&#242­;à
    function GetCurrentRegister : byte; // ×èò&#224­;åò ñïè&#241­;îê ComboBox2 è âîç&#226­;ðàù&#224­;åò ñîî&#242­;âåò&#241­;òâó&#254­;ùèé íîì&#229­;ð ðåã&#232­;ñòð&#224­;

  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var msg : AnsiString;
begin
 Lpt := TLptPortConnection.Create;
 if not Lpt.Ready then
  begin { îáú&#229­;êò íå ãîò&#238­;â -- ïîê&#224­;æåì êîä îøè&#225­;êè }
  msg := 'Îøè&#22­5;êà ïðè ñîç&#228­;àíè&#232­; îáú&#229­;êòà Lpt, êîä = ' + IntToStr(GetLastError());
  Application.MessageBox(PChar(msg),'ERRO­R',MB_OK);
  Application.Terminate; // âûõ&#238­;ä
  end;
 // Ïðî&#226­;åðè&#236­; íàë&#232­;÷èå ïîð&#242­;îâ è çàï&#238­;ëíè&#236­; èõ ñïè&#241­;îê â ComboBox-e
 ComboBox1.Items.Clear;
 ComboBox1.Text := '';
 if Lpt.IsPortPresent(LPT1) then ComboBox1.Items.Add('LPT1');
 if Lpt.IsPortPresent(LPT2) then ComboBox1.Items.Add('LPT2');
 if Lpt.IsPortPresent(LPT3) then ComboBox1.Items.Add('LPT3');
 if 0<>ComboBox1.Items.Count then ComboBox1.ItemIndex := 0;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
 Timer1.Enabled := false;
 Lpt.Destroy;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 Close();
end;

function TForm1.GetCurrentPort : byte;     // &#215;&#232;&#242;&#224­;&#229;&#242; &#241;&#239;&#232;&#241­;&#238;&#234; ComboBox1 &#232; &#226;&#238;&#231;&#226­;&#240;&#224;&#249;&#224­;&#229;&#242; &#241;&#238;&#238;&#242­;&#226;&#229;&#242;&#241­;&#242;&#226;&#243;&#254­;&#249;&#232;&#233; &#237;&#238;&#236;&#229­;&#240; &#239;&#238;&#240;&#242­;&#224;
begin
 if 'LPT1' = ComboBox1.Text then
  GetCurrentPort:=LPT1
                            else
  if 'LPT2' = ComboBox1.Text then
   GetCurrentPort:=LPT2      else
   GetCurrentPort:=LPT3;
end;

function TForm1.GetCurrentRegister : byte; // &#215;&#232;&#242;&#224­;&#229;&#242; &#241;&#239;&#232;&#241­;&#238;&#234; ComboBox2 &#232; &#226;&#238;&#231;&#226­;&#240;&#224;&#249;&#224­;&#229;&#242; &#241;&#238;&#238;&#242­;&#226;&#229;&#242;&#241­;&#242;&#226;&#243;&#254­;&#249;&#232;&#233; &#237;&#238;&#236;&#229­;&#240; &#240;&#229;&#227;&#232­;&#241;&#242;&#240;&#224­;
begin
 if '&#196;&#192;&#205;&#20­5;&#219;&#213;' = ComboBox2.Text then
  GetCurrentRegister:=LPT_DATA_REG
                              else
  if '&#209;&#206;&#209;&#21­0;&#206;&#223;&#205;&#20­0;&#223;' = ComboBox2.Text       then
   GetCurrentRegister:=LPT_STATE_REG    else
   GetCurrentRegister:=LPT_CONTROL_REG;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var PairArray : packed array [0..2] of ADRDATASTRUCT;
    port : byte;
begin
 if CheckBox1.Checked then
  begin
   port:=GetCurrentPort(); // &#207;&#238;&#235;&#243­;&#247;&#232;&#242;&#252­; &#237;&#238;&#236;&#229­;&#240; &#226;&#251;&#225;&#240­;&#224;&#237;&#237;&#238­;&#227;&#238; &#239;&#238;&#240;&#242­;&#224;
   // &#200;&#237;&#232;&#246­;&#232;&#224;&#235;&#232­;&#231;&#232;&#240;&#243­;&#229;&#236; &#236;&#224;&#241;&#241­;&#232;&#226;
   PairArray[0].Adr := port or LPT_DATA_REG;
   PairArray[1].Adr := port or LPT_STATE_REG;
   PairArray[2].Adr := port or LPT_CONTROL_REG;
   // &#215;&#232;&#242;&#224­;&#229;&#236; &#239;&#238;&#240;&#242­;&#251;
   if not Lpt.ReadPorts((собачка)PairArray,3) then
    Panel1.Color := clRed   else
    begin
     Panel1.Color := clLime;
     // &#194;&#251;&#226;&#229­;&#228;&#229;&#236; &#240;&#229;&#231;&#243­;&#235;&#252;&#242;&#224­;&#242;&#251; &#247;&#242;&#229;&#237­;&#232;&#255; &#239;&#238;&#240;&#242­;&#238;&#226;
     StaticText5.Caption := IntToHex(integer(PairArray[0].Data),2);­
     StaticText6.Caption := IntToHex(integer(PairArray[1].Data),2);­
     StaticText7.Caption := IntToHex(integer(PairArray[2].Data),2);­
    end;

  end; // if Checked...
end;

procedure TForm1.Button1Click(Sender: TObject); {&#226;&#251;&#226;&#23­8;&#228; &#231;&#237;&#224;&#247­;&#229;&#237;&#232;&#255­; &#226; &#240;&#243;&#247;&#237­;&#238;&#236; &#240;&#229;&#230;&#232­;&#236;&#229;}
var Value : byte;
begin
 Value := StrToInt('$0'+Edit1.Text);
 Lpt.WritePort(GetCurrentPort(),GetCurre­ntRegister(),Value);
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin

 if not ((Key<' ') or ((Key>='0')and(Key<='9')) or ((Key>='A')and(Key<='F')) or ((Key>='a')and(Key<='f'))) then
  Key := chr(0);
end;

end.




  • Написать ответ

    Имя: Регистрация HTML?
    smiles смайлики
    Потом перейти в:    
    паутина



      ©  webest.net, 2002-2007  

    top.mail.ru
    » Бесплатный счетчик посещений
    » Рейтинг сайтов