作者wufumin (黑狼)
看板Visual_Basic
标题[VB6 ] RS232驱动步进马达的问题
时间Thu May 29 16:59:31 2008
各位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