K8055 programming with Visual Basic for applications

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

whats wrong with this??

i have the :

Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)

at the top of the page …
sorry i have 2 books im reading too

Here an example how you get a blinking LED.
The digital channel is on for one second and then off for 500ms etc.
You may extend the state machine by adding steps.

You may test this using the example in the folder \examples\K8055DemoVB_2008.
Just replacing the timer 2 handler code with this one and add a public variable “state” to the declarations section of the code.

    Dim state As Integer

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick Select Case state Case 0 SetDigitalChannel(1) Timer2.Interval = 1000 state = 1 Case 1 ClearDigitalChannel(1) Timer2.Interval = 500 state = 0 End Select End Sub
In the program click the “Output Test” button to run this example.

so if i wanted it to blink every 30 seconds for a second of two,

i would call intivals 60000 and 30000??? and set the intival on the form designer to 100???


Option Explicit On
Public Class Form1

Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Integer) As Integer
Private Declare Sub CloseDevice Lib "k8055d.dll" ()
Private Declare Function Version Lib "k8055d.dll" () As Integer
Private Declare Function SearchDevices Lib "k8055d.dll" () As Integer
Private Declare Function SetCurrentDevice Lib "k8055d.dll" (ByVal CardAddress As Integer) As Integer
Private Declare Function ReadAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer) As Integer
Private Declare Sub ReadAllAnalog Lib "k8055d.dll" (ByRef Data1 As Integer, ByRef Data2 As Integer)
Private Declare Sub OutputAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer, ByVal Data As Integer)
Private Declare Sub OutputAllAnalog Lib "k8055d.dll" (ByVal Data1 As Integer, ByVal Data2 As Integer)
Private Declare Sub ClearAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Private Declare Sub SetAllAnalog Lib "k8055d.dll" ()
Private Declare Sub ClearAllAnalog Lib "k8055d.dll" ()
Private Declare Sub SetAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Private Declare Sub WriteAllDigital Lib "k8055d.dll" (ByVal Data As Integer)
Private Declare Sub ClearDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Private Declare Sub ClearAllDigital Lib "k8055d.dll" ()
Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer)
Private Declare Sub SetAllDigital Lib "k8055d.dll" ()
Private Declare Function ReadDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer) As Boolean
Private Declare Function ReadAllDigital Lib "k8055d.dll" () As Integer
Private Declare Function ReadCounter Lib "k8055d.dll" (ByVal CounterNr As Integer) As Integer
Private Declare Sub ResetCounter Lib "k8055d.dll" (ByVal CounterNr As Integer)
Private Declare Sub SetCounterDebounceTime Lib "k8055d.dll" (ByVal CounterNr As Integer, ByVal
DebounceTime As Integer)
Dim i As Integer
Dim state As Integer




Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
    i = ReadAllDigital
    CheckBox4.Checked = (i And 1) > 0
    CheckBox5.Checked = (i And 2) > 0
    CheckBox6.Checked = (i And 4) > 0
    CheckBox7.Checked = (i And <img src="/uploads/default/original/1X/77285d5b171a9185455b287d7dac6638c76b3ea8.gif" width="15" height="17" alt="8)" title="Cool"/> > 0
    CheckBox8.Checked = (i And 16) > 0
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    Select Case state
        Case 0
            SetDigitalChannel(1)
            Timer2.Interval = 30000
            state = 1
        Case 1
            ClearDigitalChannel(1)
            Timer2.Interval = 60000
            state = 0
    End Select
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

what have i done wrong ??? :frowning:

Using this code the LED is on for 2 seconds and off for 30 seconds:

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick Select Case state Case 0 SetDigitalChannel(1) Timer2.Interval = 2000 state = 1 Case 1 ClearDigitalChannel(1) Timer2.Interval = 30000 state = 0 End Select End Sub
You may add to the CheckBox3 code this lines to turn the timer on by pressing the “Output Test” button down:

If CheckBox3.Checked Then Timer2.Enabled = True Else Timer2.Enabled = False

thanks loads it runnnss!!!

but fails to make output via channel 1

isnt channel itself an array ??? one number beeing the address and the opther being its state??? you didnt give a state… in the timer sub

[quote]isnt channel itself an array ??? one number beeing the address and the opther being its state[/quote]No, here is the channel number the only parameter. There are different functions to set and clear the channel:

SetDigitalChannel(1) 'channel #1 ON SetDigitalChannel(5) 'channel #5 ON ClearDigitalChannel(1) 'channel #1 OFF ClearDigitalChannel(5) 'channel #5 OFF
Please see the manual for more details how to use the other functions too, e.g.
WriteAllDigital.

could you help me design a recheck algorithm i get a 5 minuit reply from the clock on a switch…input 13 on the board…

J’ai fais un programme recuperant le nombre de flacon en fonction du temps sur excel en visual basic avec la digital input 1 du VM110 de plus j’ai programmé une sauvegarde automatique avec aussi une creation et changement de fichier chaque jours

pourriez vous m’aider à corriger les erreurs de programmations svp

'-------------------------------------------------------------------------------------------------------------------------
'/PREMIER CAPTEUR /////////////////////////////

'
'Je lance le programme au démarrage
'Lancer un programme au démarrage du PC -> Sans toucher au registre( menu Démarrer )



Private Declare Function SetTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Private Declare Function KillTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long)
Private Declare Function OpenDevice Lib "K8055D.DLL" (ByVal CardAddress As Long)
Private Declare Function ReadAllDigital Lib "K8055D.DLL" ()
Private Declare Function ReadIOchannel Lib "K8055D.DLL" (ByVal Channel As Long)

