K8063 commande d'un digit jumbo, affichage heure, date en alterné,...

Soyez le premier à donner votre avis sur cette source.

Vue 3 548 fois - Téléchargée 395 fois

Description

Ce programme permet d'afficher l'heure et la date chiffre par chiffre sur un K8063 de Velleman. Si vous possédez la K8055 (interface USB, version de base) et un ou deux K8067 (capteur de température universel), l'afficheur affichera la (les) températures. 4 checks permettent de séléctionner ce qu'on désire afficher. Par un simple clic, on peut réduire le programme dans le systray!
Le port COM, séléctionné par défaut est le 7 (on peut changer soit en mode programmation ou en mode RUN), et l'adresse du digit est le 1 (on peut également...).

Source / Exemple :


Dim z As Byte
Dim zz As Byte
Dim zt1 As Byte
Dim zt2 As Byte
Dim ok As Byte

Dim hh As Byte
Dim dd As Byte
Dim t1 As Byte
Dim t2 As Byte

Dim h1 As Byte
Dim h2 As Byte
Dim m1 As Byte
Dim m2 As Byte
Dim s1 As Byte
Dim s2 As Byte

Dim d1 As Byte
Dim d2 As Byte
Dim d3 As Byte
Dim d4 As Byte
Dim d5 As Byte
Dim d6 As Byte

Dim ha1 As Byte
Dim ha2 As Byte
Dim ha3 As Byte
Dim ha4 As Byte

Dim hz1 As Byte
Dim hz2 As Byte
Dim mz1 As Byte
Dim mz2 As Byte

Public addr As Byte

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 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 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)

Public Sub connects()
Comm.CommPort = K8067.ncom.Text
Comm.Settings = "2400,N,8,1"
Comm.PortOpen = True
End Sub

Public Sub strobe()
commandstring = Chr$(13) & Chr$(0) & "S" & Chr$(0) & Chr$(160)
Comm.Output = commandstring
End Sub

Private Sub Check1_Click()
If Comm.PortOpen = False Then Call connects
zt1 = 0

If K8055.ino.Visible = True Then Check1.Value = 0
If Timer3.Enabled = False And Timer1.Enabled = False And Timer5.Enabled = False Then Timer4.Enabled = True

'Timer4.Enabled = True
'If Check1.Value = 0 Then Timer4.Enabled = False

End Sub

Private Sub Check2_Click()
If Comm.PortOpen = False Then Call connects
zt2 = 0

If K8055.ino.Visible = True Then Check2.Value = 0

If Timer3.Enabled = False And Timer4.Enabled = False And Timer1.Enabled = False Then Timer5.Enabled = True

End Sub

Private Sub Check3_Click()
If Timer1.Enabled = False And Timer4.Enabled = False And Timer5.Enabled = False Then Timer3.Enabled = True

zz = 0

'Timer3.Enabled = True

plusla:

End Sub

Private Sub Check4_Click()
If Comm.PortOpen = False Then Call connects
z = 0
If Timer3.Enabled = False And Timer4.Enabled = False And Timer5.Enabled = False Then Timer1.Enabled = True

End Sub

Private Sub Check5_Click()
If Check5.Value = 1 Then
    checksum = 256 - (13 + addr + 73 + 255) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(73) & Chr$(255) & Chr$(checksum)
    Comm.Output = commandstring
Else
    checksum = 256 - (13 + addr + 73 + 0) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(73) & Chr$(0) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
End Sub

Private Sub Check6_Click()
ha1 = Mid(txt_a1, 1, 1)
ha2 = Mid(txt_a1, 2, 1)
ha3 = Mid(txt_a2, 1, 1)
ha4 = Mid(txt_a2, 2, 1)

End Sub

Private Sub cSysTray1_MouseDown(Button As Integer, Id As Long)
Select Case Button
    Case 1  ' Left button
        cSysTray1.InTray = False
        Base.Visible = True
    Case 2  'Right button
        PopupMenu mnus_systray
  End Select
End Sub

