AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

DLL einbinden octopus.dll

Offene Frage von "multi-man"
Ein Thema von multi-man · begonnen am 22. Jul 2008 · letzter Beitrag vom 5. Aug 2008
Antwort Antwort
Seite 1 von 4  1 23     Letzte »    
multi-man

Registriert seit: 9. Jul 2008
16 Beiträge
 
Delphi 7 Professional
 
#1

DLL einbinden octopus.dll

  Alt 22. Jul 2008, 22:59
Hallo !

Ich habe folgendes Problem :

Ich habe einen OctopusUSB ( Hier der Link )
Das ist ein Ein/Ausgabe Interface für den Anschluss an USB. Ich habe es mir bestellt, da ich dachte, ich bekomme es auch mit Delphi angesteuert, allerdings komme ich nicht richtig weiter...

Dabei ist eine octopus.dll
Diese exportiert unter anderem eine Funktion "octopus_init" :
Code:
/*
 * initial octopus handle before use octopus_open
 */
int octopus_init(struct octopus_context *octopus)
{
   if (octopus == NULL)
      octopus_error_return(-1,"octopus not valid");

   octopus->error_str = NULL;
   octopus->usb_handle = NULL;
 
   return 1;
}
Dass ich diese mit
function octopus_init(context: octopus_context): integer; external 'octopus.dll'; aufrufen kann ist klar, aber was mache ich eben mit den Übergabewert "*octopus" ?

Das struct octopus_context ist wie folgt definiert :
Code:
struct octopus_context {
   // USB specific
   /// libusb's usb_dev_handle
   struct usb_dev_handle *usb_handle;

   /// String representation of last error
   char *error_str;
};
Ich habe es versucht mit folgendem record zu übersetzen :

Delphi-Quellcode:
  usb_device_handle = Record
  end;

  octopus_context = record
      usb_handle : usb_device_handle;
      error_str : string;
  end;
aber der Inhalt bleibt leer, und sobald ich eine andere Funktion aufrufen möchte, kommt eine exception ...

Ich hoffe mir kann jemand helfen

mfg
Chris
  Mit Zitat antworten Zitat
multi-man

Registriert seit: 9. Jul 2008
16 Beiträge
 
Delphi 7 Professional
 
#2

Re: DLL einbinden octopus.dll

  Alt 23. Jul 2008, 00:40
Hier nochmal ein paar Hintergrundinfos zu dem Teil :

Downloads-Section auf Embedded-projects.net

Hier gibt es ein Handbuch zu dem Teil (allerdings noch im Aufbau)

In C ist es ohne Probleme ansprechbar, allerdings will ich nicht erst ein C-Prog coden, dass ich dann von der Delphi-App fernsteuern lasse

Ich hoffe auf eure Tipps

mfg
Chris
  Mit Zitat antworten Zitat
multi-man

Registriert seit: 9. Jul 2008
16 Beiträge
 
Delphi 7 Professional
 
#3

Re: DLL einbinden octopus.dll

  Alt 23. Jul 2008, 20:44
Falls ich ins falsche Forum gepostet habe, oder einfach zu wenige Informationen wäre ich auch über einen Hinweis dankbar ..
  Mit Zitat antworten Zitat
omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#4

Re: DLL einbinden octopus.dll

  Alt 23. Jul 2008, 20:49
versuch es doch mal so...
function octopus_init(var context: octopus_context): integer; external 'octopus.dll';
  Mit Zitat antworten Zitat
multi-man

Registriert seit: 9. Jul 2008
16 Beiträge
 
Delphi 7 Professional
 
#5

Re: DLL einbinden octopus.dll

  Alt 23. Jul 2008, 21:03
Es gab wieder denselben fehler, habe den Fehler mal als screenshot angehängt ...
Miniaturansicht angehängter Grafiken
delphifehler_195.jpg  
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#6

Re: DLL einbinden octopus.dll

  Alt 23. Jul 2008, 21:10
Zeig doch mal den ganzen Code. Wie rufst du die Funktion denn auf? hast du auch entsprechend Speicher reserviert? Und wie sieht es mit den Aufrufkonventionen aus? Standardmäßig nimmt Delphi, wenn nichts anderes angegeben ist Register. C-DLLs, die auch für andere Programmiersprachen gedacht sind nehmen meist stdcall. Was sagt denn die Dokumentation dazu?
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#7

