VERSION 5.00
Begin VB.Form Test_InpOutt32 
   Caption         =   "Test Inpout32"
   ClientHeight    =   9180
   ClientLeft      =   915
   ClientTop       =   1410
   ClientWidth     =   12090
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   9180
   ScaleWidth      =   12090
   Begin VB.CommandButton m4 
      Caption         =   "m4"
      Height          =   495
      Left            =   8280
      TabIndex        =   18
      Top             =   2880
      Width           =   615
   End
   Begin VB.CommandButton m3 
      Caption         =   "m3"
      Height          =   495
      Left            =   8280
      TabIndex        =   17
      Top             =   3840
      Width           =   615
   End
   Begin VB.CommandButton m2 
      Caption         =   "m2"
      Height          =   495
      Left            =   8280
      TabIndex        =   16
      Top             =   4920
      Width           =   615
   End
   Begin VB.CommandButton m1 
      Caption         =   "m1"
      Height          =   495
      Left            =   8280
      TabIndex        =   15
      Top             =   5880
      Width           =   615
   End
   Begin VB.Frame Frame1 
      Caption         =   "Programmation de l'ascenseur sous VB CORRECTION Lycée Louis Payen"
      Height          =   495
      Left            =   2280
      TabIndex        =   14
      Top             =   120
      Width           =   5415
   End
   Begin VB.CommandButton Command4 
      Caption         =   "Command4"
      Height          =   495
      Left            =   5640
      TabIndex        =   13
      Top             =   5160
      Width           =   1215
   End
   Begin VB.TextBox Text2 
      Height          =   375
      Left            =   5280
      TabIndex        =   12
      Text            =   "Text2"
      Top             =   1320
      Width           =   6015
   End
   Begin VB.CommandButton etage4 
      Caption         =   "etage4"
      Height          =   495
      Left            =   9720
      TabIndex        =   11
      Top             =   2880
      Width           =   1335
   End
   Begin VB.CommandButton etage3 
      Caption         =   "etage3"
      Height          =   495
      Left            =   9720
      TabIndex        =   10
      Top             =   3840
      Width           =   1335
   End
   Begin VB.CommandButton etage2 
      Caption         =   "etage2"
      Height          =   495
      Left            =   9720
      TabIndex        =   9
      Top             =   4800
      Width           =   1335
   End
   Begin VB.CommandButton etage1 
      Caption         =   "etage1"
      Height          =   495
      Left            =   9720
      TabIndex        =   8
      Top             =   5880
      Width           =   1335
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Command3"
      Height          =   495
      Left            =   3840
      TabIndex        =   7
      Top             =   5160
      Width           =   1215
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Command2"
      Height          =   495
      Left            =   2040
      TabIndex        =   6
      Top             =   5160
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   495
      Left            =   240
      TabIndex        =   5
      Top             =   5160
      Width           =   1215
   End
   Begin VB.Timer Timer1 
      Interval        =   10
      Left            =   2640
      Top             =   2280
   End
   Begin VB.CommandButton lire_port 
      Caption         =   "lire_port"
      Height          =   495
      Left            =   240
      TabIndex        =   4
      Top             =   2280
      Width           =   1215
   End
   Begin VB.CommandButton arreter 
      Caption         =   "Arreter"
      Height          =   735
      Left            =   4920
      TabIndex        =   3
      Top             =   3600
      Width           =   1815
   End
   Begin VB.CommandButton descendre 
      Caption         =   "Descendre"
      Height          =   735
      Left            =   2520
      TabIndex        =   2
      Top             =   3600
      Width           =   1815
   End
   Begin VB.TextBox Text1 
      Height          =   372
      Left            =   120
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   1440
      Width           =   2052
   End
   Begin VB.CommandButton monter 
      Caption         =   "Monter"
      Height          =   732
      Left            =   120
      TabIndex        =   0
      Top             =   3600
      Width           =   1932
   End
End
Attribute VB_Name = "Test_InpOutt32"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Value, i, etage_courant, c_etage1, c_etage2, c_etage3, c_etage4 As Integer


Dim PortAddress1, PortAddress2, code As Integer

Private Sub Form_Load()

PortAddress1 = &H378
PortAddress2 = &H379

c_etage1 = 64
c_etage2 = 32
c_etage3 = 16
c_etage4 = 8


End Sub


Private Sub Command1_Click()
Do
  Out &H378, 1         ' commande pour monter
  code = Inp(&H379)
Loop Until code = 16
Out &H378, 0            ' stop
  
End Sub



Private Sub Command2_Click()
Do
  Out &H378, 2         ' commande pour descendre
  code = Inp(&H379)
Loop Until code = 32
Out &H378, 0            ' stop

End Sub

Private Sub Command3_Click()


  Do
    Out &H378, 1         ' commande pour monter
    code = Inp(&H379)
  Loop Until code = 16
  Out &H378, 0            ' stop
  Sleep 1000              ' Valeur en milliseconde (1000 ms = 1 seconde)
  Do
    Out &H378, 2         ' commande pour descendre
    code = Inp(&H379)
  Loop Until code = 32
  Out &H378, 0            ' stop



