Can Bus über PCMCIA Karte und dll ansprechen

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
HarryPython
User
Beiträge: 60
Registriert: Freitag 8. Juni 2007, 07:39

Hi @ all

Ich möchte über eine PCMCIA Karte auf den Can Bus gucken. Die Firma liefert zu der Karte auch eine Bibliothek mit. Natürlich ist das alles in C geschrieben. Hier gibts eine von vielen Anleitungen.

Was ich bisher geschafft hab:

Code: Alles auswählen

import ctypes
from ctypes import*

CanCard_id=c_int(15)         #Diese Werte kommen aus einer mit 
gChannel=c_int(0)            #gelieferten .h Datei wobei 15 für den
PermissionMask=c_int(0)      #Kartentyp steht

      
candll = ctypes.windll.LoadLibrary("vcand32.dll")    #die dll wird geladen
candll.ncdOpenDriver()                                     


gChannelMask = candll.ncdGetChannelMask(CanCard_id,c_int(0),gChannel)              


vErr = candll.ncdOpenPort(gPortHandle,"CanBus",gChannelMask,gChannelMask,PermissionMask,128);
Also bis gChannel kommt keine Fehlermeldung. gChannel liefert eine 1 zurück was auch richtig ist. Nur OpenPort macht mir nun schon seit 2 Tagen Kopfschmerzen :cry:

Die Anleitung der Firma selbst sagt:

2.2.7 ncdOpenPort
Syntax :
  • Vstatus ncdOpenPort (
    VportHandle *portHandle,
    char *userName,
    Vaccess accessMask,
    Vaccess initMask,
    Vaccess *permissionMask,
    int rxQueueSize)
Parameters :
Name
  • Description
portHandle
  • Pointer to a variable where the port handle isreturned. This handle must be used for any further calls to the port. If -1 is returned, the port was neither created nor opened.
userName
  • The name of the application which uses the port must be unique on each call.
accessMask
  • Mask specifying which channels shall be used with this port.
initMask
  • Mask specifying the channels for which the ports wants additional
    access for initialisation (e.g. to set the bit timing). Only
    one port can have init access to a channel.
permissionMask
  • Pointer to a variable where the mask is returned for the channel
    for which init access is granted.
rxQueueSize
  • Size of the port’s receive queue allocated by the driver. Specifies how many events can be stored in the queue. The value
    should be a power of 2. If not, the value is rounded up to the
    next power of 2. (max. queue size is 32k)
...

Example:
// select CANcardX channel 1
gChannelMask = ncdGetChannelMask(HWTYPE_CANCARDX,-1,0);
if(!gChannelMask) return VERR_HW_NOT_PRESENT;
// try to get init access to all channels
gInitMask = gChannelMask;
vErr = ncdOpenPort(&gPortHandle,„CANDEMO„,gChannelMask,gInitMask,
&gPermissionMask,1024);
Das Problem ist gPortHandle. Wie in der Beschreibung steht soll das ein Pointer sein. Aber wenn ich das Richtig verstehe ist das irgendein Pointer oder soll auf die Header Datei zugegriffen werden? Muss ich die einbinden? Soll ich die Header Datei auch posten?
Glaub was Pointer angeht ich hab aber schon alles Versucht.
Aber am heufigsten kommt:
WindowsError: exception: access violation writing 0x00000000
oder
TypeError: int expected instead of LP_c_long instance

Puhh. Glaub das ist jetzt mal nicht so einfach. Hoffe mir kann jemand Helfen. Wie würdet ihr das mit der Anleitung machen? Danke!
HarryPython
User
Beiträge: 60
Registriert: Freitag 8. Juni 2007, 07:39

lol

Als ich das abgeschickt hab, ist mir beim erneuten durchlesen aufgefallen, das PermissionMask auch ein Pointer sein soll. omg. :shock: Was soll ich sagen. Mit:

Code: Alles auswählen


a=c_int()
b=c_int()

vErr = candll.ncdOpenPort(byref(a),"",gChannelMask,gChannelMask,byref(b),128);


hab ich auch mal eine schwere Frage in diesem Forum beantwortet. Immerhin hat der Depp ca. 12 Stunden mit dem Problem verbracht. :? :lol: :roll: :x :( AAHHHHHHH
Ich glaub ich dreh durch.

Danke das es das Forum gibt
Antworten