Sie befinden sich hier: Lego® - K8055 USB Interface- Board - VB und VBA

K8055 USB Interface- Board mit Visual Basic (Version 2008) und Visual Basic for Applications (Office 2007):

Ansteuerung:

  • Download k8055_source_code.zip von Hersteller Seite (http://www.velleman.eu)
  • Datei K8055D.dll aus dem Verzeichnis VB in das Verzeichnis c:/windows/system32 kopieren
  • Folgendes an den Anfang vom VB- Programm einfügen:
Public Class Form1
Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib "k8055d.dll" ()
Private Declare Function ReadAnalogChannel Lib "k8055d.dll" (ByVal Channel As Long) As Long)
Private Declare Sub ReadAllAnalog Lib "k8055d.dll" (ByVal Data1 As Long, ByVal 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 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 ReadCounter Lib "k8055d.dll" (ByVal CounterNr As Long) As Long
Private Declare Sub ResetCounter Lib "k8055d.dll" (ByVal CounterNr As Long)
Private Declare Sub SetCounterDebounceTime Lib "k8055d.dll" (ByVal CounterNr As Long, ByVal DebounceTime As Long)
  • In der Benutzeranleitung von der Herstellerseite gibt es Informationen über Befehle zum Ansprechen der Karte.
    z.B.: OpenDevice(Card Address) Öffnet den Kommunikationslink zu dem K8055 Gerät
    Die Card Address ist davon abhängig wie der Jumper auf dem K8055 Board gesteckt wurde. Auf dem Bild ist der Befehl OpenDevice(2) um die Karte anzusprechen. (SK5=Jumper; SK6=keinen Jumper)Card Address










    Dann kann die Karte z.B. mit SetDigitalChannel(Channel) = Stellt den Ausgangskanal ein angesprochen werden. Der Befehl z.B. SetDigitalChannel(1) täte auf dem Board den Digitalen Ausgang 1 setzen. --> LED mit der Bezeichnung LD1 auf dem Board würde leuchten.
    ClearDigitalChannel(Channel) = Löscht den Ausgangskanal würde z.B. bei ClearDigitalChannel(1) den Digitalen Ausgang 1 deaktivieren. --> LED mit der Bezeichnung LD1 auf dem Board würde aus gehen.
    CloseDevice() = Schließt den Link zum K8055 Gerät sollte an jedem Programm Ende stehen.

Beispielprogramm:

  • Digitaler Ausgang 1 ist gesetzt bis Digitaler Eingang 1 (z.B. Taster Inp1 auf Karte) betätigt wird:


























VB- Programm zu Beispielprogramm:


Public Class Form1
 'externe k8055.dll einbinden
 Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Long) As Long
 Private Declare Sub CloseDevice Lib "k8055d.dll" ()
 Private Declare Function ReadAnalogChannel Lib "k8055d.dll" (ByVal Channel As Long) As Long
 Private Declare Sub ReadAllAnalog Lib "k8055d.dll" (ByVal Data1 As Long, ByVal 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 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 ReadCounter Lib "k8055d.dll" (ByVal CounterNr As Long) As Long
 Private Declare Sub ResetCounter Lib "k8055d.dll" (ByVal CounterNr As Long)
 Private Declare Sub SetCounterDebounceTime Lib "k8055d.dll" (ByVal CounterNr As Long, ByVal DebounceTime As Long)

 'Private Sub wird ausgeführt, wenn Button1 betätigt wurde
 Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click

  'Variable deklarieren
  Dim Eingang1 As Integer

  'Karte ansprechen
  OpenDevice(2)
 
  'Wert Digital Channel 1 wird Variable Eingang1 zugewiesen 
  Eingang1 = ReadDigitalChannel(1)

  'LED1 leuchtet so lange bis Taster Inp1 betätigt wird.
  Do While Eingang1 = 0
    SetDigitalChannel(1)
    Eingang1 = ReadDigitalChannel(1)
  Loop

  'deaktiviert Digitalen Ausgang 1
  ClearDigitalChannel(1) 

  'schließt den Link zum K8055 Gerät
  CloseDevice()

 End Sub
End Class

VBA- Programm zu Beispielprogramm:


'externe k8055.dll einbinden
Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib "k8055d.dll" ()
Private Declare Function ReadAnalogChannel Lib "k8055d.dll" (ByVal Channel As Long) As Long
Private Declare Sub ReadAllAnalog Lib "k8055d.dll" (ByVal Data1 As Long, ByVal 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 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 ReadCounter Lib "k8055d.dll" (ByVal CounterNr As Long) As Long
Private Declare Sub ResetCounter Lib "k8055d.dll" (ByVal CounterNr As Long)
Private Declare Sub SetCounterDebounceTime Lib "k8055d.dll" (ByVal CounterNr As Long, ByVal DebounceTime As Long)
    
Sub cmdStart()

  'Variable deklarieren
   Dim Eingang1 As Integer

   'Karte ansprechen
    OpenDevice (2)

    'Wert Digital Channel 1 wird Variable Eingang1 zugewiesen
     Eingang1 = ReadDigitalChannel(1)

    'LED1 leuchtet so lange bis Taster Inp1 betätigt wird.
     Do While Eingang1 = 0
        SetDigitalChannel (1)
        Eingang1 = ReadDigitalChannel(1)
     Loop

    'deaktiviert Digitalen Ausgang 1
     ClearDigitalChannel (1)

End Sub   

Lego mit

  K8055

Modelle
- Steinsortierer

allgemein
- Ansteuerung

Programmieren - VB u. VBA
- LabVIEW
- K8055 & NXT