Private Sub Form_Load()
'cSysTray1.InTray = True 'démarrage réduit
'Base.Visible = False

K8067.ncom.Text = 7  'met le com défaut à 7
K8067.addigit.Text = 1  ' attt
Call connects

Timer1.Enabled = False
Timer2.Enabled = True
Timer3.Enabled = False
Timer4.Enabled = False
Timer5.Enabled = False

addr = K8067.addigit.Text 'attt

checksum = 256 - (13 + addr + 66 + 2) Mod 256
commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(2) & Chr$(checksum)
Comm.Output = commandstring
Call strobe

Check5.Value = 1 'adoucit l'afficheur
'Check4.Value = 1 'active l'heure

txt_a1 = 20
txt_a2 = "05" 'force le 0 sinon met 5 au lieu de 05
'check6.value= 1

z = 0
txt_a1.MaxLength = 2
txt_a2.MaxLength = 2
K8055.SK5.Value = 1
K8055.SK6.Value = 1
K8055.dt1.Text = 0
K8055.dt2.Text = 0
K8055.Command1 = True

K8055.lt2.Value = 1
K8055.lt1.Value = 1

End Sub

Private Sub Label3_Click()
End Sub

Private Sub Form_Terminate()
checksum = 256 - (13 + addr + 66 + (0) Mod 256)
commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
Comm.Output = commandstring
Call strobe
Comm.PortOpen = False

CloseDevice 'K8055
End
End Sub

Private Sub Form_Unload(Cancel As Integer)
checksum = 256 - (13 + addr + 66 + (0) Mod 256)
commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
Comm.Output = commandstring
Call strobe
Comm.PortOpen = False

CloseDevice 'K8055
End
End Sub

Private Sub mnu_k8055_Click()
K8055.Visible = True
End Sub

Private Sub mnu_k8067_Click()
Check1.Value = 0
Check2.Value = 0
Check3.Value = 0
Check4.Value = 0

'affiche adresse DIGIT
checksum = 256 - (13 + 0 + 68 + 0) Mod 256
commandstring = Chr$(13) & Chr$(0) & Chr$(68) & Chr$(0) & Chr$(checksum)
Comm.Output = commandstring
Call strobe

Timer1.Enabled = False
Comm.PortOpen = False
K8067.Visible = True
End Sub

Private Sub mnu_quit_Click()
checksum = 256 - (13 + addr + 66 + (0) Mod 256)
commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
Comm.Output = commandstring
Call strobe
Comm.PortOpen = False

CloseDevice 'K8055
End
End Sub

Private Sub mnu_recon_Click()
'Call connects
If Comm.PortOpen = False Then Comm.PortOpen = True

End Sub

Private Sub mnu_systray_Click()
cSysTray1.InTray = True
Base.Visible = False
End Sub

Private Sub mnu_version_Click()
Comm.PortOpen = False
Splash.Show
End Sub

Private Sub mnus_agrand_Click()
cSysTray1.InTray = False
 Base.Visible = True
End Sub

Private Sub mnus_quit_Click()
checksum = 256 - (13 + addr + 66 + (0) Mod 256)
commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
Comm.Output = commandstring
Call strobe
Comm.PortOpen = False
End
End Sub

Private Sub Timer1_Timer()
Timer1.Enabled = False
heure2 = Time

checksum = 256 - (13 + addr + 66 + 0) Mod 256
commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
Comm.Output = commandstring
Call strobe

h1 = Mid(heure2, 1, 1) 'découpe l'heure et met chaque chiffre dans 1 variable
h2 = Mid(heure2, 2, 1)
m1 = Mid(heure2, 4, 1)
m2 = Mid(heure2, 5, 1)
's1 = Mid(heure, 7, 1)
's2 = Mid(heure, 8, 1)

z = z + 1 'gére l'affichage de l'heure
If Check4.Value = 1 And z = 1 Then
    checksum = 256 - (13 + addr + 65 + (Asc(h1)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(h1)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check4.Value = 1 And z = 2 Then
    checksum = 256 - (13 + addr + 65 + (Asc(h2)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(h2)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check4.Value = 1 And z = 3 Then
    checksum = 256 - (13 + addr + 66 + 79) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(79) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check4.Value = 1 And z = 4 Then
    checksum = 256 - (13 + addr + 65 + (Asc(m1)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(m1)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check4.Value = 1 And z = 5 Then
    checksum = 256 - (13 + addr + 65 + (Asc(m2)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(m2)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check4.Value = 1 And z = 6 Then
    checksum = 256 - (13 + addr + 66 + 0) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If

If z = 6 And Check3.Value = 1 Then z = 0: zz = 0: Timer1.Enabled = False: Timer3.Enabled = True: GoTo fin
If z = 6 And Check1.Value = 1 Then z = 0: zt1 = 0: Timer1.Enabled = False: Timer4.Enabled = True: GoTo fin
If z = 6 Then z = 0

Timer1.Enabled = True
fin:
End Sub

Private Sub Timer2_Timer()
heure = Time
ddate = Date
Label2.Caption = ddate

hz1 = Mid(heure, 1, 1)
hz2 = Mid(heure, 2, 1)
mz1 = Mid(heure, 4, 1)
mz2 = Mid(heure, 5, 1)
Label1.Caption = Mid(heure, 1, 5)

If Check6.Value = 1 And hz1 = ha1 And hz2 = ha2 And mz1 = ha3 And mz2 = ha4 Then Beep: MsgBox "Alarme! C'est l'heure!", vbCritical: Check6.Value = 0

tfb1.Caption = K8055.tf1 + "°"
tfb2.Caption = K8055.tf2 + "°"

'WATCHDOG
If Timer1.Enabled = False And Timer3.Enabled = False And Timer4.Enabled = False And Timer5.Enabled = False And Check4.Value = 1 Then Timer1.Enabled = True
If Timer1.Enabled = False And Timer3.Enabled = False And Timer4.Enabled = False And Timer5.Enabled = False And Check3.Value = 1 Then Timer3.Enabled = True
If Timer1.Enabled = False And Timer3.Enabled = False And Timer4.Enabled = False And Timer5.Enabled = False And Check1.Value = 1 Then Timer4.Enabled = True
If Timer1.Enabled = False And Timer3.Enabled = False And Timer4.Enabled = False And Timer5.Enabled = False And Check2.Value = 1 Then Timer5.Enabled = True

End Sub

Private Sub Timer3_Timer()
Timer3.Enabled = False
ddate = Date

checksum = 256 - (13 + addr + 66 + 0) Mod 256
commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
Comm.Output = commandstring
Call strobe

d1 = Mid(ddate, 1, 1) 'découpe la date et met chaque chiffre dans 1 variable
d2 = Mid(ddate, 2, 1)
d3 = Mid(ddate, 4, 1)
d4 = Mid(ddate, 5, 1)
d5 = Mid(ddate, 9, 1)
d6 = Mid(ddate, 10, 1)

zz = zz + 1 'gére l'affichage de la date
If Check3.Value = 1 And zz = 1 Then
    checksum = 256 - (13 + addr + 65 + (Asc(d1)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(d1)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 2 Then
    checksum = 256 - (13 + addr + 65 + (Asc(d2)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(d2)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 3 Then
    checksum = 256 - (13 + addr + 66 + (2) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(2) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 4 Then
    checksum = 256 - (13 + addr + 65 + (Asc(d3)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(d3)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 5 Then
    checksum = 256 - (13 + addr + 65 + (Asc(d4)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(d4)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 6 Then
    checksum = 256 - (13 + addr + 66 + (2) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(2) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 7 Then
    checksum = 256 - (13 + addr + 65 + (Asc(d5)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(d5)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 8 Then
    checksum = 256 - (13 + addr + 65 + (Asc(d6)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(d6)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 9 Then
    checksum = 256 - (13 + addr + 66 + 0) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If zz = 9 And Check1.Value = 1 Then zz = 0: zt1 = 0: Timer3.Enabled = False: Timer4.Enabled = True: GoTo plusl2
If zz = 9 And Check2.Value = 1 Then zz = 0: zt2 = 0: Timer3.Enabled = False: Timer5.Enabled = True: GoTo plusl2
If zz = 9 And Check4.Value = 1 Then zz = 0: Timer3.Enabled = False: Timer1.Enabled = True: GoTo plusl2

If zz = 9 Then zz = 0
Timer3.Enabled = True
plusl2:

End Sub

Private Sub Timer4_Timer()
Timer4.Enabled = False
    checksum = 256 - (13 + addr + 66 + 0) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
    
tfba1 = Round(Val(tfb1.Caption), 1)
pt1 = Mid(tfba1, 1, 1)
pt2 = Mid(tfba1, 2, 1)
pt3 = Mid(tfba1, 3, 1)

zt1 = zt1 + 1

If zt1 = 1 And pt1 = "-" Then
    checksum = 256 - (13 + addr + 66 + (2) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(2) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
    GoTo pluslt4
End If
If zt1 = 1 Then
    checksum = 256 - (13 + addr + 65 + (Asc(pt1)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(pt1)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
pluslt4:
If zt1 = 2 And pt2 = "" Then zt1 = 3
If zt1 = 2 Then
    checksum = 256 - (13 + addr + 65 + (Asc(pt2)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(pt2)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If

If zt1 = 3 And pt3 = "" Then zt1 = 4

If zt1 = 3 Then
    checksum = 256 - (13 + addr + 65 + (Asc(pt3)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(pt3)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If

If zt1 = 4 Then
    checksum = 256 - (13 + addr + 66 + (39) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(39) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If zt1 = 5 Then
    checksum = 256 - (13 + addr + 66 + 0) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If zt1 = 5 And Check2.Value = 1 Then zt1 = 0: zt2 = 0: Timer4.Enabled = False: Timer5.Enabled = True: GoTo fint4b
If zt1 = 5 And Check4.Value = 1 Then zt1 = 0: z = 0: Timer4.Enabled = False: Timer1.Enabled = True: GoTo fint4b
If zt1 = 5 And Check3.Value = 1 Then zt1 = 0: zz = 0: Timer4.Enabled = False: Timer3.Enabled = True: GoTo fint4b
If zt1 = 5 Then zt1 = 0

Timer4.Enabled = True
fint4b:
End Sub

Private Sub Timer5_Timer()
Timer5.Enabled = False
    checksum = 256 - (13 + addr + 66 + 0) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
    
tfba2 = Round(Val(tfb2.Caption), 1)
pt4 = Mid(tfba2, 1, 1)
pt5 = Mid(tfba2, 2, 1)
pt6 = Mid(tfba2, 3, 1)

zt2 = zt2 + 1

If zt2 = 1 And pt4 = "-" Then
    checksum = 256 - (13 + addr + 66 + (2) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(2) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
    GoTo pluslt5
End If
If zt2 = 1 Then
    checksum = 256 - (13 + addr + 65 + (Asc(pt4)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(pt4)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
pluslt5:
If zt2 = 2 And pt5 = "" Then zt2 = 3
If zt2 = 2 Then
    checksum = 256 - (13 + addr + 65 + (Asc(pt5)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(pt5)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If

If zt2 = 3 And pt6 = "" Then zt2 = 4

If zt2 = 3 Then
    checksum = 256 - (13 + addr + 65 + (Asc(pt6)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(pt6)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If

If zt2 = 4 Then
    checksum = 256 - (13 + addr + 66 + (39) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(39) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If zt2 = 5 Then
    checksum = 256 - (13 + addr + 66 + 0) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If zt2 = 5 And Check4.Value = 1 Then zt2 = 0: z = 0: Timer5.Enabled = False: Timer1.Enabled = True: GoTo fint5
If zt2 = 5 And Check3.Value = 1 Then zt2 = 0: z = 0: Timer5.Enabled = False: Timer3.Enabled = True: GoTo fint5
If zt2 = 5 And Check1.Value = 1 Then zt2 = 0: zt1 = 0: Timer5.Enabled = False: Timer4.Enabled = True: GoTo fint5

If zt2 = 5 Then zt2 = 0

Timer5.Enabled = True
fint5:

End Sub

Private Sub Timer6_Timer()
'controle 1 timer à la fois! - WATCHDOG -

End Sub

Private Sub Timerm_Timer()
'non utilisé

Timerm.Enabled = False
    checksum = 256 - (13 + addr + 66 + 0) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
    
'gestion température 1
If Check1.Value = 0 Then GoTo temp2
If occ = 0 Then occ = temp1
If occ <> temp1 Then GoTo temp2
tfba1 = Round(Val(tfb1.Caption), 1)
pt1 = Mid(tfba1, 1, 1)
pt2 = Mid(tfba1, 2, 1)
pt3 = Mid(tfba1, 3, 1)

zt1 = zt1 + 1

If zt1 = 1 And pt1 = "-" Then
    checksum = 256 - (13 + addr + 66 + (2) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(2) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
    GoTo pluslt4
End If
If zt1 = 1 Then
    checksum = 256 - (13 + addr + 65 + (Asc(pt1)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(pt1)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
pluslt4:
If zt1 = 2 And pt2 = "" Then zt1 = 3
If zt1 = 2 Then
    checksum = 256 - (13 + addr + 65 + (Asc(pt2)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(pt2)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If

If zt1 = 3 And pt3 = "" Then zt1 = 4

If zt1 = 3 Then
    checksum = 256 - (13 + addr + 65 + (Asc(pt3)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(pt3)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If

If zt1 = 4 Then
    checksum = 256 - (13 + addr + 66 + (39) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(39) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If zt1 = 5 Then
    checksum = 256 - (13 + addr + 66 + 0) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If zt1 = 5 Then zt1 = 0: occ = 0 Else GoTo gfin

    checksum = 256 - (13 + addr + 66 + 0) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe

temp2:
'gestion température 2
If Check2.Value = 0 Then GoTo gheure
occ = temp2
tfba2 = Round(Val(tfb2.Caption), 1)
pt4 = Mid(tfba2, 1, 1)
pt5 = Mid(tfba2, 2, 1)
pt6 = Mid(tfba2, 3, 1)

zt2 = zt2 + 1

If zt2 = 1 And pt4 = "-" Then
    checksum = 256 - (13 + addr + 66 + (2) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(2) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
    GoTo pluslt5
End If
If zt2 = 1 Then
    checksum = 256 - (13 + addr + 65 + (Asc(pt4)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(pt4)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
pluslt5:
If zt2 = 2 And pt5 = "" Then zt2 = 3
If zt2 = 2 Then
    checksum = 256 - (13 + addr + 65 + (Asc(pt5)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(pt5)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If

If zt2 = 3 And pt6 = "" Then zt2 = 4

If zt2 = 3 Then
    checksum = 256 - (13 + addr + 65 + (Asc(pt6)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(pt6)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If

If zt2 = 4 Then
    checksum = 256 - (13 + addr + 66 + (39) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(39) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If zt2 = 5 Then
    checksum = 256 - (13 + addr + 66 + 0) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If zt2 = 5 Then zt2 = 0: occ = 0 Else GoTo gfin

'gestion heure
gheure:
If Check4.Value = 0 Then GoTo gdate
occ = heur
heure2 = Time
h1 = Mid(heure2, 1, 1) 'découpe l'heure et met chaque chiffre dans 1 variable
h2 = Mid(heure2, 2, 1)
m1 = Mid(heure2, 4, 1)
m2 = Mid(heure2, 5, 1)
's1 = Mid(heure, 7, 1)
's2 = Mid(heure, 8, 1)

z = z + 1
If Check4.Value = 1 And z = 1 Then
    checksum = 256 - (13 + addr + 65 + (Asc(h1)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(h1)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check4.Value = 1 And z = 2 Then
    checksum = 256 - (13 + addr + 65 + (Asc(h2)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(h2)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check4.Value = 1 And z = 3 Then
    checksum = 256 - (13 + addr + 66 + 79) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(79) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check4.Value = 1 And z = 4 Then
    checksum = 256 - (13 + addr + 65 + (Asc(m1)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(m1)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check4.Value = 1 And z = 5 Then
    checksum = 256 - (13 + addr + 65 + (Asc(m2)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(m2)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check4.Value = 1 And z = 6 Then
    checksum = 256 - (13 + addr + 66 + 0) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If z = 6 Then z = 0: occ = 0

'gestion date
gdate:
If Check3.Value = 0 Then GoTo gfin
occ = dat
ddate = Date
d1 = Mid(ddate, 1, 1) 'découpe la date et met chaque chiffre dans 1 variable
d2 = Mid(ddate, 2, 1)
d3 = Mid(ddate, 4, 1)
d4 = Mid(ddate, 5, 1)
d5 = Mid(ddate, 9, 1)
d6 = Mid(ddate, 10, 1)

zz = zz + 1 'gére l'affichage de la date
If Check3.Value = 1 And zz = 1 Then
    checksum = 256 - (13 + addr + 65 + (Asc(d1)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(d1)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 2 Then
    checksum = 256 - (13 + addr + 65 + (Asc(d2)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(d2)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 3 Then
    checksum = 256 - (13 + addr + 66 + (2) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(2) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 4 Then
    checksum = 256 - (13 + addr + 65 + (Asc(d3)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(d3)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 5 Then
    checksum = 256 - (13 + addr + 65 + (Asc(d4)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(d4)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 6 Then
    checksum = 256 - (13 + addr + 66 + (2) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(2) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 7 Then
    checksum = 256 - (13 + addr + 65 + (Asc(d5)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(d5)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 8 Then
    checksum = 256 - (13 + addr + 65 + (Asc(d6)) Mod 256)
    commandstring = Chr$(13) & Chr$(addr) & Chr$(65) & Chr$(Asc(d6)) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If Check3.Value = 1 And zz = 9 Then
    checksum = 256 - (13 + addr + 66 + 0) Mod 256
    commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(0) & Chr$(checksum)
    Comm.Output = commandstring
    Call strobe
End If
If zz = 9 Then zz = 0: occ = 0
gfin:

Timerm.Enabled = True
End Sub

Conclusion :


Version 0.0.2.
Malheuresement il reste encore quelques petits bugs.

Je recommande de ne pas décocher un élément qui est en cours d'affichage.

Codes Sources

A voir également

Ajouter un commentaire Commentaire
Messages postés
1172
Date d'inscription
jeudi 24 mai 2007
Statut
Membre
Dernière intervention
28 septembre 2013
1
Salut, tout d'abord pourquoi un niveau initié ?
je trouve ton code trop lourd à lire, regarde par exemple les "If Check3.Value 1 And zz 3 Then" tu aurais pu faire une fonction à l'appeler en lui passant la valeur de zz ( ou faire un case au moins), regarde aussi le nombre de fos ou tu écris "169.checksum = 256 - (13 + addr + 66 + 2) Mod 256
170.commandstring = Chr$(13) & Chr$(addr) & Chr$(66) & Chr$(2) & Chr$(checksum)
171.Comm.Output = commandstring" ceux la aussi mérite une ptie fonction.
Pour ce qui est de la VM110 (K8055) tu n'utilisse pas la derniére DLL, la nouvelle version inclus la recherche automatique des cartes, l'affichage de la version et surtout la gestion multicarte.
Regarde aussi la form K8055, tu redéclare les appels à la dll !
Fait un seul appel en public, au lieu de le faire plusieurs fois en private.
Bon j'arrêtte là, mais ya plein de chose qui font que le codage me parait pas être un bon exemple pour les autres. Je connais trés bien les cartes velleman si tu as besoin de conseil demande par MP. POur le codage regarde d'autre source pour voir comment factoriser ton code, il en sera bien plus lisible.

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.