2010-02-18 8 views
0

J'essaie d'écrire un LotusScript pour contrôler un moteur. Le script que j'ai pour lire les bits semble bien fonctionner, mais je souhaite ajouter un bouton d'arrêt. J'ai toutes les commandes pour arrêter le périphérique, mais le problème est que lorsque LotusScript exécute une boucle, je ne peux pas cliquer sur l'un des autres boutons.Pourquoi ce LotusScript s'arrête-t-il pendant une boucle?

Est-ce que quelqu'un sait un moyen de contourner cela ???

Les scripts que j'utilise sont ci-dessous.

Merci beaucoup.

Andy Barlow

Sous readpositionsub Dim send_string As String
Dim readString As String Dim tempString As String readString = ""

REM Sets the "movement" cell to 6 (the movement int) 
[b1].contents = "6" 
Do While [b1].contents <> "7" 

    readString = "" 
    statusBitString = "" 

    REM READ STATUS ===!!!=== 
    REM Open the handle to the motor 
    handle = init_RS232(19200) 
    REM #1$ reads the status from the controller. 
    send_string = "#1$"+Chr$(13) 
    REM Ask the controller to store the results in bits 
    resultStatus=write_RS232 (handle,send_string) 

    REM Read Status by looping through all of the bits 
    For n=0 To 8 
     tempString = "*1234567" 
     sendReadCommand = read_RS232(handle,tempString) 
     If Mid(tempString,1,1) = Chr$(13) Then 
      Exit For 
     Else 
      statusBitString = statusBitString + Mid(tempString,1,1) 
     End If 

    Next 
    [b1].contents = Mid(statusBitString,7, 1) 
    close_RS232(handle) 
    REM End Read Status 



    REM READ POSITION ===!!!=== 
    REM Open the handle to the motor 
    handle = init_RS232(19200) 
    send_string = "#1C"+Chr$(13) 
    t=write_RS232 (handle,send_string) 
    REM Reading Position 
    For n=0 To 20 
     tempString = "*1234567" 
     r = read_RS232(handle,tempString) 
     If Mid(tempString,1,1) = Chr$(13) Then 
      Exit For 
     Else 
      readString = readString + Mid(tempString,1,1) 

     End If 

    Next 
    REM End Read Position 
    [a1].contents=Mid(readString, 4) 
    close_RS232(handle) 

Loop 

End Sub

et le bouton d'arrêt cela devrait fonctionner devrait être ... Objet btnStop

Sub Cliquez (Source Comme ButtonControl) REM handle = initialisez init_RS232 (19200)

REM Create the string for starting the motor 
send_string = "#1S"+Chr$(13) 

REM Send the string for starting the motor 
resultStartMotor=write_RS232 (handle,send_string) 

REM Close the spin handle 
close_RS232(handle) 

End Sub

Répondre

1

Vous n'êtes pas en cours d'exécution de votre Lotusscript dans un environnement threadées, comment voulez-vous le code sur un bouton pour arrêter le code en cours d'exécution?

1

Si vous voulez pouvoir annuler une boucle, vous devez jouer avec l'objet timer. Fondamentalement, vous démarrez une heure qui exécute une itération de votre boucle. Au début, vous recherchez une valeur de champ modifiée ou une variable ini pour annuler la temporisation si elle est définie. Maintenant, vous pouvez utiliser votre bouton pour définir cette variable. La boucle fonctionnera beaucoup plus lentement que sans minuterie (après tout, elle a un intervalle d'attente que vous avez défini)