Velleman k8055 programme pour comprendre et utiliser le code (a tester avec la carte) (vb6)

Description

Ce programme permet de mieux comprendre les routines utilisées pour le K8055.

-Initialisation de l'interface
-Essais entrées analogiques et digitales
(les entrées sont lues à intervalles régulières définies par le Timer1
-Essais sorties analogiques et digitales
(les sorties sont activées/désactivées par la coche (pour l'exemple)
-Déconnection de l'interface

Source / Exemple :


Option Explicit
Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib "k8055d.dll" ()
Private Declare Sub WriteAllDigital Lib "k8055d.dll" (ByVal Data As Long)
Private Declare Sub ClearDigitalChannel Lib "k8055d.dll" (ByVal Channel As Long)
Private Declare Sub ClearAllDigital Lib "k8055d.dll" ()
Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Long)
Private Declare Sub SetAllDigital Lib "k8055d.dll" ()
Private Declare Function ReadDigitalChannel Lib "k8055d.dll" (ByVal Channel As Long) As Boolean
Private Declare Function ReadAllDigital Lib "k8055d.dll" () As Long
Private Declare Function ReadAnalogChannel Lib "k8055d.dll" (ByVal Channel As Long) As Long
Private Declare Sub ReadAllAnalog Lib "k8055d.dll" (Data1 As Long, Data2 As Long)
Private Declare Sub OutputAnalogChannel Lib "k8055d.dll" (ByVal Channel As Long, ByVal Data As Long)
Private Declare Sub OutputAllAnalog Lib "k8055d.dll" (ByVal Data1 As Long, ByVal Data2 As Long)
Private Declare Sub ClearAnalogChannel Lib "k8055d.dll" (ByVal Channel As Long)
Private Declare Sub SetAllAnalog Lib "k8055d.dll" ()
Private Declare Sub ClearAllAnalog Lib "k8055d.dll" ()
Private Declare Sub SetAnalogChannel Lib "k8055d.dll" (ByVal Channel As Long)

Private Sub Command1_Click()
ClearAllDigital
Check3.Value = 0
Check4.Value = 0
Check5.Value = 0
Check6.Value = 0
Check7.Value = 0
Check8.Value = 0
Check9.Value = 0
Check10.Value = 0

End Sub

Private Sub Check10_Click()
If Check10.Value = 1 Then SetDigitalChannel (8) Else ClearDigitalChannel (8)
End Sub

Private Sub Check3_Click()
If Check3.Value = 1 Then SetDigitalChannel (1) Else ClearDigitalChannel (1)
'si check3 est cochée alors activer sortie (1) sinon désactiver sortie (1)
End Sub

Private Sub Check4_Click()
If Check4.Value = 1 Then SetDigitalChannel (2) Else ClearDigitalChannel (2)
End Sub

Private Sub Check5_Click()
If Check5.Value = 1 Then SetDigitalChannel (3) Else ClearDigitalChannel (3)

End Sub

Private Sub Check6_Click()
If Check6.Value = 1 Then SetDigitalChannel (4) Else ClearDigitalChannel (4)
End Sub

Private Sub Check7_Click()
If Check7.Value = 1 Then SetDigitalChannel (5) Else ClearDigitalChannel (5)
End Sub

Private Sub Check8_Click()
If Check8.Value = 1 Then SetDigitalChannel (6) Else ClearDigitalChannel (6)
End Sub

Private Sub Check9_Click()
If Check9.Value = 1 Then SetDigitalChannel (7) Else ClearDigitalChannel (7)
End Sub

Private Sub Connect_Click()
Dim CardAddress As Long
Dim h As Long
CardAddress = 0
CardAddress = 3 - (SK5.Value + SK6.Value * 2)
h = OpenDevice(CardAddress)
Select Case h
  Case 0, 1, 2, 3
  Label1.Caption = "card" + Str(h) + " connected"
  Case -1
  Label1.Caption = "card" + Str(CardAddress) + " no found"
End Select

End Sub

Private Sub Form_Unload(Cancel As Integer)
CloseDevice
End Sub

Private Sub HScroll1_Scroll()
OutputAnalogChannel 2, HScroll1.Value
End Sub

Private Sub Timer1_Timer()
 Timer1.Enabled = False
    Dim i As Long
    Dim Data1 As Long
    Dim Data2 As Long
    i = ReadAllDigital
    ent1.Value = (i And 1)
    ent2.Value = (i And 2) / 2
    ent3.Value = (i And 4) / 4
    ent4.Value = (i And 8) / 8
    ent5.Value = (i And 16) / 16
    
    ReadAllAnalog Data1, Data2
    
    ProgressBar1.Value = Data1
    Label7.Caption = Data1
    
    ProgressBar2.Value = Data2
    Label8.Caption = Data2
    
    Timer1.Enabled = True
    
End Sub

Private Sub Unconnect_Click()
CloseDevice
Label1.Caption = "Deconnected"
End Sub

Private Sub VScroll1_Scroll()
OutputAnalogChannel 1, VScroll1.Value
End Sub

Conclusion :


N'oubliez pas que vous devez avoir le fichier K8055D.dll dans Windows\System pour que les routines fonctionnent! N'hésitez pas à poser vos questions!

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.