0

我正在尝试编写一个 LotusScript 来控制电机。我用于阅读这些位的脚本似乎工作正常,但我希望添加一个停止按钮。我拥有使设备停止的所有命令,但我遇到的问题是,每当 LotusScript 循环运行时,我都无法单击任何其他按钮。

有谁知道解决这个问题的方法???

我正在使用的脚本如下。

非常感谢你。

安迪·巴洛

Sub 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

结束子

应该工作的停止按钮应该是... Object btnStop

Sub Click(Source As Buttoncontrol) REM 初始化句柄 = 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)

结束子

4

2 回答 2

1

您没有在线程环境中运行 Lotusscript,那么您如何期望按钮上的代码停止已经运行的代码?

于 2010-03-03T01:51:05.090 回答
1

如果您希望能够取消循环,则需要使用计时器对象。基本上,您开始执行循环的一次迭代。在开始时,您查找更改的字段值或 ini 变量以取消计时器(如果已设置)。现在您可以使用按钮设置该变量。循环将比没有计时器时运行得慢得多(毕竟它有你设置的等待间隔)

于 2010-03-05T04:07:55.103 回答