I now have my K8055 at home but i dont understand the programing. Can someone do the following (in visual basic). So i can look to it and puzzel whit it and make my one program.
if input 1 is true give output 1
if input 1 and 2 are true give output 2(no output 1)
Dim i As Long
Dim n As Long
i = ReadAllDigital
If (i = 1) Then
n = 1
ElseIf (i = 3) Then
n = 2
Else
n = 0
End If
WriteAllDigital (n)
You can add this code to the Private Sub Timer1_Timer() procedure in the VB6 example.
In Visual Basic 2008 Express to this:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
thanks for the fast reaction but can you explain the 3 in ElseIf (i = 3) Then becaus i see if i change it to 4 then inpout 1 is outpout 1 and inpout 3(only) is outpout 2
Private Sub Form_Activate()
Dim i As Long
Dim n As Long
OpenDevice (0)
i = ReadAllDigital
If (i = 1) Then
n = 1
ElseIf (i = 3) Then
n = 2
Else
n = 0
End If
WriteAllDigital (n)
End Sub
i have now this codec but it does nothing only making connectie Option Explicit
[code]Dim DoNothing As Boolean
Dim n As Integer
Private Declare Function OpenDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib “k8055d.dll” ()
Private Declare Sub WriteAllDigital Lib “k8055d.dll” (ByVal Data As Long)
Private Declare Function ReadAllDigital Lib “k8055d.dll” () As Long
Private Sub noodstop_Click()
Dim i As Long
Dim n As Long
OpenDevice (0)
i = ReadAllDigital
If (i = 16) Then
n = 128
End If
WriteAllDigital (n)
End Sub
Private Sub Form_Activate()
Dim i As Long
Dim n As Long
OpenDevice (0)
i = ReadAllDigital
If (i = 1) Then
n = 1
ElseIf (i = 3) Then
n = 2
Else
n = 0
End If
WriteAllDigital (n)
End Sub
Private Sub Form_Load()
MsgBox “welcome to my first k8055 program”, , “welcome”
End Sub
Private Sub Connect_Click()
Dim CardAddress As Long
Dim h As Long
CardAddress = 0
CardAddress = 3 - (Check1(0).Value + Check1(1).Value * 2)
h = OpenDevice(CardAddress)
Select Case h
Case 0, 1, 2, 3
Label1.Caption = “Card " + Str(h) + " connected”
Case -1
Label1.Caption = “Card " + Str(CardAddress) + " not found”
End Select
End Sub[/code]
Call the OpenDevice(0) only once.
This is done in the procedure Form_Activate().
This program works fine.
If you activate input 1 or input 1 and 2, when you close the message box, the outputs are activated: LD1 or LD2 is lit.
If you activate input 5 and press the noodstop button then the LD8 is lit.
[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 Sub WriteAllDigital Lib “k8055d.dll” (ByVal Data As Long)
Private Declare Function ReadAllDigital Lib “k8055d.dll” () As Long
Private Sub noodstop_Click()
Dim i As Long
Dim n As Long
i = ReadAllDigital
If (i = 16) Then
n = 128
End If
WriteAllDigital (n)
End Sub
Private Sub Form_Activate()
Dim i As Long
Dim n As Long
OpenDevice (0)
i = ReadAllDigital
If (i = 1) Then
n = 1
ElseIf (i = 3) Then
n = 2
Else
n = 0
End If
WriteAllDigital (n)
End Sub
Private Sub Form_Load()
MsgBox “welcome to my first k8055 program”, , “welcome”
End Sub[/code]
[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 Sub WriteAllDigital Lib “k8055d.dll” (ByVal Data As Long)
Private Declare Function ReadAllDigital Lib “k8055d.dll” () As Long
Private Sub noodstop_Click()
Dim i As Long
Dim n As Long
i = ReadAllDigital
If (i = 16) Then
n = 128
End If
WriteAllDigital (n)
End Sub
Private Sub Form_Activate()
Dim i As Long
Dim n As Long
OpenDevice (0)
i = ReadAllDigital
If (i = 1) Then
n = 1
ElseIf (i = 3) Then
n = 2
Else
n = 0
End If
WriteAllDigital (n)
End Sub
Private Sub Form_Load()
MsgBox “welcome to my first k8055 program”, , “welcome”
End Sub
[/code]
and if i at this code and the noodstop button in the demo software it isnt working and i have renamed it to noodstop and the caption also
Private Sub noodstop_Click()
Dim i As Long
Dim n As Long
i = ReadAllDigital
If (i = 16) Then
n = 128
End If
WriteAllDigital (n)
End Sub
I do not see any problem in the code.
It reads the digital inputs and activates the digital outputs when button “noodstop” is pressed.
Maybe you have to add a label to display what is read from the digital input.
Add:
Label1.Caption = CStr(i)
Private Sub noodstop_Click()
Dim i As Long
Dim n As Long
i = ReadAllDigital
Label1.Caption = CStr(i)
If (i = 16) Then
n = 128
End If
WriteAllDigital (n)
End Sub
now i get it the timer is to read the k8055 on every interval so i need to set the noodstop also in the timer to make it al real time button
i need to make this in the timer code but how
Private Sub Timer1_Timer()
Timer1.Enabled = True
Dim i As Long
Dim Data1 As Long
Dim Data2 As Long
Dim n As Long
OpenDevice (0)
i = ReadAllDigital
If (i = 1) Then
n = 1
ElseIf (i = 3) Then
n = 2
elseif (i = 16 'or noodstop.click) Then
n = 128
Else
n = 0
End If
WriteAllDigital (n)
i = ReadAllDigital
Timer1.Enabled = True
End Sub
and if noodstop is active or inpout 5 it need to be above everything so if inpout1 is true and noodstop is true it need to be noodstop
[code]Option Explicit
Dim DoNothing As Boolean
Dim n As Integer
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” (Data1 As Long, 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 Form_Load()
MsgBox “welcome to my first k8055 program”, , “welcome”
End Sub
Private Sub noodstop_click()
If noodstop.Caption = “NOODSTOP” Then
Timer1.Enabled = False
Dim i As Long
Dim n As Long
OpenDevice (0)
i = ReadAllDigital
n = 128
WriteAllDigital (n)
noodstop.Caption = “LOCK”
Else
If noodstop.Caption = “LOCK” Then
Timer1.Enabled = True
noodstop.Caption = “NOODSTOP”
End If
End If
End Sub
Private Sub Timer1_Timer()
Dim i As Long
Dim Data1 As Long
Dim Data2 As Long
Dim n As Long
OpenDevice (0)
i = ReadAllDigital
If (i = 16) Then
n = 128
Else
If (i = 17) Then
n = 128
Else
If (i = 18) Then
n = 128
Else
If (i = 19) Then
n = 128
Else
If (i = 1) Then
n = 1
Else
If (i = 3) Then
n = 2
End If
End If
End If
End If
End If
End If
WriteAllDigital (n)
i = ReadAllDigital
Timer1.Enabled = True
Some comments about your code:
You are calling the [color=#008000]OpenDevice (0)[/color] in the timer routine. This is not a good practice.
Call the [color=#008000]OpenDevice (0)[/color] only once at the beginning of the program.
You may put it to the [color=#008000]Form_Load() [/color]function.
Also add this code to close the connection to the K8055:
Private Sub Form_Terminate()
CloseDevice
End Sub
Here the slightly modified code:
[code]Option Explicit
Dim DoNothing As Boolean
Dim n As Integer
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” (Data1 As Long, 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 Form_Load()
MsgBox “welcome to my first k8055 program”, , “welcome”
OpenDevice (0)
End Sub
Private Sub Form_Terminate()
CloseDevice
End Sub
Private Sub noodstop_click()
If noodstop.Caption = “NOODSTOP” Then
Timer1.Enabled = False
Dim i As Long
Dim n As Long
i = ReadAllDigital
n = 128
WriteAllDigital (n)
noodstop.Caption = “LOCK”
Else
If noodstop.Caption = “LOCK” Then
Timer1.Enabled = True
noodstop.Caption = “NOODSTOP”
End If
End If
End Sub
Private Sub Timer1_Timer()
Dim i As Long
Dim n As Long
Timer1.Enabled = False
i = ReadAllDigital
If (i = 16) Then
n = 128
Else
If (i = 17) Then
n = 128
Else
If (i = 18) Then
n = 128
Else
If (i = 19) Then
n = 128
Else
If (i = 1) Then
n = 1
Else
If (i = 3) Then
n = 2
End If
End If
End If
End If
End If
End If
WriteAllDigital (n)
Timer1.Enabled = True