Programme dur a comprendre

mpjp57
Messages postés
18
Date d'inscription
jeudi 13 mars 2008
Statut
Membre
Dernière intervention
23 mai 2008
- 13 mars 2008 à 18:16
mpjp57
Messages postés
18
Date d'inscription
jeudi 13 mars 2008
Statut
Membre
Dernière intervention
23 mai 2008
- 18 mars 2008 à 15:00
bonjour a tous je suis en stage au canada et je dois faire un graphe de fonctionnement dun programme en VB.net mais cela fait 2 ans que je né pas fait de VB et je n'est travaillé que sur VB6 Pouvez vous m'aider a comprendre le programme.

4 réponses

cs_ghuysmans99
Messages postés
3983
Date d'inscription
jeudi 14 juillet 2005
Statut
Membre
Dernière intervention
30 juin 2013
16
13 mars 2008 à 19:05
"et je dois faire un graphe de fonctionnement dun programme en VB.net" -> Le quel ?
_______________________________________________________________________
VB.NETis good ...VB6is better
0
jrivet
Messages postés
7393
Date d'inscription
mercredi 23 avril 2003
Statut
Membre
Dernière intervention
6 avril 2012
60
14 mars 2008 à 09:28
Salut,
Il est inutile de valide rle topic si tu n'estime pas ton problème résolu.
Apporte plus de précision comme le propose [auteur/GHUYSMANS99/549970.aspx ghuysmans99]

@+: Ju£i?n
Pensez: Réponse acceptée
0
mpjp57
Messages postés
18
Date d'inscription
jeudi 13 mars 2008
Statut
Membre
Dernière intervention
23 mai 2008

