[VB6 ] RS232驅動步進馬達的問題
各位VB界的先進好:
目前學生在寫透過RS232來驅動步進馬達
基本上已經可以做來回掃描
但由於一些需求 必須在馬達來回移動期間能夠每隔一段時間做延遲
比方 馬達前進每格3秒後停滯1秒 並以此前提做來回移動
學生也嘗試用以下指令
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Call Sleep(延遲時間)
但只能在兩端點作延遲 移動路徑上卻沒有
以下為原始的程式碼 希望先進們可以給予指導 謝謝
----------------------------------------------------------------------
Private Sub cmdStart_Click()
If cmdStart.Caption = "Start" Then
' set the cycle timer to the indicated values and start the timer
tmrCycle0.Enabled = True
cmdStart.Caption = "Stop"
Else
' stop timer
tmrCycle0.Enabled = False
cmdStart.Caption = "Start"
End If
End Sub
Sub Delay(d)
' wait for d seconds
t = Timer
While (Timer - t) < d
Wend
End Sub
Private Sub tmrCycle0_Timer()
tmrCycle0.Interval = Val(txtPeriod(0).Text) / 2
If Check1(0) Then CycleUpdate (0)
End Sub
Sub CycleUpdate(i As Integer)
If n(i) = 0 Then
'send command to extend to range
comboUnitNum.Text = Str(i + 1)
comboCommandNum.Text = "20"
txtData.Text = txtRange(i).Text
Call Send
n(i) = 1
Else
'send command to retract to zero
comboUnitNum.Text = Str(i + 1)
comboCommandNum.Text = "20"
txtData.Text = txtStartPos(i).Text
Call Send
n(i) = 0
End If
End Sub
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.130.91.186