Logo Banner

Velleman K8055 - [Velleman K8055 Class]

Velleman K8055

What is the Velleman K8055 class?

The K8055 is a Visual Basic .NET class to access the card very easily. I wrote it to develop my K8055 testing applications more quickly. The class can be downloaded at the bottom of this website. You can add it to any Visual Basic .NET project.

Why should you use this class?

The libraries provided by Velleman are easy to use. So why would you use my class instead? Because it is even more easy to use! After adding the class to an existing VB.NET project you can access the K8055 with only 3 lines of code.

My class provides a very easy access to the K8055 card. After you add the class to your project, you can start controlling the K8055 in just 3 lines of source code. This code should be added to the main form of a VB.Net project:

    Dim myK8055 As New K8055()
    myK8055.connect(SK5:=True, SK6:=True)
    myK8055.setDigitalOutput(1)
    

The first line creates an instance of the class K8055. It can be accessed through the 'myK8055' variable. Then you can create a connection with the K8055. Each card has its own address which is set by 2 jumpers SK5 and SK6. You need to specify the state of these jumpers. True means the jumper is in place, False means the jumper is open. Finally the third line of the program will set the digital output channel #1.

For larger programs you could move the declaration of the myK8055 to a module level. Then the K8055 becomes accessible from any sub or function. The code below shows you how to do that. The sample assumes you have two buttons on a form: cmdSetChannel and cmdClearChannel.

    Private myK8055 As New K8055()
    		
    Private Sub frmMain_Load(...) Handles MyBase.Load
    	myK8055.connect(SK5:=True, SK6:=True)
    End Sub
    		
    Private Sub cmdSetChannel_Click(...) Handles cmdSetChannel.Click
    	myK8055.setDigitalOutput(1)
    End Sub
    
    Private Sub cmdClearChannel_Click(...) Handles cmdClearChannel.Click
    	myK8055.clearDigitalOutput(1)
    End Sub		
    

Sample: the counter application

Screenshot of the counter application

The power of the K8055 class becomes unleashed when you write a larger application for the card. Assume the following case: you are asked to design a counter application. Initially the counter is set to 0. Each time you push the button INP1 the value is increased with 1. Each push to button INP2 decreases the value with 1.

This means you need to poll your K8055 frequently to determine if a button was pressed. You also need to add code to detect if the user doesn't keep pushing the button. A simple program like this already involves a lot of coding.

My K8055 class allows you to write this program with no more than 15 lines of code.This is possible because the class supports events which are triggered when an input changed.

Counter Application Code

    Public Class frmMain
      Private WithEvents myK8055 As New K8055(enableEvents:=True, interval:=100)
      Private counter As Integer = 0
      			
      Private Sub frmMain_Load(...) Handles MyBase.Load
        Label1.Text = CStr(counter)
        myK8055.connect(SK5:=True, SK6:=True)
      End Sub
      			
      Private Sub myK8055_digitalInputChanged(ByVal channel as Integer, _
      						ByVal Value as boolean) Handles myK8055.digitalInputChanged
        If channel = 1 And Value = True Then counter += 1
        If channel = 2 And Value = True Then counter -= 1		
        Label1.Text = CStr(counter)
      End Sub	
    End Class				
    

Explaining: first an myK8055 object is created. This time it is preceded by the "WithEvents" keyword to allow it to generate events. I also passed some additional parameters to the constructor of the K8055 class: enabledEvents and interval.

This value is the interval at which the K8055 card constantly be polled. The given of 100 causes it to be polled every 100 ms. This value shouldn't be too low as the K8000 can't work that fast. Setting it too high also poses a problem: with an interval of 10 seconds a short press on a button would never be notices.

The Sub myK8055_digitalInputChanged is called when an event is fired. It has 2 parameters: NAME and VALUE. NAME is the number of the channel that caused the event to fire. VALUE is the value that channel had when the event occurred. The code inside the demonstration subroutine just checks if you pressed either INP1 or INP2, then it will increase or decrease the counter and show it in the label1.

Other features of the K8055 Class

It sounds too good. What is the catch?

There indeed is a catch: my class can handle only one K8055 card. You can't control multiple cards with it and you can't create multiple instances of the K8055 class.

What about the original K8055D.DLL ?

Make no mistakes: this class is *NO* replacement for the K8055D.DLL file. The DLL still has to be included with all your programs. You just don't need to call the K8055D.DLL directly as my class does it for you.

Downloads

Here you can download the files for this project: the K8055 counter class (zipped Visual Basic CLASS file), the manual for the class (PDF) and a sample Visual Basic .NET project.

Copyright ©1998-2022 Vanderhaegen Bart - last modified: August 24, 2013