14 mars 2008 à 15:31
je suis désoler je ne connais pas encore tres bien le systeme de ce forum. voila mon programme:
Public Class Controle
    Dim i As Boolean
    ' parallel: pin 0: 0 => reculer / 1 => avancer
    '               1: 0 => gauche / 1 => droite
    '               2: 0 => pas-à-pas désactivé / 1 => pas-à-pas activé


    '           pin 8: 0 => ne rien faire / 1 => arrêter de tourner vers la gauche
    '           pin 9: 0 => ne rien faire / 1 => arrêter de tourner vers la droite


    Private Declare Function RLC_Get_PIO Lib "rlc_arm.dll" (ByVal portNum As Integer) As Integer
    Private Declare Sub RLC_Set_PIO Lib "rlc_arm.dll" (ByVal portNum As Integer, ByVal data As Integer)
    Private Declare Function RLC_SetPWM Lib "rlc_arm.dll" (ByVal channel As Integer, ByVal frequency As Integer, ByVal dutyCycle As Integer) As Boolean
    Private Declare Function RLC_Analog_In Lib "rlc_arm.dll" (ByVal Ch As Int16) As Integer


    Private Const FREQ_COMM As Integer = 10000  'fréquence de commutation
    Private Const DUTYMAX As Integer = 75
    Private Const PORTINTERNET As Integer = 1234


    Private Shared Park As Boolean
    Private Shared AvancerReculer As SByte
    Private AvancerReculerActuel As SByte


    Private Shared GaucheDroite As Short
    Private GaucheDroiteActuel As Short


    Private OutputPins(0 To 1) As Integer


    Private Periodique As Timer
    Private EnvoieAuxClients As Timer


    Private Enum Controleurs
        DIRECT
        TELECOMMANDE
        INTERNET
    End Enum
    'Private Function RLC_Get_PIO(ByVal portNum As Integer) As Integer


    'End Function
    'Private Sub RLC_Set_PIO(ByVal portNum As Integer, ByVal data As Integer)


    'End Sub
    'Private Function RLC_SetPWM(ByVal channel As Integer, ByVal frequency As Integer, ByVal dutyCycle As Integer) As Boolean


    'End Function
    'Private Function rlc_analog_in(ByVal ch As Int16) As Integer


    'End Function
    Private Structure Utilisateur
        Public Client As System.Net.Sockets.TcpClient
        Public Stream As System.Net.Sockets.NetworkStream
    End Structure


    Private Shared Controleur As Controleurs


    Private Shared Serie As System.IO.Ports.SerialPort
    Private PortSerieThread As System.Threading.Thread
    Private Shared Terminer As Boolean


    Private Shared NetEcouteur As System.Net.Sockets.TcpListener
    Private Shared NetClients As System.Collections.Generic.List(Of Utilisateur)
    Private InternetThread As System.Threading.Thread


    Private Sub Controle_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        Terminer = True
        PortSerieThread.Join()
        Serie.Close()
        InternetThread.Join()
    End Sub


    Private Sub Controle_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler Tourne1.Click, AddressOf PeserSurDirection
        AddHandler Tourne2.Click, AddressOf PeserSurDirection
        AddHandler Tourne3.Click, AddressOf PeserSurDirection
        AddHandler Tourne4.Click, AddressOf PeserSurDirection
        AddHandler Tourne5.Click, AddressOf PeserSurDirection


        RLC_SetPWM(1, FREQ_COMM, 100)
        ChoisirControleur.SelectedIndex = 1
        ChoisirControleur_SelectedIndexChanged(Nothing, Nothing)


        Periodique = New Timer
        AddHandler Periodique.Tick, AddressOf OperationsPeriodiques
        Periodique.Interval = 250
        Periodique.Enabled = True


        EnvoieAuxClients = New Timer
        AddHandler EnvoieAuxClients.Tick, AddressOf EnvoyerLesDonnees
        EnvoieAuxClients.Interval = 2500
        EnvoieAuxClients.Enabled = True


        Serie = New System.IO.Ports.SerialPort
        With Serie
            .PortName = "COM2"
            .BaudRate = 9600
            .Parity = IO.Ports.Parity.None
            .DataBits = 8
            .StopBits = IO.Ports.StopBits.One
            .Handshake = IO.Ports.Handshake.None
            .ReadTimeout = 100
            .WriteTimeout = 100
            .Open()
        End With


        Terminer = False
        PortSerieThread = New System.Threading.Thread(AddressOf LirePortSerie)
        PortSerieThread.Start()


        NetEcouteur = New System.Net.Sockets.TcpListener(System.Net.IPAddress.Any, PORTINTERNET)
        NetEcouteur.Start()
        InternetThread = New System.Threading.Thread(AddressOf VerifierConnexionsInternet)
        InternetThread.Start()
    End Sub


    Private Shared Sub VerifierConnexionsInternet()
        NetClients = New System.Collections.Generic.List(Of Utilisateur)
        While Not Terminer


            While NetEcouteur.Pending()
                Dim NouveauClient As Utilisateur = New Utilisateur
                NouveauClient.Client = NetEcouteur.AcceptTcpClient()
                NouveauClient.Stream = NouveauClient.Client.GetStream()
                NetClients.Add(NouveauClient)
            End While


            If Controleur = Controleurs.INTERNET Then
                Dim CeClient As Utilisateur
                For Each CeClient In NetClients
                    Try
                        If CeClient.Stream.DataAvailable Then
                            Dim buf(CeClient.Client.ReceiveBufferSize) As Byte, i As Integer, OctetsRecus As Integer
                            OctetsRecus = CeClient.Stream.Read(buf, 0, buf.Length)


                            For i = 0 To OctetsRecus - 1
                                Select Case buf(i)
                                    Case Asc("P")
                                        AvancerReculer = 0
                                        Park = True
                                    Case Asc("R")
                                        AvancerReculer = -40
                                        Park = False
                                    Case Asc("N")
                                        AvancerReculer = 0
                                        Park = False
                                    Case Asc("D")
                                        AvancerReculer = DUTYMAX
                                        Park = False
                                    Case Asc("1")
                                        AvancerReculer = 30
                                        Park = False
                                    Case Asc("2")
                                        AvancerReculer = 45
                                        Park = False
                                    Case Asc("3")
                                        AvancerReculer = 60
                                        Park = False
                                    Case Asc("H")
                                        GaucheDroite = 2000
                                    Case Asc("J")
                                        GaucheDroite = 1000
                                    Case Asc("K")
                                        GaucheDroite = 0
                                    Case Asc("L")
                                        GaucheDroite = -1000
                                    Case Asc(";")
                                        GaucheDroite = -2000
                                End Select
                            Next i
                        End If
                    Catch Ex As Exception
                        CeClient.Stream.Close()
                        CeClient.Client.Close()
                        CeClient.Stream = Nothing
                        CeClient.Client = Nothing
                        NetClients.Remove(CeClient)
                    End Try
                Next
            End If


            System.Threading.Thread.Sleep(250)
        End While
    End Sub


    Private Shared Sub LirePortSerie()
        Dim Temp As String = ""
        Dim Timeout As Date = Now()


        While Not Terminer            'If (Now() - Timeout).TotalSeconds 10 And Controleur Controleurs.TELECOMMANDE Then
            '    AvancerReculer = 0
            '    GaucheDroite = 0
            'End If
            If Serie.BytesToRead > 0 Then                Dim Avance As SByte 0, Tourne As Short 0
                Dim buf(Serie.BytesToRead - 1) As Byte ', i As Integer
                Serie.Read(buf, 0, buf.Length)
                Temp += System.Text.ASCIIEncoding.ASCII.GetString(buf, 0, buf.Length)
                'Temp = "booEQB03sdafs"
                'MsgBox(Temp)
                If Strings.InStr(Temp, "EQINT") > 0 Then
                    Timeout = Now()
                    Temp = Temp.Replace("EQINT", "")
                End If
                Dim pos As Integer
                pos = Strings.InStr(Temp, "EQB")
                Do
                    If pos - 1 + Len("EQB") + 2 <= Temp.Length Then  'a-t-on reçu une commande complète ?
                        Select Case Temp.Substring(pos + Len("EQB") - 1, 2)
                            Case "O1" 'tout droit
                                Tourne = 1
                            Case "O3" 'mode vitesse r
                                Avance = -50
                                Park = False
                            Case "O4" 'mode vitesse p
                                Avance = 1
                                Park = True
                            Case "O5" 'tourner à gauche
                                Tourne = 1000
                            Case "O6" 'tourner à droite
                                Tourne = -1000
                            Case "O7" 'mode vitesse d
                                Avance = DUTYMAX
                                Park = False
                            Case "OB" 'mode vitesse n
                                Avance = 1
                                Park = False
                            Case "O9" 'à gauche plus
                                Tourne = 2000
                            Case "1O" 'à droite plus
                                Tourne = -2000
                            Case "11" 'mode vitesse 2
                                Avance = 50
                                Park = False
                            Case "12" 'mode vitesse 1
                                Avance = 30
                                Park = False
                            Case "13" 'stop
                                Avance = 1
                                Tourne = 1
                                Park = False
                            Case "16" 'mode vitesse 3
                                Avance = 60
                                Park = False
                        End Select
                        Temp = Temp.Remove(0, pos - 1 + Len("EQB") + 2)
                    End If
                    pos = Strings.InStr(Temp, "EQB")
                Loop While pos > 0


                'For i = 0 To buf.Length
                '    Select Case buf(i)
                '        Case 0 'avancer
                '            Avance = DUTYMAX
                '        Case 1 'reculer
                '            Avance = -DUTYMAX
                '        Case 2 'gauche
                '            Tourne = 1500
                '        Case 3 'droite
                '            Tourne = -1500
                '    End Select
                'Next i


                If Controleur = Controleurs.TELECOMMANDE Then


                    If Avance <> 0 Then
                        If Avance = 1 Then
                            AvancerReculer = 0
                        Else
                            AvancerReculer = Avance
                        End If
                    End If




                    If Tourne <> 0 Then
                        If Tourne = 1 Then
                            GaucheDroite = 0
                        Else
                            GaucheDroite = Tourne
                        End If


                    End If
                End If
            End If
            System.Threading.Thread.Sleep(500)
        End While
    End Sub


    Private Sub SetPinBit(ByVal port As Integer, ByVal bit As Integer)
        OutputPins(port - 1) = OutputPins(port - 1) Or (1 << bit)
        PIO_Parallel_Out(port, OutputPins(port - 1))
    End Sub


    Private Sub ClearPinBit(ByVal port As Integer, ByVal bit As Integer)
        OutputPins(port - 1) = OutputPins(port - 1) And Not (1 << bit)
        PIO_Parallel_Out(port, OutputPins(port - 1))
    End Sub


    Private Sub EnvoyerLesDonnees(ByVal sender As Object, ByVal e As System.EventArgs)
        '    Static SerieCycle As Byte = 0
        '    Select Case SerieCycle
        '        'Case 0
        '        '    Serie.Write("EQV" + Vitesse.Text.PadLeft(3, "0"))
        '        'Case 1
        '        '    Serie.Write("EQR" + CStr(AvancerReculerActuel).PadLeft(3, "0"))
        '        'Case 2
        '        '    Serie.Write("EQ1" + CStr(rlc_analog_in(2)).PadLeft(3, "0"))
        '        'Case 3
        '        '    Serie.Write("EQ2" + CStr(rlc_analog_in(3)).PadLeft(3, "0"))
        '        'Case 4
        '        '    Serie.Write("EQ3" + CStr(rlc_analog_in(4)).PadLeft(3, "0"))
        '    End Select
        '    SerieCycle += 1
        '    If SerieCycle > 4 Then
        '        SerieCycle = 0
        '    End If


        '    Dim EnvoieCECI As Byte() = {0}
        '    EnvoieCECI(0) = CByte(Vitesse.Text)


        '    Dim CeClient As Utilisateur
        '    For Each CeClient In NetClients
        '        Try
        '            CeClient.Stream.Write(EnvoieCECI, 0, 1)
        '        Catch Ex As Exception
        '            CeClient.Stream.Close()
        '            CeClient.Client.Close()
        '            CeClient.Stream = Nothing
        '            CeClient.Client = Nothing
        '            NetClients.Remove(CeClient)
        '        End Try
        '    Next
    End Sub


    Private Sub OperationsPeriodiques(ByVal sender As Object, ByVal e As System.EventArgs)
        'If ((PIO_Parallel_In(2) And &H1) <> 0) And (GaucheDroite > 0 Or GaucheDroiteActuel > 0) Then
        '    GaucheDroite = 0
        '    GaucheDroiteActuel = 0
        '    ClearPinBit(1, 2)
        'End If


        'If (PIO_Parallel_In(2) And &H2) <> 0 And (GaucheDroite < 0 Or GaucheDroiteActuel < 0) Then
        '    GaucheDroite = 0
        '    GaucheDroiteActuel = 0
        '    ClearPinBit(1, 2)   'pin 2 à 0 ==> disable
        'End If


        Dim dV As Short


        If GaucheDroite <> GaucheDroiteActuel Then
            dV = (GaucheDroite - GaucheDroiteActuel) \ 25




            If Math.Abs(GaucheDroite - GaucheDroiteActuel) <= 500 Then
                dV = GaucheDroite - GaucheDroiteActuel
            End If


            If dV = 0 Then
                dV = GaucheDroite - GaucheDroiteActuel
            End If


            GaucheDroiteActuel = GaucheDroiteActuel + dV


            If GaucheDroiteActuel < 500 And GaucheDroiteActuel > 0 Then
                GaucheDroiteActuel = 500
            ElseIf GaucheDroiteActuel > -500 And GaucheDroiteActuel < 0 Then
                GaucheDroiteActuel = -500
            End If
            If GaucheDroiteActuel > 0 Then
                RLC_SetPWM(2, GaucheDroiteActuel, 50)
                'RLC_SetPWM(1, FREQ_COMM, 100 - AvancerReculerActuel)
                ClearPinBit(1, 1)   'pin 1 à 0 ==> gauche
                SetPinBit(1, 2)     'pin 2 à 1 ==> enable
            ElseIf GaucheDroiteActuel < 0 Then
                RLC_SetPWM(2, -GaucheDroiteActuel, 50)
                'RLC_SetPWM(1, FREQ_COMM, 100 - AvancerReculerActuel)
                SetPinBit(1, 1)     'pin 1 à 1 ==> droite
                SetPinBit(1, 2)     'pin 2 à 1 ==> enable
            Else
                ClearPinBit(1, 2)   'pin 2 à 0 ==> disable
            End If
        End If


        If AvancerReculer <> AvancerReculerActuel Then
            dV = (AvancerReculer - AvancerReculerActuel) \ 25


            If dV = 0 Then
                dV = AvancerReculer - AvancerReculerActuel
            End If


            AvancerReculerActuel = AvancerReculerActuel + dV
            If AvancerReculerActuel > 0 Then
                SetPinBit(1, 0)
                RLC_SetPWM(1, FREQ_COMM, 100 - AvancerReculerActuel)
            ElseIf AvancerReculerActuel < 0 Then
                ClearPinBit(1, 0)
                RLC_SetPWM(1, FREQ_COMM, 100 + AvancerReculerActuel)
            Else
                RLC_SetPWM(1, FREQ_COMM, 100)
            End If
        End If


        Vitesse.Text = FormatNumber(CDbl(RLC_Analog_In(0)) * 100 / 1024, 2)
        'Vitesse.Text = RLC_Analog_In(0)


        MetAJourLesBoutons()
    End Sub


    Private Sub ChangeDeDirection(ByVal NouvelleDirection As Short, ByVal Tourner As Boolean)
        If Tourner Then
            GaucheDroite = NouvelleDirection
        Else
            AvancerReculer = NouvelleDirection
        End If


        MetAJourLesBoutons()
    End Sub


    Private Sub MetAJourLesBoutons()
        Select Case GaucheDroite
            Case 0
                PictureBox1.Visible = True
                PictureBox2.Visible = False


                'Volant.Image = 'New Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Interface3.steering_wheel_b.gif"))
            Case Is <= -1500
                PictureBox1.Visible = False
                PictureBox2.Visible = True


                'Volant.Image = 'New Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Interface3.steering_wheel_b_90.gif"))
            Case Is < 0
                PictureBox1.Visible = False
                PictureBox2.Visible = True
                'Volant.Image = 'New Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Interface3.steering_wheel_b_45.gif"))
            Case Is >= 1500
                PictureBox1.Visible = True
                PictureBox2.Visible = False
                'Volant.Image = 'New Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Interface3.steering_wheel_b_-90.gif"))
            Case Is > 0
                PictureBox1.Visible = True
                PictureBox2.Visible = False
                'Volant.Image = 'New Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Interface3.steering_wheel_b_-45.gif"))
        End Select


        Select Case AvancerReculer
            Case 0
                If Park Then
                    Avance.Value = 6
                Else
                    Avance.Value = 4
                End If
            Case 75
                Avance.Value = 3
            Case Is >= 60
                Avance.Value = 0
            Case Is >= 45
                Avance.Value = 1
            Case Is > 0
                Avance.Value = 2
            Case Is < 0
                Avance.Value = 5
        End Select
    End Sub


    'Private Sub ChangeVitesse(ByVal sender As Object, ByVal e As System.EventArgs)
    '    Dim BoutonPese As Windows.Forms.Button = CType(sender, Windows.Forms.Button)
    '    ChangeDeDirection(BoutonPese.Tag, False)
    'End Sub


    Private Sub PeserSurDirection(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim BoutonPese As Windows.Forms.Button = CType(sender, Windows.Forms.Button)
        ChangeDeDirection(BoutonPese.Tag, True)
    End Sub


    Sub PIO_Parallel_Out(ByVal port As Integer, ByVal val As Integer)
        Dim temp As Integer


        temp = Not val
        temp = (temp And &HFF)
        temp = 255 - temp


        RLC_Set_PIO(port, temp)
    End Sub


    Function PIO_Parallel_In(ByVal port As Integer) As Integer
        PIO_Parallel_In = RLC_Get_PIO(port)
    End Function


    Private Sub ChoisirControleur_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChoisirControleur.SelectedIndexChanged
        Select Case ChoisirControleur.SelectedIndex
            Case 0
                Controleur = Controleurs.DIRECT
            Case 1
                Controleur = Controleurs.TELECOMMANDE
            Case 2
                Controleur = Controleurs.INTERNET
        End Select
    End Sub


    Private Sub Avance_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Avance.ValueChanged
        If Not Avance.Value = 6 Then
            Park = False
        End If
        Select Case Avance.Value
            Case 6  'P
                Park = True
                ChangeDeDirection(0, False)
            Case 5  'R
                ChangeDeDirection(-40, False)
            Case 4  'N
                ChangeDeDirection(0, False)
            Case 3  'D
                ChangeDeDirection(75, False)
            Case 2  '1
                ChangeDeDirection(30, False)
            Case 1  '2
                ChangeDeDirection(45, False)
            Case 0  '3
                ChangeDeDirection(60, False)
        End Select
    End Sub


    Private Sub ArreterTout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ArreterTout.Click
        ChangeDeDirection(0, False)
        ChangeDeDirection(0, True)
    End Sub


    Private Sub Logo_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Logo.DoubleClick
        MsgBox("Interface pour voiture électrique" + vbNewLine + _
                "Groupe Équinoxe" + vbNewLine + _
                "Département de génie électrique" + vbNewLine + _
                "Université de Moncton", MsgBoxStyle.Information, "À propos")
    End Sub

ce programme va permettre de commander une voiture electrique
0
mpjp57
Messages postés
18
Date d'inscription
jeudi 13 mars 2008
Statut
Membre
Dernière intervention
23 mai 2008

18 mars 2008 à 15:00
bonjours a tous'.
est ce que quelqu'un sauré comment fair un compteur tour de voiture en visual basic.net.

merci
0