Einzelnen Beitrag anzeigen

jacky213

Registriert seit: 2. Mär 2011
146 Beiträge
 
#10

AW: Dymo USB Waage ansteuern

  Alt 18. Mär 2019, 16:19
Ich habe die Komponente auf meiner Form, kannst du mir bitte ein Konkretes Beispiel machen?

Hier ist der gesamte Code meiner Anwendung:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Buttons, Vcl.ExtCtrls,
  JvComponentBase, JvHidControllerClass, Vcl.StdCtrls;

type
  TfrmMain = class(TForm)
    DC1: TJvHidDeviceController;
    wpan: TPanel;
    Button1: TButton;
    procedure DC1Arrival(HidDev: TJvHidDevice);
    procedure DC1DeviceData(HidDev: TJvHidDevice; ReportID: Byte;
      const Data: Pointer; Size: Word);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  frmMain: TfrmMain;
  ReceivedData : Array[0..5] of Byte;
  HIDDevice: TJvHidDevice;
  gram : boolean;
  division : boolean;
const
  VendorID = $0922;
  ProductID = $8000;

implementation

{$R *.dfm}

procedure TfrmMain.DC1Arrival(HidDev: TJvHidDevice);
begin
if ((HidDev.Attributes.VendorID = VendorID) AND
    (HidDev.Attributes.ProductID > ProductID)) then
  begin
    HIDDevice := HidDev;
    HIDDevice.CheckOut;
  end;
end;

procedure TfrmMain.DC1DeviceData(HidDev: TJvHidDevice;
  ReportID: Byte; const Data: Pointer; Size: Word);
  var raw_weight : integer;
  var raw_weight_oz : real;
begin
  CopyMemory(@ReceivedData, Data, Size);
  raw_weight := ReceivedData[3] + ReceivedData[4] * 256;
  if(raw_weight > 0) then
    begin
      if (ReceivedData[1] = 2) then //grams
      begin
        wpan.Caption := IntToStr(raw_weight)+' g';
        gram := true;
      end;
      if (ReceivedData[1] = 11) then //oz
      begin
        raw_weight_oz := raw_weight*0.1;
        wpan.Caption := FloatToStr(raw_weight_oz)+' oz';
        gram := false;
      end;
   end
   else
     begin
       wpan.Caption := '0 g';
     end;

  end;

end.
  Mit Zitat antworten Zitat