What is the error message are you getting?
Where is the “OpenDevice” function?
[quote=“VEL255”]What is the error message are you getting?
Where is the “OpenDevice” function?[/quote]
Private Sub UserForm_Initialize()
’
Dim i As Integer
For Each Ctrl In UserForm1.Controls
If TypeOf Ctrl Is MSForms.TextBox Then
i = i + 1
’ Controls(“TextBox” & i - 1).Value = Cells(5, i).Value
UserForm1.Controls(“TextBox” & i - 1).Value = Bit
End If
Next Ctrl
StartTimer
End Sub
Erreur provient du StarTimer( dans l’urserform)
Erreur de compilation:
Utilisation incorrect de l’opérateur AdressOf
I don’t know how to get the timer function to update any controls on the UserForm1 – sorry
Bonjour,
La solution était toute simple…
Il faut juste mettre la propriété “ControlSource” d’un TextBox liée à l’entrée digital
(exemple : A1 pour lire l’entrée digital 5)
Nice that you found a solution
Bonjour,
Pour les entrées et sortie analog, la procédure est-elle la même que:
Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)
Dim Byt As Long
Dim Bit As Long
On Error Resume Next
’
’ The procedure is called by Windows. Put your
’ timer-related code here.
’
Byt = ReadAllDigital
WriteAllDigital Byt
ActiveSheet.Cells(3, 1).Value = Byt
For i = 0 To 4
If (Byt And 2 ^ i) Then Bit = 1 Else Bit = 0
ActiveSheet.Cells(4, 5 - i).Value = Bit
Next i
End Sub
You can put the analog I/O functions to this timer procedure as well.
Bonjour,
Comment faire ?? :
dans la procédure :
Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)
Dim Byt As Long
Dim Bit As Long
On Error Resume Next
’
’ The procedure is called by Windows. Put your
’ timer-related code here.
Byt = ReadAllDigital
WriteAllDigital Byt
ActiveSheet.Cells(3, 1).Value = Byt
For i = 0 To 4
If (Byt And 2 ^ i) Then Bit = 1 Else Bit = 0
ActiveSheet.Cells(4, 5 - i).Value = Bit
Next i
End Sub
Quand j’utilise:
SetAnalogChannel(1 ou 2) pour activer les sorties 1 ou 2 à 5v, cela fonctionne bien
mais, activer une sortie avec une tension définie ex:
OutputAnalogChannel(1, 127)
Obtient toujours un message d’erreur ?
merci de ton attention
Change:
OutputAnalogChannel(1, 127)
to:
OutputAnalogChannel 1, 127
then it should work OK.
[quote=“VEL255”]Here is a VBA procedure that reads the digital inputs of the K8055 card and displays the value on Excel sheet. The state is displayed in decimal and in binary form.
Add two buttons ‘Start’ and ‘Stop’ on the sheet. Assign the macros Start_Click and Stop_Click to these buttons.
Type the card address to cell C1 and press Enter before you click the Start button.
The update interval in this example is 1 sec.
Put the K8055D.DLL to Windows’ SYSTEM32 folder.
[code]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
Private Declare Function OpenDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
Private Declare Function ReadAllDigital Lib “k8055d.dll” () As Long
Dim TimerID As Long
Dim TimerSeconds As Single
Dim Connected As Boolean
Sub StartTimer()
TimerSeconds = 1 ’ how often to “pop” the timer.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
End Sub
Sub EndTimer()
On Error Resume Next
KillTimer 0&, TimerID
End Sub
Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)
Dim Byt As Long
Dim Bit As Long
On Error Resume Next
’
’ The procedure is called by Windows. Put your
’ timer-related code here.
’
Byt = ReadAllDigital
ActiveSheet.Cells(3, 1).Value = Byt
For i = 0 To 4
If (Byt And 2 ^ i) Then Bit = 1 Else Bit = 0
ActiveSheet.Cells(4, 5 - i).Value = Bit
Next i
’
End Sub
Sub Start_Click()
Dim CardAddress As Long
Dim h As Long
CardAddress = ActiveSheet.Cells(1, 3).Value
h = OpenDevice(CardAddress)
Select Case h
Case 0, 1, 2, 3
ActiveSheet.Cells(1, 1) = “Card " + Str(h) + " connected”
Case -1
ActiveSheet.Cells(1, 1) = “Card " + Str(CardAddress) + " not found”
End Select
StartTimer
End Sub
Sub Stop_Click()
EndTimer
ActiveSheet.Cells(1, 1) = “Stopped”
End Sub[/code][/quote]
[quote=“PeterCol”]Thanks for the code. Unfortunately it still hangs on the starttimer procedure at “AddressOf TimerProc” with the message " Invalid use of Addressof operator". I can’t resolve this.
Have you managed to run this on Excel 2000 VBA?[/quote]
In case anyone else is trying this sample code and are getting the same error then you need to copy and paste the code into a Module not a worksheet. (Alt+ F11, Right click Project, Insert Module) Then on Sheet1 Add two buttons. From the code in sheet1 you need to call the Start_Click and Stop_Click. EG
Private Sub Start_Button_Click()
Start_Click
End Sub
Private Sub Stop_Button_Click()
Stop_Click
End Sub
Hope this Helps. Took me best part of the Night to sort this out but I’m not really a programer
Thank you Silentmonkey for these instructions how to solve the " Invalid use of Addressof operator" error message and how to assign the macro.
Nice that you got this macro working
Have a look at the IOGateway ActiveX control from www.industrialmightandlogic.com
It supports K8055 and k8061 in a control package that you can just drop on to an excel form or worksheet. There are also examples in excel.
bonjour
si quelqu’un a une idée
comment faire pour garder en memoire l’etat des soties digital
a chaque nouvelle commande tout se desactive
je n’utilise pas d’interface grafique seulement des executable
pour activer les 8 sorties
exemple pour la 1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Visible = False
OpenDevice(0)
SetDigitalChannel(1)
Me.Close()
End Sub
mais quand je passe au deuxieme exe la sortie 1 se desactive
One possible solution to solve this problem is to use a (text) file.
Save the setting of the K8055 digital outputs to a (text) file before closing the .EXE.
Read the file to the second .EXE and set all the digital outputs of the K8055.
the questions here are Exel related not Visual basic…
im trying to find "procedure in the visual basic manuals i have could you bring out a DLL manual for VB?? or do you have one?
Sorry - I’m not sure what manual you are looking for…
Here is the link to download the latest K8055 software package with the new K8055D.DLL:
velleman.eu/downloads/files/ … rsion4.zip
To this package there is included a DLL manual for the K8055.
In the examples folder there is a ready to run Excel VBA demo.
You can also download this package:
[color=#000080]Software DLL Rev 2
older DLL with examples and source code (source can also be used with DLL rev 3)[/color]
Here the link to the download page: velleman.eu/distributor/supp … 8055&type=
The software package includes the DLL manual written is several languages.
Option Explicit On
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)
Private input_pit As New List(Of String)
Dim Channel(8) As String
ReadOnly Tick As Boolean = False
Dim chan As String
Dim minfiv As Integer
Dim n As Integer
Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
If minfiv + n > 60000 Then
minfiv = 0
n = 0
End If
ReadAllDigital() = input_pit.ToArray()
input_pit.Add(ListBox1.Text)
TextBox1.Text = input_pit(0)
TextBox2.Text = input_pit(1)
TextBox3.Text = input_pit(2)
TextBox4.Text = input_pit(3)
TextBox5.Text = input_pit(4)
End Sub
Public Class tim_2
' read n as intager vicks_1 + tunes_1
select case
case Timer2_Tick = True Then
Public Function ADD(ByVal n As Double)
ADD = (minfiv / 10000)
Return (n)
If n >= 10 Then
GetType ReadDigitalChannel () = 4
ListBox2.Text = ReadAllDigital
End Function
End If
'N = 4 ie
case Timer1_Tick = True then
TextBox4.Text = "wait for it"
minfiv = 0
Case n = minfiv then
TextBox3.Text = "30"
Case SetDigitalChannel(1) = False then
TextBox3.Text = "wait"
end select
End Class
Private Sub Timer2_Tick(ByVal Timer2 As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If Timer2 = False Then
SetDigitalChannel(1) = False
ElseIf Timer2 = True Then
SetDigitalChannel(1) = True
End If
End Sub
Declare Function ReadDigitalChannel(ByVal Channel, ByVal Longint) As Boolean
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox5.Text = ReadDigitalChannel()
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
minfiv += 1
End Sub
Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim h As Long
Dim CardAddress As Long
CardAddress = 0
CardAddress = 3 - (CheckBox1.Value + CheckBox2.value * 2)
h = OpenDevice(CardAddress)
Select Case h
Case 0, 1, 2, 3
label2.Text ='Card '+ inttostr(h)+' connected';
Case -1
label1.Text ='Card '+ inttostr(CardAddr)+' not found';
End Select
End Sub
Private Function ReadDigitalChannel() As String
Throw New NotImplementedException
End Function
End Class
novice atempt in progress to make a program to hold a channel hight for a time period…
any help would be cool!!! cheers!!! this has 3 counters for a reason, two are stabalising a 30 second period of output that trigers my 1900’s clock … the other is an input back from the clock to re-check its acuracy… im yet to fugur the <( less than ) > (greater than) equation needed to re-check its performance… i’d need a usb memory board to load the program onto in the future to make the clock run independant of my Pc…
ideas would be cool
i was thinking about geting a PIC program board… or something…
cheers
It seems that you are using new Visual Basic version, maybe 2008 or 2010.
The DLL function declarations you are using are for the Visual Basic 6.
Please see the example in the subfolder \examples[color=#000080]K8055DemoVB_2008[/color]
You may use this code as a starting point for your own program.
Here is the link to download the K8055 software package with examples and with new K8055D.DLL:
velleman.eu/downloads/files/ … rsion4.zip
[quote]make a program to hold a channel hight for a time period[/quote]You may use the timers “in series”:
Press a button to enable the timer #1.
When the timer #1 event occurs, disable this timer.
In the timer procedure set digital channel settings as you like.
Enable timer #2.
When the timer #2 event occurs, disable this timer.
In the timer procedure set digital channel settings as you like.
Enable timer #3… etc.
Brill!!! great help thanks!!! yes im on visual studio 2010 express…
i = ReadAllDigital();
CheckBox4->Checked = (i & 1)>0;
CheckBox5->Checked = (i & 2)>0;
CheckBox6->Checked = (i & 4)>0;
CheckBox7->Checked = (i & >0;
CheckBox8->Checked = (i & 16)>0;
^^^^ translated into visual studio 2010 is what??
Int(ReadAllDigital()
i = ReadAllDigital();
CheckBox4_CheckedChange = (i & 1)>0;
CheckBox5_CheckedChange = (i & 2)>0;
CheckBox6_CheckedChange = (i & 4)>0;
CheckBox7_CheckedChange = (i & >0;
CheckBox8_CheckedChange = (i & 16)>0;
computer said no
If you have download this latest K8055 software package with the new K8055D.DLL:
velleman.eu/downloads/files/ … rsion4.zip
There in the folder \examples\ K8055DemoVB_2008 you’ll find a VB 2010 compatible example project.
DLL function declaration:
Private Declare Function ReadAllDigital Lib "k8055d.dll" () As Integer
Use:
Dim i As Integer
i = ReadAllDigital
CheckBox4.Checked = i And 1
CheckBox5.Checked = (i >> 1) And 1
CheckBox6.Checked = (i >> 2) And 1
CheckBox7.Checked = (i >> 3) And 1
CheckBox8.Checked = (i >> 4) And 1
This works too:
Dim i As Integer
i = ReadAllDigital
CheckBox4.Checked = (i And 1) > 0
CheckBox5.Checked = (i And 2) > 0
CheckBox6.Checked = (i And 4) > 0
CheckBox7.Checked = (i And 8) > 0
CheckBox8.Checked = (i And 16) > 0