Private değişken nasıl kullanılıyor...

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Kullanıcı avatarı
uğur alkan
Üye
Mesajlar: 227
Kayıt: 29 Ağu 2004 04:49
Konum: Istanbul

Private değişken nasıl kullanılıyor...

Mesaj gönderen uğur alkan »

USB bir aygıtla haberleşmeye çalışıyorum HID sınıfı çalışıyor.

Kod: Tümünü seç

unit FormMain;

interface

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

const

   // input and out buffer size constants...
   BufferInSize  = 8;
   BufferOutSize = 8;
type

   // input and output buffers...
   TBufferIn = array[0..BufferInSize] of byte;
   TBufferOut = array[0..BufferOutSize] of byte;

   // main form
   TForm1 = class(TForm)
    Label1: TLabel;
      procedure FormCreate(Sender: TObject);
      procedure FormDestroy(Sender: TObject);
   private
      FBufferIn:TBufferIn;
      FBufferOut:TBufferOut;
      function USBEvent(var Msg: TMessage): Boolean;
   public
   end;

var
  Form1: TForm1;

implementation

uses
   cUSBInterface,
   cUSBInterfaceTypes;

const

   // vendor and product ID constants...
   VENDOR_ID           = ****;
   PRODUCT_ID          = ****;

{$R *.DFM}

{
****************************************************************************
* Name    : Create                                                         *
* Purpose : Create the main form                                           *
****************************************************************************
}
procedure TForm1.FormCreate(Sender: TObject);
begin
   Application.HookMainWindow(USBEvent);
   Connect(Application.Handle);
end;
{
****************************************************************************
* Name    : Destroy                                                        *
* Purpose : Free the main form                                             *
****************************************************************************
}
procedure TForm1.FormDestroy(Sender: TObject);
begin
   Application.UnHookMainWindow(USBEvent);
end;
{
****************************************************************************
* Name    : USBEvent                                                       *
* Purpose : DLL message handler hook                                       *
****************************************************************************
}
function TForm1.USBEvent(var Msg: TMessage): Boolean;
var
   DevHandle:cardinal;
//   TextBuffer:array[0..255] of char;
begin
  result := False;
  if Msg.Msg = WM_HID_EVENT then
  begin
     case Msg.WParam of

        // a HID device has been plugged in...
        NOTIFY_PLUGGED :
        begin

           // is it our HID device...
           DevHandle := Msg.LParam; // handle of HID device in this message
           if (GetVendorID(DevHandle) = VENDOR_ID) and (GetProductID(DevHandle) = PRODUCT_ID) then
           begin
              // add your code here, for example...
               form1.Caption:='Aygıt Kontrol Bulundu';
              // GetProductName(DevHandle, TextBuffer, 256);
              // ALabel.Caption := string(TextBuffer);
           end;
           result := true;
        end;

        // a HID device has been device removed...
        NOTIFY_UNPLUGGED :
        begin

           // is it our HID device...
           DevHandle := Msg.LParam; // handle of HID device in this message
           if (GetVendorID(DevHandle) = VENDOR_ID) and (GetProductID(DevHandle) = PRODUCT_ID) then
           begin
              form1.Caption:='Aygıt Kaldırıldı';
           end;
           result := true;
        end;

        // a HID device has been attached or removed. This event is fired after
        // either NotifyPlugged or NotifyUnplugged.
        NOTIFY_CHANGED :
        begin
           // get the handle of the device we are interested in
           // and set it's read notification flag to true...
           DevHandle := GetHandle(VENDOR_ID,PRODUCT_ID);
           SetReadNotify(DevHandle,true);
           result := true;
        end;

        // a HID device has sent some data..
        NOTIFY_READ :
        begin
           DevHandle := Msg.LParam; // handle of HID device in this message
           if (GetVendorID(DevHandle) = VENDOR_ID) and (GetProductID(DevHandle) = PRODUCT_ID) then
           begin
               // read the data - remember that first byte is report ID...
               Read(DevHandle,@FBufferIn);
               form1.Label1.Caption:=FBufferIn;
               // process data here...
           end;
           result := true;
        end;
     end;
  end;
end;

(*
   if you want to write some data to the USB device, then
   try using something like this...

   // first element is report ID, set to 0...
   FBufferOut[0] := $0;

   // fill the buffer with some data...
   for index := 1 to BufferOutSize do
      FBufferOut[index] := index;

   DevHandle := GetHandle(VendorID, ProductID);
   Write(DevHandle,@FBufferOut);
*)

end.
 
şeklinde bir kod bloğu olşturulmuş hazır olarak geliyor.
Yalnız buffer bilgilrine nasıl ulaşcam anlayamadım.


Kod: Tümünü seç

   private
      FBufferIn:TBufferIn;
      FBufferOut:TBufferOut;
      function USBEvent(var Msg: TMessage): Boolean;
   public
   end;
Tbufferin diye bir şey tanımlı ve örneği hiç yok HID.DLL dosyasını kullanıyor.

Bunu hangi değişken tipine atayarak işleyebilirim.

Teşekkür Ederim...
Bazen sert rüzgarlar eser başını öne eğmekten asla korkma
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Mesaj gönderen mrmarman »

Selam.

- En üstte Type tanımı yapılarak tip belirtilmiş.

Kod: Tümünü seç

   TBufferIn = array[0..BufferInSize] of byte; 

Kod: Tümünü seç

   BufferInSize  = 8; 
şeklindeki tanımla da bu değer 8 olduğuna göre ve 0'dan başladığın göre 9 BYTE uzunluğunda bir bilgi olduğu görülüyor.

- Değişkenin de 9 Byte uzunluğunda bir byte array olabilir. Yani değişkenin Deger ise tanımın,

Kod: Tümünü seç

Var
  Deger : TBufferIn;
tanımlayacağına göre her Byte'ı Deger[0], Deger[1] ... Deger[8] şeklinde byte by byte alabilirsin.
Resim
Resim ....Resim
Cevapla