End Sub

Private Sub Command4_Click()
For i = 1 To 3
  Do
    Out &H378, 1         ' commande pour monter
    code = Inp(&H379)
  Loop Until code = 16
  Out &H378, 0            ' stop
  Sleep 1000
  Do
    Out &H378, 2         ' commande pour descendre
    code = Inp(&H379)
  Loop Until code = 32
  Out &H378, 0            ' stop
Next i

End Sub

Private Sub etage1_Click()
  etage_courant = Inp(&H379)
  If etage_courant = 0 Then
    Text2.Text = "Ascenseur entre 2 étages. Positionner le à un étage précis"
  Else
    
  If etage_courant = c_etage2 Or etage_courant = c_etage3 Or etage_courant = c_etage4 Then
    
    Do
      Out &H378, 2         ' commande pour descendre
      code = Inp(&H379)
    Loop Until code = c_etage1
    Out &H378, 0            ' stop
    
  End If
  
  
  Text2.Text = " Etage 1 atteint "
  End If
  
End Sub

Private Sub etage2_Click()

etage_courant = Inp(&H379)
  If etage_courant = 0 Then
    Text2.Text = "Ascenseur entre 2 étages. Positionner le à un étage précis"
  Else
    
    If etage_courant = c_etage3 Or etage_courant = c_etage4 Then   ' on descend
    
      Do
        Out &H378, 2         ' commande pour descendre
        code = Inp(&H379)
      Loop Until code = c_etage2
      Out &H378, 0            ' stop
    
    
    Else                      ' sinon on monte
   
      Do
        Out &H378, 1         ' commande pour monter
        code = Inp(&H379)
     Loop Until code = c_etage2
      Out &H378, 0            ' stop
    
    End If
     
  Text2.Text = " Etage 2 atteint "
  End If
  











End Sub

Private Sub etage3_Click()
etage_courant = Inp(&H379)
  If etage_courant = 0 Then
    Text2.Text = "Ascenseur entre 2 étages. Positionner le à un étage précis"
  Else
    
    If etage_courant = c_etage4 Then   ' on descend
    
      Do
        Out &H378, 2         ' commande pour descendre
        code = Inp(&H379)
      Loop Until code = c_etage3
      Out &H378, 0            ' stop
    
    
    Else  '                         sinon on monte
   
      Do
        Out &H378, 1         ' commande pour monter
        code = Inp(&H379)
     Loop Until code = c_etage3
      Out &H378, 0            ' stop
    
    End If
     
  Text2.Text = " Etage 3 atteint "
  End If
End Sub

Private Sub etage4_Click()
etage_courant = Inp(&H379)
  If etage_courant = 0 Then
    Text2.Text = "Ascenseur entre 2 étages. Positionner le à un étage précis"
  Else
          
      Do
        Out &H378, 1         ' commande pour monter
        code = Inp(&H379)
     Loop Until code = c_etage4
      Out &H378, 0            ' stop
    
     
  Text2.Text = " Etage 4 atteint "
  End If
End Sub




Private Sub arreter_Click()
Out PortAddress1, 0

End Sub

Private Sub descendre_Click()
Out PortAddress1, 2
End Sub



Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)

End Sub

Private Sub lire_port_Click()
Text1.Text = Inp(PortAddress2)
End Sub

Private Sub m2_Click()
 Do
    Out &H378, 1         ' commande pour monter
    code = Inp(&H379)
  Loop Until code = 32
  Out &H378, 0            ' stop
  Sleep 1000              ' Valeur en milliseconde (1000 ms = 1 seconde)
  Do
    Out &H378, 2         ' commande pour descendre
    code = Inp(&H379)
  Loop Until code = 64
  Out &H378, 0            ' stop

End Sub

Private Sub m3_Click()
Do
    Out &H378, 1         ' commande pour monter
    code = Inp(&H379)
  Loop Until code = 16    ' etage 3
  Out &H378, 0            ' stop
  Sleep 1000              ' Valeur en milliseconde (1000 ms = 1 seconde)
  Do
    Out &H378, 2         ' commande pour descendre
    code = Inp(&H379)
  Loop Until code = 64
  Out &H378, 0            ' stop


End Sub

Private Sub m4_Click()
   Do
    Out &H378, 1         ' commande pour monter
    code = Inp(&H379)
  Loop Until code = 8     ' etage 4
  Out &H378, 0            ' stop
  Sleep 1000              ' Valeur en milliseconde (1000 ms = 1 seconde)
  Do
    Out &H378, 2         ' commande pour descendre
    code = Inp(&H379)
  Loop Until code = 64
  Out &H378, 0            ' stop
End Sub

Private Sub monter_Click()
Out PortAddress1, 1

End Sub

Private Sub Timer1_Timer()
  Text1.Text = Inp(PortAddress2)
End Sub
