Trying to test my K8055

Hello,

Can somebody tell me what i do wrong in this script ?

________________________________________________________-

Private Declare Sub ReadAll Lib “k8055d.dll” (ByVal data As Long)
Private Declare Function Version Lib “k8055d.dll” () As Long
Private Declare Function SearchDevices Lib “k8055d.dll” () As Long
Private Declare Function SetCurrentDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
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 Connect_Click()
Dim CardAddress As Long
Dim h As Long
CardAddress = 0
CardAdress = 3 - (Check1(0).Value + Check1(1).Value * 2)
h = OpenDevice(0)
Select Case h
Case 0, 1, 2, 3
Label1.Caption = “Card” + Str(h) + “Connected”
Case -1
Label1.Caption = “Card” + Str(0) + “not found”
End Select

End Sub

Private Sub CommandButton2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

SetAllDigital (0)

End Sub
Private Sub Form_Terminate()
CloseDevice
End Sub

I wil check all digital outputs ( LED on/off ) and test with these buttons:

open , connect all digital outputs

can somebody help me about this problem ?

Thank you for read this post.

Please change:

SetAllDigital (0)to

SetAllDigital

[quote=“VEL255”]Please change:

SetAllDigital (0)to

SetAllDigital

Hello Thank you for quick reply,

I have change it but it still not work.
I will make it in a Excel program, when i push the button " Set All Digital " that all Digital outputs are active .( LEDS on )

Have i also make a button to connect the K8055 ?

Thanks for read this post

[quote]Have i also make a button to connect the K8055 ?[/quote]Yes, you have to make it.

Please download the latest software package for the K8055.
Here is the link to download page:
velleman.eu/distributor/supp … code=K8055
Download the: “Complete SDK Pack (Rev 4.0)”.

The package includes new K8055D.DLL and sample projects written in various programming languages. - Visual basic and Excel examples are included.
Pleas read the “README.TXT” and the “K8055 & VM110 Getting Started.pdf”.

Thank’s for this information,

It works now !!

I have otherwise one question, is it possible to make a .exe file in Excel ??

Thank’s for quick reply

Patrick

[quote]I have otherwise one question, is it possible to make a .exe file in Excel ??[/quote]This is not possible.

There seems to be an utility to convert Excel files from original XL format to EXE format.
See: orlando.mvps.org/XLtoEXEMore.asp

Anyhow, it is not possible to convert Excel workbook to a “real” standalone exe file.

O.K Thank’s for your information, no problem,
It works also fine only as XLS file :smiley:

Now i have working my project , to open de Digital outputs !!

Maby you can help me to make a script for , when i open a doorcontact i can read it out in a text label ??
These are the digital inputs ??

Is this possible whit excel / Visual Basic.

Thank’s for read this post

I’m not sure if this is what you meant.
Here is a script showing the text “Contact Closed” if digital input 1 is connected to the GND.
If this input is open, the displayed text is “Contact Open”.
You can test this by pressing the button Inp1 on the K8055 card.
You have to put on the Excel workbook two buttons (connect and close) and assign them to the macros: Button1_Click() and to Button2_Click().

When connected, the status of the digital input 1 is checked every 100ms using a timer.

[code]Option Explicit
Private Declare Function OpenDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib “k8055d.dll” ()
Private Declare Function ReadDigitalChannel Lib “k8055d.dll” (ByVal Channel As Long) As Boolean

Private Declare Function SetTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long
Dim TimerID As Long
Dim TimerSeconds As Single

Sub Button1_Click()
Dim h As Long
h = OpenDevice(0)
If h = 0 Then
ActiveSheet.Cells(1, 4) = “Card 0 Connected”
TimerSeconds = 0.1 ’ the timer interval is now 0.1 sec.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
Else
ActiveSheet.Cells(1, 4) = “Card 0 Not Found”
End If
End Sub

Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long)
On Error Resume Next
Dim b As Boolean
b = ReadDigitalChannel(1)
If b Then
ActiveSheet.Cells(1, 1) = “Contact Closed”
Else
ActiveSheet.Cells(1, 1) = “Contact Open”
End If
End Sub