Re: DLL einbinden octopus.dll

  Alt 23. Jul 2008, 21:13
eventuell sind das alles Zeiger...
Delphi-Quellcode:
type
  usb_device_handle = record
  end;

  Pusb_device_handle = ^usb_device_handle;

  octopus_context = record
    usb_handle : Pusb_device_handle;
    error_str : pchar;
  end;
  Poctopus_context = ^octopus_context;
function octopus_init(context: Poctopus_context): integer; stdcall; external 'octopus.dll';
Delphi-Quellcode:
var context:Poctopus_context;
begin
  new(context);
  if octopus_init(context) <> 0 then
  begin
  end;
end;
  Mit Zitat antworten Zitat
multi-man

Registriert seit: 9. Jul 2008
16 Beiträge
 
Delphi 7 Professional
 
#8

Re: DLL einbinden octopus.dll

  Alt 23. Jul 2008, 21:17
Speicher reserviert ? Wohl eher nicht
Aber hier mal der Code :
Delphi-Quellcode:
unit octopusU1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

type
  usb_device_handle = Record
  end;

  octopus_context = record
      usb_handle : usb_device_handle;
      error_str : string;
  end;

var

  Form1: TForm1;
  oc1 : octopus_context;


implementation


{$R *.dfm}

function octopus_init(var context: octopus_context): integer; external 'octopus.dll';

function octopus_get_hwdesc(var context: octopus_context; desc: Pchar): Pchar; external 'octopus.dll';

function octopus_open(context: octopus_context): integer; external 'octopus.dll';

procedure TForm1.Button1Click(Sender: TObject);
var
erg : integer;
desc1, desc2 : Pchar;
begin
erg := octopus_init(oc1);
desc1 := octopus_get_hwdesc(oc1,desc2);
form1.Caption := inttostr(erg);

end;


end.
  Mit Zitat antworten Zitat
multi-man

Registriert seit: 9. Jul 2008
16 Beiträge
 
Delphi 7 Professional
 
#9

Re: DLL einbinden octopus.dll

  Alt 23. Jul 2008, 21:27
Zitat von omata:
eventuell sind das alles Zeiger...
Delphi-Quellcode:
type
  usb_device_handle = record
  end;

  Pusb_device_handle = ^usb_device_handle;

  octopus_context = record
    usb_handle : Pusb_device_handle;
    error_str : pchar;
  end;
  Poctopus_context = ^octopus_context;
function octopus_init(context: Poctopus_context): integer; stdcall; external 'octopus.dll';
Delphi-Quellcode:
var context:Poctopus_context;
begin
  new(context);
  if octopus_init(context) <> 0 then
  begin
  end;
end;
Habe ich probiert, aber leider will es so auch nicht, er bekommt zwar ne 1 zurück, aber anschliessend kommt gleich wieder ne exception... Hab mal geschaut, also der wert von context ist vor dem Aufruf der DLL natürlich irgendein Wert, wenn die DLL-Funktion aber vorbei ist, dann ist context NIL ...
  Mit Zitat antworten Zitat
omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#10

Re: DLL einbinden octopus.dll

  Alt 24. Jul 2008, 02:07
Versuch es mal so...
Delphi-Quellcode:
type
  octopus_context = packed record
    usb_handle : integer;
    error_str : pchar;
  end;
  Poctopus_context = ^octopus_context;

function octopus_init(context: Poctopus_context): integer; stdcall; external 'octopus.dll';
function octopus_open(context: Poctopus_context): integer; stdcall; external 'octopus.dll';
Aufruf...
Delphi-Quellcode:
var context:Poctopus_context;
begin
  new(context);
  try
    if octopus_init(context) = 0 then
      raise Exception.Create(context.error_str);

    if octopus_open(context) < 0 then
      raise Exception.Create(context.error_str);

  finally
    dispose(context);
  end;
end;
Das Init läuft durch, beim Open erhalte ich die folgende Meldung: "could not found octopus device with pid and vid". Diese Meldung ist ja schonmal vielversprechend, ich habe ja auch kein Gerät. Aber es kommt eben auch keine Access Violation mehr.
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 4  1 23     Letzte »    


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:03 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz