Knop omzeilen.

  • Onderwerp starter Onderwerp starter Desk
  • Startdatum Startdatum
Status
Niet open voor verdere reacties.

Desk

Gebruiker
Lid geworden
26 jan 2009
Berichten
13
Ik heb een stukje programma dat bij stappenmotor hardware hoort.
Nu moet ik in een form op een knop drukken om de motor te initialiseren.
Hoe kan ik die knop omzeilen, zodat het programma direct doorloopt en zelf de motor initialiseert?


Code:
 Declare Function InitStp Lib "stp.dll" () As Integer
    Declare Function RunMotor1 Lib "stp.dll" (ByVal steps As Integer, ByVal interval As Integer, ByVal direction As Integer, ByVal outputs As Integer) As Boolean
    Declare Function RunMotor2 Lib "stp.dll" (ByVal steps As Integer, ByVal interval As Integer, ByVal direction As Integer, ByVal outputs As Integer) As Boolean
    Declare Function StopMotor1 Lib "stp.dll" (ByVal outputs As Integer) As Boolean
    Declare Function StopMotor2 Lib "stp.dll" (ByVal outputs As Integer) As Boolean
    Declare Function SetStepMode Lib "stp.dll" (ByVal M1Mode As Integer, ByVal M2Mode As Integer) As Boolean
    Declare Function GetCurrentStatus Lib "stp.dll" (ByRef M1Active As Integer, ByRef M2Active As Integer, ByRef M1Steps As Integer, ByRef M2Steps As Integer, ByRef Inputs As Integer) As Boolean

Het gaat om dit stukje:

    'Initialise StepperBee. This must be called before any of the other functions.
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      InitStp()  
End Sub
 
Laatst bewerkt:
Ik heb een stukje programma dat bij stappenmotor hardware hoort.
Nu moet ik in een form op een knop drukken om de motor te initialiseren.
Hoe kan ik die knop omzeilen, zodat het programma direct doorloopt en zelf de motor initialiseert?


Code:
 Declare Function InitStp Lib "stp.dll" () As Integer
    Declare Function RunMotor1 Lib "stp.dll" (ByVal steps As Integer, ByVal interval As Integer, ByVal direction As Integer, ByVal outputs As Integer) As Boolean
    Declare Function RunMotor2 Lib "stp.dll" (ByVal steps As Integer, ByVal interval As Integer, ByVal direction As Integer, ByVal outputs As Integer) As Boolean
    Declare Function StopMotor1 Lib "stp.dll" (ByVal outputs As Integer) As Boolean
    Declare Function StopMotor2 Lib "stp.dll" (ByVal outputs As Integer) As Boolean
    Declare Function SetStepMode Lib "stp.dll" (ByVal M1Mode As Integer, ByVal M2Mode As Integer) As Boolean
    Declare Function GetCurrentStatus Lib "stp.dll" (ByRef M1Active As Integer, ByRef M2Active As Integer, ByRef M1Steps As Integer, ByRef M2Steps As Integer, ByRef Inputs As Integer) As Boolean

Het gaat om dit stukje:

    'Initialise StepperBee. This must be called before any of the other functions.
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      InitStp()  
End Sub

als je wil dat het programma iets doet gelijk bij het opstarten moet je het tussen
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
doen (bij vb8)
ik hoop dat dit hielp.
MVG,
gabber1
 
Fantastisch, werkt als een trein!!!
Bedankt!!!

Kan zoiets ook met de RUN knop voor de motor, zodat ik van de startknop af ben?

Code:
 ' Run Motor 1 according to supplied parameters
    Private Sub Run1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Run1.Click
        Dim steps As Integer
        Dim interval As Integer
        Dim direction As Integer
        Dim outputs As Integer

        steps = 100
        interval = 5
        direction = 1

        ' all parameters have now been specified so send the run command to motor1
        RunMotor1(steps, interval, direction, outputs)
End Sub
 
Laatst bewerkt:
Ik ben absolute beginner en richt mij op de hardware ontwikkeling.
Het is daarom fantastisch dat ik zo geholpen kan worden.
Hierboven staat en dergelijk vraagje over de RUN knop.
Dat gaat waarschijnlijk precies zo.
 
Laatst bewerkt:
Voor motor 1 is het zo opgelost, die loopt zonder op een knop te drukken.
Motor twee lukt mij niet.
als ik de Form elementen weg haal werkt het niet.
Ik wil eigenlijk van dat ding af.

Code:
 ' Run Motor 1 according to supplied parameters

    Private Sub Run1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim steps As Integer
        Dim interval As Integer
        Dim direction As Integer
        Dim outputs As Integer

        steps = 100
        interval = 5
        direction = 1

        ' all parameters have now been specified so send the run command to motor1
        RunMotor1(steps, interval, direction, outputs)

    End Sub

    ' Run Motor 2 according to supplied parameters

    Private Sub Run2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Run2.Click
        Dim steps As Integer
        Dim interval As Integer
        Dim direction As Integer
        Dim outputs As Integer

        steps = 1
        interval = 5
        direction = 1

        ' all parameters have now been specified so send the run command to motor2
        RunMotor2(steps, interval, direction, outputs)
 
Laatst bewerkt:
Voor motor 1 is het zo opgelost, die loopt zonder op een knop te drukken.
Motor twee lukt mij niet.

Code:
 ' Run Motor 1 according to supplied parameters

    Private Sub Run1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim steps As Integer
        Dim interval As Integer
        Dim direction As Integer
        Dim outputs As Integer

        steps = 100
        interval = 5
        direction = 1

        ' all parameters have now been specified so send the run command to motor1
        RunMotor1(steps, interval, direction, outputs)

    End Sub

    ' Run Motor 2 according to supplied parameters

    Private Sub Run2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Run2.Click
        Dim steps As Integer
        Dim interval As Integer
        Dim direction As Integer
        Dim outputs As Integer

        steps = 1
        interval = 5
        direction = 1

        ' all parameters have now been specified so send the run command to motor2
        RunMotor2(steps, interval, direction, outputs)

Ik kan niet uit zekerheid spreken maar noem bij motor 2 de integers is anders zoals
Code:
Dim steps2 As Integer
        Dim interval2 As Integer
        Dim direction2 As Integer
        Dim outputs2 As Integer
vergeet
Code:
RunMotor2(steps, interval, direction, outputs)
dit niet aan te passen
 
Als ik dat doe
Code:
 ' Run Motor 2 according to supplied parameters

    Private Sub Run1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Private Sub Run2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Run2.Click
        Dim steps2 As Integer
        Dim interval2 As Integer
        Dim direction2 As Integer
        Dim outputs2 As Integer

        steps2 = 1
        interval2 = 5
        direction2 = 1

        ' all parameters have now been specified so send the run command to motor2
        RunMotor2(steps2, interval2, direction2, outputs2)

    End Sub

Dan krijg ik deze foutmelding

Error 1 'Private Sub Run1_Click(sender As Object, e As System.EventArgs)' has multiple definitions with identical signatures.
 
Voor motor 1 is het zo opgelost, die loopt zonder op een knop te drukken.
Motor twee lukt mij niet.
als ik de Form elementen weg haal werkt het niet.
Ik wil eigenlijk van dat ding af.

Code:
 ' Run Motor 1 according to supplied parameters

    Private Sub Run1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim steps As Integer
        Dim interval As Integer
        Dim direction As Integer
        Dim outputs As Integer

        steps = 100
        interval = 5
        direction = 1

        ' all parameters have now been specified so send the run command to motor1
        RunMotor1(steps, interval, direction, outputs)

    End Sub

    ' Run Motor 2 according to supplied parameters

    Private Sub Run2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Run2.Click
        Dim steps As Integer
        Dim interval As Integer
        Dim direction As Integer
        Dim outputs As Integer

        steps = 1
        interval = 5
        direction = 1

        ' all parameters have now been specified so send the run command to motor2
        RunMotor2(steps, interval, direction, outputs)

mischien is dit het

Code:
 Run Motor 1 according to supplied parameters

    Private Sub Run1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim steps As Integer
        Dim interval As Integer
        Dim direction As Integer
        Dim outputs As Integer

        steps = 100
        interval = 5
        direction = 1

        ' all parameters have now been specified so send the run command to motor1
        RunMotor1(steps, interval, direction, outputs)

    End Sub

    ' Run Motor 2 according to supplied parameters

    Private Sub Run2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) handles MyBase.Load
        Dim steps As Integer
        Dim interval As Integer
        Dim direction As Integer
        Dim outputs As Integer

        steps = 1
        interval = 5
        direction = 1

        ' all parameters have now been specified so send the run command to motor2
        RunMotor2(steps, interval, direction, outputs)
 
Perfect!!!
Bedankt voor de snelle hulp.
Het werkt als een zonnetje.
 
aangezien de vraag is opgelost graag even op "vraag is opgelost" rechtonsder te klikken.

MVG,
gabber1
 
Was gisteren al gedaan.
Het staat ook vaag, maar ik heb er nog een keer op gedrukt.
 
Twee stappenmotoren worden aangestuurd vanuit VB2008.
Dat werkt (dankzij Gabber) nu prima.
Maar, als ik vervolgens de status van de motoren wil uitlezen, lopen de motoren niet meer.
Het programma zelf loopt wel door want ik hoor de Beep.
En als ik voor While Motor#Active een nul invoer, blijft het programma keurig wachten.

Code:
 ' Run Motor 2 according to supplied parameters
    Private Sub Run2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim steps As Integer
        Dim interval As Integer
        Dim direction As Integer
        Dim outputs As Integer

        steps = 1
        interval = 5
        direction = 1

        ' all parameters have now been specified so send the run command to motor2
        RunMotor2(steps, interval, direction, outputs)

    End Sub

    'get the current status of both motors 
    Private Sub GetMotorStatus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Motor1Active, Motor2Active, Motor1StepsLeft, Motor2StepsLeft, DigitalInputs As Integer

        ' get the status into the local variables passed by reference
        GetCurrentStatus(Motor1Active, Motor2Active, Motor1StepsLeft, Motor2StepsLeft, DigitalInputs)

        'if motor 1 is still active then hold program
        While Motor1Active = 1
        End While

        'if motor 2 is still active then hold program
        While Motor2Active = 1
        End While

        Beep()


    End Sub
 
Opgelost, alles in één sub gezet
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan