cs_xa4ke
Messages postés44Date d'inscriptiondimanche 21 novembre 2004StatutMembreDernière intervention 9 juin 2007
-
9 mai 2006 à 22:36
cs_xa4ke
Messages postés44Date d'inscriptiondimanche 21 novembre 2004StatutMembreDernière intervention 9 juin 2007
-
13 mai 2006 à 14:44
Donc voila je m'explique j'ai donc le projet d'un ascensur avec une carte Velleman K8055
J'ai donc tout un code qui fonctionne correctement il me manque juste une partie
Ou une petite modification à faire
Voici mon problème j'ai donc des Command (4) qui sont indexée
le moteur de l'ascenseur est actioné avec 2 sorties de la carte ( setdigitalchannel(1) ) qui met la sortie 1 a 1 ( puis partie de puissance )
donc il y a deux sortie sortie 1 Monté sortie 2 descendre
Il faudrait avec le code que quand j'appuie sur la commande 1 il sache que l'ascensur doit monté jusqu'a ce que une checkbox soit coché ( check box qui correspond a l'étage )
et que quand je suis a deux il sache ( quand j'appuie sur la command ) 3 par ex qu'il doit monté ( donc que la sortie 1 doit etre a 1 )
jusqu'a ce que la check box 3 soit cochée
voici donc mon code
Option Explicit
'
Dim DoNothing As Boolean '<- je vois pas à quoi il sert, il ne change jamais
'Dim n As Integer '<- pas la peine de le déclarer 2 fois
'
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 Check3_Click(index As Integer)
Dim i As Long
Dim n As Long
n = 0
For i = 0 To 7
n = n + Check3(i).Value * (2 ^ i) '<-- pas très propre d'utiliser un booléen...
Next
If Not DoNothing Then WriteAllDigital n
End Sub
'
'
Private Sub Command_Click(index As Integer) '<- commencent à 1
ClearAllDigital
Call carte(index)
'If Command(Index).Value Then ... '<-- pourquoi tester la valeur du bouton?!
Call ChangeAscenseur(index)
End Sub
'
'
Private Sub connect_Click()
Dim cardaddress As Long
Dim h As Long
cardaddress = 0
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
Private Sub Form_Load()
Dim cardaddress As Long
Dim h As Long
cardaddress = 0
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
'
'
Private Sub test_Click()
Form2.Show
Unload Form1 ' oubien Unload Me '<- parfois plus simple pour se relire
End Sub
'
'
Private Sub ChangeAscenseur(Etage As Integer)
Dim i As Integer
Shape(Etage).FillStyle = 0
For i = 1 To 4
If i <> Etage Then Shape(i).FillStyle = 1
Next i
End Sub
Private Sub carte(test As Integer)
ClearAllDigital
Dim i As Integer
For i = 1 To 4
If i <> test Then SetDigitalChannel i
Next i
End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
Frame1.Caption = Check2.Value
End Sub
Private Sub Label2_Click()
Check2 = Label2.Caption
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
Dim i As Long
i = ReadAllDigital
Check2(0).Value = (i And 1)
Check2(1).Value = (i And 2) / 2
Check2(2).Value = (i And 4) / 4
Check2(3).Value = (i And 8) / 8
Check2(4).Value = (i And 16) / 16
Timer1.Enabled = True
Dim bloop As Byte, bchecked As Byte
If Check2(0).Value 1 Then bchecked bchecked + 1
If Not bchecked = 0 Then
For bloop = 1 To 4
Command(bloop).Visible = True
Next
End If
If bchecked = 0 Then
For bloop = 1 To 4
Command(bloop).Visible = False
Next
End If
End Sub
Private Sub Timer2_Timer()
Dim bloop As Byte, bchecked As Byte
If Check2(0).Value 1 Then bchecked bchecked + 1
If Not bchecked = 0 Then
For bloop = 1 To 4
Frame7.Visible = True
Next
End If
If bchecked = 0 Then
For bloop = 1 To 4
Frame7.Visible = False
Next
End If
End Sub
EN ROUGE LE CODE QU IL Y A POUR L INSTANT
ce code décide que la sortie correspondante a i va etre a 1
donc de ce fait 4 sortie moi je ne peux en avoir que deux
1 monté une descendre et en gardant mes 4 command
Si quelqu'un pouvait m'aider
merci d'avance
______________________ PLACE DES BOUTONS ___________________________
VERSION 5.00
Begin VB.Form Form3
Caption = "Form1"
ClientHeight = 2895
ClientLeft = 60
ClientTop = 390
ClientWidth = 8340
LinkTopic = "Form1"
ScaleHeight = 2895
ScaleWidth = 8340
StartUpPosition = 3 'Windows Default
Begin VB.Timer Timer2
Interval = 50
Left = 3480
Top = 720
End
Begin VB.Timer Timer1
Interval = 50
Left = 6000
Top = 720
End
Begin VB.Frame Frame6
Caption = "Inputs"
Height = 735
Left = 3840
TabIndex = 15
Top = 0
Width = 2595
Begin VB.CheckBox Check2
Caption = "1"
Height = 255
Index = 0
Left = 240
TabIndex = 20
Top = 300
Width = 495
End
Begin VB.CheckBox Check2
Caption = "2"
Height = 255
Index = 1
Left = 720
TabIndex = 19
Top = 300
Width = 375
End
Begin VB.CheckBox Check2
Caption = "3"
Height = 255
Index = 2
Left = 1080
TabIndex = 18
Top = 300
Width = 495
End
Begin VB.CheckBox Check2
Caption = "4"
Height = 255
Index = 3
Left = 1560
TabIndex = 17
Top = 300
Width = 495
End
Begin VB.CheckBox Check2
Caption = "5"
Height = 255
Index = 4
Left = 2040
TabIndex = 16
Top = 300
Width = 435
End
End
Begin VB.CommandButton Command
Caption = "Command(4)"
Height = 735
Index = 4
Left = 7200
TabIndex = 14
Top = 2160
Width = 1095
End
Begin VB.CommandButton Command
Caption = "Command(3)"
Height = 735
Index = 3
Left = 7200
TabIndex = 13
Top = 1440
Width = 1095
End
Begin VB.CommandButton Command
Caption = "Command(2)"
Height = 735
Index = 2
Left = 7200
TabIndex = 12
Top = 720
Width = 1095
End
Begin VB.CommandButton Command
Caption = "Command(1)"
Height = 735
Index = 1
Left = 7200
TabIndex = 11
Top = 0
Width = 1095
End
Begin VB.Frame Frame7
Caption = "Outputs"
Height = 735
Left = 0
TabIndex = 2
Top = 0
Width = 3555
Begin VB.CheckBox Check3
Caption = "1"
Height = 255
Index = 0
Left = 120
TabIndex = 10
Top = 300
Width = 375
End
Begin VB.CheckBox Check3
Caption = "2"
Height = 255
Index = 1
Left = 540
TabIndex = 9
Top = 300
Width = 375
End
Begin VB.CheckBox Check3
Caption = "3"
Height = 255
Index = 2
Left = 960
TabIndex = 8
Top = 300
Width = 375
End
Begin VB.CheckBox Check3
Caption = "4"
Height = 255
Index = 3
Left = 1380
TabIndex = 7
Top = 300
Width = 375
End
Begin VB.CheckBox Check3
Caption = "5"
Height = 255
Index = 4
Left = 1800
TabIndex = 6
Top = 300
Width = 375
End
Begin VB.CheckBox Check3
Caption = "6"
Height = 255
Index = 5
Left = 2220
TabIndex = 5
Top = 300
Width = 375
End
Begin VB.CheckBox Check3
Caption = "7"
Height = 255
Index = 6
Left = 2640
TabIndex = 4
Top = 300
Width = 375
End
Begin VB.CheckBox Check3
Caption = "8"
Height = 255
Index = 7
Left = 3060
TabIndex = 3
Top = 300
Width = 375
End
End
Begin VB.CommandButton connect
Caption = "test connect"
Height = 615
Left = 0
TabIndex = 0
Top = 960
Width = 1215
End
Begin VB.Shape Shape
Height = 735
Index = 4
Left = 6480
Top = 2160
Width = 735
End
Begin VB.Shape Shape
Height = 735
Index = 3
Left = 6480
Top = 1440
Width = 735
End
Begin VB.Shape Shape
Height = 735
Index = 2
Left = 6480
Top = 720
Width = 735
End
Begin VB.Shape Shape
Height = 735
Index = 1
Left = 6480
Top = 0
Width = 735
End
Begin VB.Label Label1
Caption = "---"
Height = 255
Left = 0
TabIndex = 1
Top = 1800
Width = 1935
End
End
Attribute VB_Name = "Form3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'
Dim DoNothing As Boolean '<- je vois pas à quoi il sert, il ne change jamais
'Dim n As Integer '<- pas la peine de le déclarer 2 fois
'
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 Check3_Click(index As Integer)
Dim i As Long
Dim n As Long
n = 0
For i = 0 To 7
n = n + Check3(i).Value * (2 ^ i) '<-- pas très propre d'utiliser un booléen...
Next
If Not DoNothing Then WriteAllDigital n
End Sub
'
'
Private Sub Command_Click(index As Integer) '<- commencent à 1
ClearAllDigital
Call carte(index)
'If Command(Index).Value Then ... '<-- pourquoi tester la valeur du bouton?!
Call ChangeAscenseur(index)
End Sub
'
'
Private Sub connect_Click()
Dim cardaddress As Long
Dim h As Long
cardaddress = 0
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
Private Sub Form_Load()
Dim cardaddress As Long
Dim h As Long
cardaddress = 0
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
'
'
Private Sub test_Click()
Form2.Show
Unload Form1 ' oubien Unload Me '<- parfois plus simple pour se relire
End Sub
'
'
Private Sub ChangeAscenseur(Etage As Integer)
Dim i As Integer
Shape(Etage).FillStyle = 0
For i = 1 To 4
If i <> Etage Then Shape(i).FillStyle = 1
Next i
End Sub
Private Sub carte(test As Integer)
ClearAllDigital
Dim i As Integer
For i = 1 To 4
If i <> test Then SetDigitalChannel i
Next i
End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
Frame1.Caption = Check2.Value
End Sub
Private Sub Label2_Click()
Check2 = Label2.Caption
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
Dim i As Long
i = ReadAllDigital
Check2(0).Value = (i And 1)
Check2(1).Value = (i And 2) / 2
Check2(2).Value = (i And 4) / 4
Check2(3).Value = (i And 8) / 8
Check2(4).Value = (i And 16) / 16
Timer1.Enabled = True
Dim bloop As Byte, bchecked As Byte
If Check2(0).Value 1 Then bchecked bchecked + 1
If Not bchecked = 0 Then
For bloop = 1 To 4
Command(bloop).Visible = True
Next
End If
If bchecked = 0 Then
For bloop = 1 To 4
Command(bloop).Visible = False
Next
End If
NHenry
Messages postés15048Date d'inscriptionvendredi 14 mars 2003StatutModérateurDernière intervention19 mars 2023156 10 mai 2006 à 10:10
Bonjour
Bon je n'ai pas tout regarder, mais j'ai quelques questions :
- comment tu fais pour connaitre l'étage au quel se trouve la cabine ?
- Peux-tu mettre un schéma simplifié (ou un tableau) pour voir facilement les E/S ?
Sinon,
- évite de mettre des images trop grandes, ça rend difficile la visualisation de ton post
- Tu peux mettre des checkbox à enabled=False
- Ensuite avec ton timer, regarde la position du checkbox et si il est à true, arrête ton moteur
- évite les noms Command(x), met un nom plus explicit : CmdGoTo(x).
Il est plus facile de batiser kk1 que de la convertir. (surtout en programmation)
Une question se pose sur le forum, pas en privé
NHenry (VB6, VBA excel, VB.NET, C++, C#.Net)
ce que je t'ai entouré correspond au check box 1 à 5 ( il y a 5V entre les entrées et le GND une fois que le GND est relier a une des entré la check Box qui correspond à l'entrée ce met a 1 )
Donc la 1ere entrée est relier Au Gnd et doit rester à 1 cela signifie que les portes des étages sont fermée.
Les autres check box doivent se cocher en fonction des étages (4) etages ... une fois la check box cochée les sorties de la carte doivent s'arreter
Moi ce qu'il me faudrait c'est que les commandes sachent si je dois monté ou descendre
ex j'appuie sur le bouton 4 l'asscenseur est au 1 il sait qu'il doit monté jusqu'a ce que la check box 4 se coche
l'ascenseur est au 3 je le veux au 2 il sait qu'il doit descendre et s'arreter quand la check box 2 va se coché
donc les sorties de la carte velleman 1 sortie Pour faire monté l'ascenseur
2 eme sortie pour faire descendre l'ascenseur
Pour sa j'utilise Un ULN
l'uln comporte un Clam ou je met 5V entre le GND et le Clamp (com )
ce qui permet une carte de puissance d'actioner un moteur
NHenry
Messages postés15048Date d'inscriptionvendredi 14 mars 2003StatutModérateurDernière intervention19 mars 2023156 11 mai 2006 à 08:20
Bonjour
Si j'ai bien compri, tu ne sais pas comment faire pour lui dire s'il doit descendre ou monter.
Dans ce cas, voici un petit test :
private Sub Command_Click(Index)
dim i as long
dim lActEtage as long
lActEtage=-1
for i=0 to 5
if Check2(i).Value then
lActEtage=i
End If
Next
if lActEtage=-1 then 'Aucune CheckBox cochée if lActEtage>Index then
'Monter
ElseIf lActEtageUne question se pose sur le forum, pas en privé
NHenry (VB6, VBA excel, VB.NET, C++, C#.Net)
Vous n’avez pas trouvé la réponse que vous recherchez ?
cs_xa4ke
Messages postés44Date d'inscriptiondimanche 21 novembre 2004StatutMembreDernière intervention 9 juin 2007 11 mai 2006 à 17:51
Il doit y avoir du bon mais sa met une erreur a ce que j'ai mis en rouge
( sa veut dire quoi lActEtage ?)
Private Sub Command_Click(Index As Integer)
Dim i As Long
Dim lActEtage As Long
lActEtage = -1
For i = 0 To 5
If Check2(i).Value Then
lActEtage = i
End If
Next
If lActEtage = -1 Then 'Aucune CheckBox cochée
If lActEtage > Index Then
SetDigitalChannel (1)
ElseIf lActEtage < Index Then
SetDigitalChannel (2)
NHenry
Messages postés15048Date d'inscriptionvendredi 14 mars 2003StatutModérateurDernière intervention19 mars 2023156 12 mai 2006 à 08:40
Bonjour
Ce code se sépare en plusieurs parties :
lActetage est la variable qui contient l'étage actuel de l'ascenseur.
Ensuite :
lActEtage = -1
For i = 0 To 5
If Check2(i).Value Then
lActEtage = i
End If
Next
If lActEtage = -1 Then 'Aucune CheckBox cochée
Recherche l'étage à partir des checkbox (ton erreur, est peut-être du aux boenes (5 et 0) adapte les en fonction des inbdex de tes checkbox).
Puis
If lActEtage > Index Then
SetDigitalChannel (1)
ElseIf lActEtage < Index Then
SetDigitalChannel (2)
End If
Lance la cabine en montée ou en descente enb fonction du chkbx coché et du bouton appuyé (Command(0) et Check(0) doivent représenter le mme étage)
Ne doit être lancé qui si lActEtage>=0
Le EndIf avant Le EndSub (il y en a 2 à la suite) est une erreur de syntaxe.
Dans : If lActEtage = -1 Then 'Aucune CheckBox cochée
Remplace le commentaire par un code à toi.
Code corrigé :
Dim i As Long
Dim lActEtage As Long
lActEtage = -1
For i = 0 To 5
If Check2(i).Value Then
lActEtage = i
End If
Next
If lActEtage = -1 Then 'Aucune CheckBox cochée
'Action à faire met y ton code.
Exit Sub
End If
If lActEtage > Index Then
SetDigitalChannel (1)
ElseIf lActEtage < Index Then
SetDigitalChannel (2)
End If
End Sub
Il est plus facile de batiser kk1 que de la convertir. (surtout en programmation)
Une question se pose sur le forum, pas en privé
NHenry (VB6, VBA excel, VB.NET, C++, C#.Net)
NHenry
Messages postés15048Date d'inscriptionvendredi 14 mars 2003StatutModérateurDernière intervention19 mars 2023156 12 mai 2006 à 08:43
Bonjour
ps : je n'ai pas accès à internet le weekend.
Il est plus facile de batiser kk1 que de la convertir. (surtout en programmation)
Une question se pose sur le forum, pas en privé
NHenry (VB6, VBA excel, VB.NET, C++, C#.Net)
cs_xa4ke
Messages postés44Date d'inscriptiondimanche 21 novembre 2004StatutMembreDernière intervention 9 juin 2007 13 mai 2006 à 14:44
je crois qu'il y a une petite erreur atta j'ai réécris donc en francais le texte
parceque jsuis pas tjs compréhensible meme quand je me relis ( je m'excuse )
je ne peux pas laissé tombé la notion du moteur qui monte ou descend ...
en francais j'aimerai un code qui retienne l'étage ou je suis
et qui fasse monté ou descendre l'ascenseur
en metant la sortie 1 ou 2 a "1"
et que le moteur s'arrete quand la checkbox se coche (check box de 0 à 4 )
Il faut que il sache ( le prog ) si il doit ouvrir la sortie 1 ou la sortie 2
la sortie 1 fait monté et la 2 fait descendre
ex 1 :
donc tu apuies sur la command 1 et la cabine est a l'étage 3
bah le prog va savoir qu'il doit descendre donc ouvrir la sortie 2
jusqu'a ce que la check box 1 se coche
ex 2 :
tu appuies sur la command 4 et la cabine est a l'étage 2
bah le prog va savoir qu'il doit monté donc ouvrir la sortie 1
jusqu'a ce que la check box 4 se coche
sa je ne sais pas l'exprimer par code
je ne vois pas du tout
mon idée est clair
il faut que sa fasse comme un vrai ascenseur
et que mon prog décide quelle sortie ( 1 ou 2 ) il va ouvrir
suivant l'étage ou il doit allé
jusqu'a ce que la check box de l'étage se coche
si click sur le bouton 1 et qu'il est a l'étage 2 3 4 alors
setdigitalchannel (2) jusqu'a ce que la check box 1 se coche
si click bouton deux qu'il est a l'étage 3-4 alors set digital channel (2)
jusqu'a ce que la check box 2 se coche
et si il est a l'tage 1 setdigitak channel (1) jusqu'a ce que la check box 2 se coche
setdigitalchannel (1) pour monté
setdigitalchannel (2 ) pour descendre
si je click sur le bouton 3 et qu'il est a l'étage 4 setdigitalchannel (2)
jusqu'a ce que la chek box 3 se coche
si il est a l'étage 1-2 setdigitalchannel(1) jusqu'a ce que la checkbox 3 se coche
si je click sur le bouton 4 et que la cabine est a l'etage 1-2-3
setdigitalchannel(1) jusqu'a ce que la checkbox 4 se coche
voila sa c'est ce que j'ai besoin
tu comprends mieux ?
voila sa c'est exactement ce que j'ai besoin de faire