Sub Button2_Click()
KillTimer 0&, TimerID
CloseDevice
ActiveSheet.Cells(1, 4) = “Card 0 Closed”
End Sub[/code]

Thank’s for reply,

I mean like this:


Door = Open
Door = Closed
Window = Open
Window = Closed

And this text in a Privat Sub Label.
is that posible ??

Thank’s for read this post

[quote]And this text in a Privat Sub Label.
is that posible ??[/quote]I think this is not possible in Excel.
Maybe possible in other programming languages…

O.K thank’s for Quick Reply, I will look futher.

Thank’s any way for your input

catch you later !!!

If this is what you want to be displayed…

In Visual Basic:
Add to the declarations section:

Dim old_sw1 As Boolean Dim old_sw2 As Boolean
Use this timer procedure:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim sw1 As Boolean Dim sw2 As Boolean Timer1.Enabled = False sw1 = ReadDigitalChannel(1) sw2 = ReadDigitalChannel(2) If sw1 <> old_sw1 Then If sw1 Then MsgBox("Door = Closed", vbExclamation, "Door") Else MsgBox("Door = Open", vbExclamation, "Door") End If End If If sw2 <> old_sw2 Then If sw2 Then MsgBox("Window = Closed", vbExclamation, "Window ") Else MsgBox("Window = Open", vbExclamation, "Window ") End If End If old_sw1 = sw1 old_sw2 = sw2 Timer1.Enabled = True End Sub

You can use the demo program in the latest software package and replace the timer function with this one.

Here is the link to the download page to download the latest version with examples:
velleman.eu/distributor/supp … 8055&type=

Please read the README.TXT

Hello,

Thank’s for this script,
I can use it also for my experiment !!!

this is for now on perfect.

:stuck_out_tongue:

Hello,

Maby you know a script by meaning like this.

Thank’s for read this post

You can use the Visual Basic function Time or Time$ to print the time.
Here an example screenshot:

This is the script to print the time:

[code]Option Explicit
Private Declare Function OpenDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib “k8055d.dll” ()
Private Declare Function ReadDigitalChannel Lib “k8055d.dll” (ByVal Channel As Long) As Boolean

Private Declare Function SetTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long
Dim TimerID As Long
Dim TimerSeconds As Single
Dim old_sw1 As Boolean
Dim n As Long

Sub Button1_Click()
Dim h As Long
n = 0
Columns(“A:A”).Select
Selection.ClearContents
Range(“B1”).Select
h = OpenDevice(0)
If h = 0 Then
ActiveSheet.Cells(1, 3) = “Card 0 Connected”
TimerSeconds = 0.1 ’ the timer interval is now 0.1 sec.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
Else
ActiveSheet.Cells(1, 3) = “Card 0 Not Found”
End If
End Sub

Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long)
On Error Resume Next
Dim sw1 As Boolean
Dim s As String
sw1 = ReadDigitalChannel(1)
If sw1 <> old_sw1 Then
s = Time$
n = n + 1
If sw1 Then
ActiveSheet.Cells(n, 1) = "Door = Open Time: " + s
Else
ActiveSheet.Cells(n, 1) = "Door = Closed Time: " + s
End If
End If
old_sw1 = sw1
End Sub

Sub Button2_Click()
KillTimer 0&, TimerID
CloseDevice
ActiveSheet.Cells(1, 3) = “Card 0 Closed”
End Sub[/code]
Follow this link to find more about the Visual Basic Time and Date functions:
http://msdn.microsoft.com/en-us/library/62dhtt92(v=VS.80).aspx

Here is another useful link for Visual Basic 2008/2010 etc.
msdn.microsoft.com/en-us/library/c157t28f.aspx
Please see the links in the section: “Microsoft.VisualBasic.DateAndTime Module”

Hello,

Thank’s for these link, and other information,
with this information , i can make my experiment complete.
It is for a technical room to check how many times the door opens and close at a day.

:smiley: