K8000: test digital input/output

Soyez le premier à donner votre avis sur cette source.

Snippet vu 6 415 fois - Téléchargée 15 fois

Contenu du snippet

Source pour la carte K8000 (interface PC) de Velleman , permet d'exploiter les entrées sorties digitales de la carte, cette source est un petit exemple destiné à aider les débutants.

Source / Exemple :


Public Class Form1
    Inherits System.Windows.Forms.Form
    'IO CONFIGURATION PROCEDURES
    Private Declare Sub ConfigAllIOasInput Lib "k8d.dll" ()
    Private Declare Sub ConfigAllIOasOutput Lib "k8d.dll" ()
    Private Declare Sub ConfigIOchipAsInput Lib "k8d.dll" (ByVal Chip_no As Integer)
    Private Declare Sub ConfigIOchipAsOutput Lib "k8d.dll" (ByVal Chip_no As Integer)
    Private Declare Sub ConfigIOchannelAsInput Lib "k8d.dll" (ByVal Channel_no As Integer)
    Private Declare Sub ConfigIOchannelAsOutput Lib "k8d.dll" (ByVal Channel_no As Integer)

    'OUTPUT PROCEDURES
    Private Declare Sub IOoutput Lib "k8d.dll" (ByVal Chip_no As Integer, ByVal Data As Integer)
    Private Declare Sub UpdateAllIO Lib "k8d.dll" ()
    Private Declare Sub ClearAllIO Lib "k8d.dll" ()
    Private Declare Sub SetAllIO Lib "k8d.dll" ()
    Private Declare Sub UpdateIOchip Lib "k8d.dll" (ByVal Chip_no As Integer)
    Private Declare Sub ClearIOchip Lib "k8d.dll" (ByVal Chip_no As Integer)
    Private Declare Sub SetIOchip Lib "k8d.dll" (ByVal Chip_no As Integer)
    Private Declare Sub SetIOchannel Lib "k8d.dll" (ByVal Channel_no As Integer)
    Private Declare Sub ClearIOchannel Lib "k8d.dll" (ByVal Channel_no As Integer)

    'INPUT FUNCTIONS AND PROCEDURES
    Private Declare Function ReadIOchip Lib "k8d.dll" (ByVal Chip_no As Integer) As Integer
    Private Declare Function ReadIOchannel Lib "k8d.dll" (ByVal Channel_no As Integer) As Boolean
    Private Declare Sub ReadIOconficArray Lib "k8d.dll" (ByVal Array_Pointer As Integer)
    Private Declare Sub ReadIOdataArray Lib "k8d.dll" (ByVal Array_Pointer As Integer)
    Private Declare Sub ReadDACarray Lib "k8d.dll" (ByVal Array_Pointer As Integer)
    Private Declare Sub ReadDAarray Lib "k8d.dll" (ByVal Array_Pointer As Integer)
    'How to use these calls:
    ' ReadIOconficArray IOconfig(0)
    ' ReadIOdataArray IOdata(0)
    ' ReadDACarray DAC(1)
    ' ReadDAarray DA(1)

    '6 BIT DAC CONVERTER PROCEDURES
    Private Declare Sub OutputDACchannel Lib "k8d.dll" (ByVal Channel_no As Integer, ByVal Data As Integer)
    Private Declare Sub ClearDACchannel Lib "k8d.dll" (ByVal Channel_no As Integer)
    Private Declare Sub SetDACchannel Lib "k8d.dll" (ByVal Channel_no As Integer)
    Private Declare Sub ClearDACchip Lib "k8d.dll" (ByVal Chip_no As Integer)
    Private Declare Sub SetDACchip Lib "k8d.dll" (ByVal Chip_no As Integer)
    Private Declare Sub ClearAllDAC Lib "k8d.dll" ()
    Private Declare Sub SetAllDAC Lib "k8d.dll" ()

    '8 BIT DA CONVERTER PROCEDURES
    Private Declare Sub OutputDAchannel Lib "k8d.dll" (ByVal Channel_no As Integer, ByVal Data As Integer)
    Private Declare Sub ClearDAchannel Lib "k8d.dll" (ByVal Channel_no As Integer)
    Private Declare Sub SetDAchannel Lib "k8d.dll" (ByVal Channel_no As Integer)
    Private Declare Sub ClearAllDA Lib "k8d.dll" ()
    Private Declare Sub SetAllDA Lib "k8d.dll" ()

    '8 BIT AD CONVERTER FUNCTION
    Private Declare Function ReadADchannel Lib "k8d.dll" (ByVal Channel_no As Integer) As Integer

    'GENERAL PROCEDURES
    Private Declare Sub SelectI2CprinterPort Lib "k8d.dll" (ByVal port As Integer)
    Private Declare Sub Start_K8000 Lib "k8d.dll" ()
    Private Declare Sub Stop_K8000 Lib "k8d.dll" ()

    'COMMON USED GLOBALS
    Const MaxIOcard As Integer = 3
    Const MaxIOchip As Integer = 7
    Const MaxDACchannel As Integer = 32
    Const MaxDAchannel As Integer = 4

    'Declare variables
    Dim IOconfig(MaxIOchip) As Integer
    Dim IOdata(MaxIOchip) As Integer
    Dim DAC(MaxDACchannel) As Integer
    Dim DA(MaxDAchannel) As Integer

    Dim o_test As Boolean
    Dim dac_out(9) As Boolean
    Dim card_nr, n As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '-------------------------------------------------------------------------------------------------
        'demarage k8000

        card_nr = 0
        n = 1
        o_test = False
        Start_K8000()
        SelectI2CprinterPort(1)
        ConfigAllIOasOutput()

        '-------------------------------------------------------------------------------------------------

        Timer1.Interval = 500
        Timer1.Start()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'active la sortie digitale 1
        SetIOchannel(1)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'désactive la sortie digitale 1
        ClearIOchannel(1)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'active toutes les entrées/sorties digitales
        SetAllIO()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        'désactive toutes les entrées/sorties digitales
        ClearAllIO()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        'active la sortie digitale 20
        'j'ai additionné 2 cartes k8000 et sur chaque carte j'ai defini 10 sortie digitales
        'et 6 entrées digitales: de OI 1 à 10 des sorties et de OI 11 à 16 des entrées
        'le pc ne voit qu'une seule carte avec 20 sorties et 12 entrées digitales
        'donc ma sortie 20 est enfait la IO 26 de mes 2 cartes
        SetIOchannel(26)
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        'désactive la sortie digitale 20
        ClearIOchannel(26)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'lit et affiche l'etat des entrées digitales 1 et 12
        ReadIOchannel(11)
        If ReadIOchannel(11) = True Then
            CheckBox1.Checked = True
        Else : CheckBox1.Checked = False
        End If

        ReadIOchannel(32)
        If ReadIOchannel(32) = True Then
            CheckBox2.Checked = True
        Else : CheckBox2.Checked = False
        End If

    End Sub
End Class

Conclusion :


Pour les débutants qui bataillent avec leurs carte interface PC , je travail sur un petit site qui regroupe des exemples d'applications, des schémas et des sources pour K8000 et K8061:

http://sites.google.com/site/brikop/

A voir également

Ajouter un commentaire

Commentaire

Messages postés
1172
Date d'inscription
jeudi 24 mai 2007
Statut
Membre
Dernière intervention
28 septembre 2013
1
tiens vous ici ^^, merci pour la source dés que j'en une (carte) je la regarde pour allez plus vite !
@+

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.