Re: [VB6 ] 該怎麼寫程式驅動x-y table
※ 引述《jiasing (福小興)》之銘言:
: 請問有人知道該怎麼寫程式去經過一個控制器來驅動x-y table嗎?
: 現在的情況是廠商有寫給一個表單來驅動
: 但是只能一個指令一個動作
: 不能走完一個我要的路徑
: 很困擾我= =
: 原本以為像CNC洗床一樣輸入絕對座標...等就可以走我要的路徑
: 請問有人會嗎?
廠商寫的是
Private Sub Command1_Click()
Call def
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Label3.Caption = "X軸座標:0 Y軸座標:0"
x_l = 38
y_l = 20
Xsize = Picture1.Width / 38
Ysize = Picture1.Height / 20
Slider2.Max = 38
Slider1.Max = 20
Line2.X1 = 0
Line2.Y1 = 0
Line2.X2 = Picture1.Width
Line2.Y2 = 0
Line1.X1 = 0
Line1.Y1 = 0
Line1.X2 = 0
Line1.Y2 = Picture1.Height
MSComm1.CommPort = 1
MSComm1.PortOpen = True
trun(0) = 254
trun(1) = 253
trun(2) = 251
trun(3) = 247
'MSComm1.RThreshold = 1
'MSComm1.InputMode = comInputModeBinary
End Sub
Private Sub delay()
Dim detime As Long
Do While (detime < 15000)
detime = detime + 1
Loop
End Sub
Private Sub leftrun()
Dim str As String
Dim i, j As Integer
'If flag = True Then
'str = "A"
'Else
'str = "B"
'End If
Do While (reg <> 0)
For i = 0 To 3
motor(0) = trun(i)
MSComm1.Output = flag
MSComm1.Output = motor
Call delay
Next i
reg = reg + 1
j = j + 1
If j = 50 Then
j = 0
Select Case flag
Case "A"
Slider2.Value = Slider2.Value - 1
Line1.X1 = Slider2.Value * Xsize
Line1.X2 = Slider2.Value * Xsize
Line1.Y1 = 0
Line1.Y2 = Picture1.Height
Case "B"
Slider1.Value = Slider1.Value - 1
Line2.Y1 = Slider1.Value * Ysize
Line2.Y2 = Slider1.Value * Ysize
Line2.X1 = 0
Line2.X2 = Picture1.Width
End Select
End If
Loop
Label3.Caption = "X軸座標:" & Slider2.Value & "Y軸座標:" & Slider1.Value
Call delay
End Sub
Private Sub rightrun()
Dim i, j As Integer
Dim str As String
'If flag = True Then
'str = "A"
'Else
'str = "B"
'End If
Do While (reg <> 0)
For i = 3 To 0 Step -1
motor(0) = trun(i)
MSComm1.Output = flag
MSComm1.Output = motor
Call delay
Next i
reg = reg - 1
j = j + 1
If j = 50 Then
j = 0
Select Case flag
Case "A"
Slider2.Value = Slider2.Value + 1
Line1.X1 = Slider2.Value * Xsize
Line1.X2 = Slider2.Value * Xsize
Line1.Y1 = 0
Line1.Y2 = Picture1.Height
Case "B"
Slider1.Value = Slider1.Value + 1
Line2.Y1 = Slider1.Value * Ysize
Line2.Y2 = Slider1.Value * Ysize
Line2.X1 = 0
Line2.X2 = Picture1.Width
End Select
End If
Loop
Label3.Caption = "X軸座標:" & Slider2.Value & Space(2) & "Y軸座標:" & Slider1.Value
Call delay
End Sub
Private Sub def()
If Text1.Text = "" And Text2.Text <> "" Then
If Val(Text2.Text) > (Slider1.Max - Slider1.Value) Or (Slider1.Value + Val(Text2.Text)) < Slider1.Min Then
MsgBox "超過極限值"
Exit Sub
End If
reg = Val(Text2.Text) * 50
flag = "B"
If reg < 0 Then
Call leftrun
Else
Call rightrun
End If
End If
If Text2.Text = "" And Text1.Text <> "" Then
If Val(Text1.Text) > (Slider2.Max - Slider2.Value) Or (Slider2.Value + Val(Text1.Text)) < Slider2.Min Then
MsgBox "超過極限值"
Exit Sub
End If
reg = Val(Text1.Text) * 50
flag = "A"
If reg < 0 Then
Call leftrun
Else
Call rightrun
End If
End If
'reg = Val(Text1.Text) * 50
'
'If reg < 0 Then
'Call leftrun
'Else
'Call rightrun
'End If
If Text1.Text <> "" And Text2.Text <> "" Then
If Val(Text2.Text) > (Slider1.Max - Slider1.Value) Or (Slider1.Value + Val(Text2.Text)) < Slider1.Min Then
MsgBox "超過極限值"
Exit Sub
End If
If Val(Text1.Text) > (Slider2.Max - Slider2.Value) Or (Slider2.Value + Val(Text1.Text)) < Slider2.Min Then
MsgBox "超過極限值"
Exit Sub
End If
reg = Val(Text1.Text) * 50
flag = "A"
If reg < 0 Then
Call leftrun
Else
Call rightrun
End If
Call delay
reg = Val(Text2.Text) * 50
flag = "B"
If reg < 0 Then
Call leftrun
Else
Call rightrun
End If
End If
End Sub
Private Sub sy()
End Sub
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 211.74.193.19
討論串 (同標題文章)