Dim TimerID As Long
Dim TimerSeconds As Single
Dim Connected As Boolean


Module Module1
Sub Main()

        'Initialisation des variables
        
        Dim Byt As Long
        Byt = ReadIOchannel(1)
        Dim Date_jour As Date
        Dim heure As Date
        Dim N As Integer
        N = 0
        
                
        
        'Boucle infinie /!\
        While 1

            'Récupération de la date actuelle

            Date_jour = Date_jour.ToShortDateString 'je recupere que jour/moi/année
            heure = heure.ToLongTimeString  'je recupere que heure/min/sec



'/////// TEST CHANGEMENT DE JOUR ///////////////////////////////////

                          If Date_jour <> Worksheets("Production en cours 1").Cells(N, 3).Value Then
                          
                            'creer nouveau classeur
                        
                   
                                Dim D As String
                                D = Day(Now) & Month(Now) & Year(Now) & "_" & Hour(Now) & Minute(Now)
                                Workbooks.Add
                                 ChDir "C:\Documents and Settings\moi\Bureau"
                                 ActiveWorkbook.SaveAs Filename:= _
                              "C:\Documents and Settings\moi\Bureau\Production en cours 1_" & D & ".xlsx", _
                                FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False


'/////// DEFINITON DES COLONNES ///////////////////////////////////
    'On nomme les colonnes
    
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "Nombre de Flacon"
    Range("A2").Select
    Columns("A:A").ColumnWidth = 16.71
    Range("B1").Select
    ActiveCell.FormulaR1C1 = "Heure"
    Range("C1").Select
    ActiveCell.FormulaR1C1 = "Date"
    Range("C2").Select


'/////////////LES VARIABLES   ///////////////////////////////////

                Dim nb_flacon As Integer
                nb_flacon = 1
              
              

'/////////Remplissage du tableau ///////////////////////////////////

' Remplir 3 colonnes : une disant le nombre de flacon et une les jours et l'autre les heures



If (Byt = 1) Then
' prévoir un anti rebond avec détection de front descendant

     
     
ActiveSheet.Cells(N, 1).Value = nb_flacon


'j'incremente mon nombre de flacon
nb_flacon = nb_flacon + 1


ActiveSheet.Cells(N, 2).Value = heure


ActiveSheet.Cells(N, 3).Value = Date_jour

'j'avance d'une ligne
N = N + 1

'////// Function sauvegarder ///////////////////////////////////////
'pour sauvegarder tout les 100 flacons
Dim Save As String
Save = nb_flacon / 100

'Save : valeur booléen. Vrai si c'est un entier, faux sinon.
Function Entier(ByVal Save) As Boolean
Entier = Int(Save) = Save
End Function


If Save = 1 Then
    ActiveWorkbook.Save
      End If

                                           
End If
   
    Else
'///////////CHANGEMENT DE    JOUR ///////////////////////////////////
    
              ' Subtract one day.
              Dim today As DateTime
              Dim Yesterday As DateTime
              today = System.DateTime.today
              Yesterday = today.AddDays(-1)

                ' Write the yesterday value.

                ChDir "C:\Documents and Settings\moi\Bureau"
                             ActiveWorkbook.SaveAs Filename:= _
   "C:\Documents and Settings\moi\Bureau\Production flacon 1_" & Yesterday & ".xlsx", _
        FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
                            
    
   
End Function
End Sub

                

Your code reminds me of spaghetti

This is readable:

While True
    If True Then
        DoAction();
    End If
End While

This is not readable:

                      WHile True
         If true Then
  Doaction()
End If
          End While