Pb utilisation ReadBackAnalogOut pour la k8061

Bonjour je cherche à utiliser la commande : Private Declare Sub ReadBackAnalogOut Lib “k8061.dll” (ByVal CardAddress As Long, Buffer As
Long) mais je n’y arrive pas :frowning:

le code en vb.net que j’utilise est le suivant :

Dim lngAnalogOut(8) As Long

ReadBackAnalogOut(0, lngAnalogOut)

j’ai l’erreur suivante : Error 1 Value of type ‘1-dimensional array of Long’ cannot be converted to ‘Long’.

je souhaite par exemple recuperer la valeur de la sortie analogique 2 de la carte 0 avec cette commande,
si quelqu’un peut m’indiquer comment utiliser correctement cette commande ca serait super génial merci :smiley:

Are you using Visual Basic 6 ?
If yes, you should write:

ReadBackAnalogOut 0, lngAnalogOut(0)

merci pour votre rapidité !!

non j’utilise pas vb 6 mais vb.net (visual studio 2010)

For VB .NET you have to declare the DLL functions like this:

[code] Private Declare Function OpenDevice Lib “k8061.dll” () As Integer
Private Declare Sub CloseDevices Lib “k8061.dll” ()
Private Declare Function PowerGood Lib “k8061.dll” (ByVal CardAddress As Integer) As Boolean
Private Declare Function Connected Lib “k8061.dll” (ByVal CardAddress As Integer) As Boolean
Private Declare Function ReadAnalogChannel Lib “k8061.dll” (ByVal CardAddress As Integer, ByVal Channel As Integer) As Integer
Private Declare Sub ReadAllAnalog Lib “k8061.dll” (ByVal CardAddress As Integer, ByRef Buffer As Integer)

Private Declare Sub ReadCounters Lib "k8061.dll" (ByVal CardAddress As Integer, ByRef Buffer As Integer)
Private Declare Sub ResetCounters Lib "k8061.dll" (ByVal CardAddress As Integer)

Private Declare Sub OutputAnalogChannel Lib "k8061.dll" (ByVal CardAddress As Integer, ByVal Channel As Integer, ByVal Data As Integer)
Private Declare Sub OutputAllAnalog Lib "k8061.dll" (ByVal CardAddress As Integer, ByRef Buffer As Integer)
Private Declare Sub ClearAnalogChannel Lib "k8061.dll" (ByVal CardAddress As Integer, ByVal Channel As Integer)
Private Declare Sub SetAllAnalog Lib "k8061.dll" (ByVal CardAddress As Integer)
Private Declare Sub ClearAllAnalog Lib "k8061.dll" (ByVal CardAddress As Integer)
Private Declare Sub SetAnalogChannel Lib "k8061.dll" (ByVal CardAddress As Integer, ByVal Channel As Integer)
Private Declare Sub OutputAllDigital Lib "k8061.dll" (ByVal CardAddress As Integer, ByVal Data As Integer)
Private Declare Sub ClearDigitalChannel Lib "k8061.dll" (ByVal CardAddress As Integer, ByVal Channel As Integer)
Private Declare Sub ClearAllDigital Lib "k8061.dll" (ByVal CardAddress As Integer)
Private Declare Sub SetDigitalChannel Lib "k8061.dll" (ByVal CardAddress As Integer, ByVal Channel As Integer)
Private Declare Sub SetAllDigital Lib "k8061.dll" (ByVal CardAddress As Integer)
Private Declare Function ReadDigitalChannel Lib "k8061.dll" (ByVal CardAddress As Integer, ByVal Channel As Integer) As Boolean
Private Declare Function ReadAllDigital Lib "k8061.dll" (ByVal CardAddress As Integer) As Integer
Private Declare Sub OutputPWM Lib "k8061.dll" (ByVal CardAddress As Integer, ByVal Data As Integer)
Private Declare Function ReadBackDigitalOut Lib "k8061.dll" (ByVal CardAddress As Integer) As Integer
Private Declare Sub ReadBackAnalogOut Lib "k8061.dll" (ByVal CardAddress As Integer, ByRef Buffer As Integer)
Private Declare Function ReadBackPWMOut Lib "k8061.dll" (ByVal CardAddress As Integer) As Integer[/code]

And use the function like this:

ReadBackAnalogOut(0, lngAnalogOut(0))

avec ceci ReadBackAnalogOut(0, lngAnalogOut(0)) j’ai l’erreure suivante :

System.AccessViolationException was unhandled
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Please check the function declaration. Should be: … [color=#FF0000]ByRef [/color]Buffer As Integer

Private Declare Sub ReadBackAnalogOut Lib "k8061.dll" (ByVal CardAddress As Integer, ByRef Buffer As Integer)

j’ai bien modifier en Private Declare Sub ReadBackAnalogOut Lib “k8061.dll” (ByVal CardAddress As Long, ByRef Buffer As Integer)

mais j’ai toujours la même erreur :frowning:

Also declare: … ByVal CardAddress As [color=#BF0000]Integer[/color]

you had “As Long”.

Here is a link to the updated Visual Basic 2008 Express project:
box.net/shared/5n393f1ifs

The following functions and one button “Read Back Output” added:

Private Declare Function ReadBackDigitalOut Lib "k8061.dll" (ByVal CardAddress As Integer) As Integer Private Declare Sub ReadBackAnalogOut Lib "k8061.dll" (ByVal CardAddress As Integer, ByRef Buffer As Integer) Private Declare Function ReadBackPWMOut Lib "k8061.dll" (ByVal CardAddress As Integer) As Integer

Here is a link to the document: box.net/shared/kbuyr1zv3r

merci je n’avais pas vue pour la CardAddress maintenant je n’ai plus l’erreur :smiley: , pardonnez moi d’abuser encore un peu comment traiter cette commande pour avoir par exemple la valeur de la sortie analogique 1 de la carte 0 dans un label.text

merci encore pour tout

OK. No problem. It’s nice that you got it working. :slight_smile:

Merci pour l’exemple ci-dessus ça fonctionne impeccable maintenant :smiley: :smiley: et encore merci pour votre efficacité et rapidité !!!