ST5驅動器-VB介面範例



ST5驅動器 VB介面 範例


'= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
'             建立通訊連接
'= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Private Sub Form_Load()
If (MSComm1.PortOpen = True) Then MSComm1.PortOpen = False
MSComm1.CommPort = Combo1.Text            ‘Choose comport
MSComm1.PortOpen = True
MSComm1.Settings = "9600,N,8,1"
End Sub
'= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
'                 設定原點
'= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Private Sub SetZeroPosition_Click()
MSComm1.Output = "SP0" & Chr(13)             'Set Absolute Position
End Sub
'= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
'             開始位置移動
'= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Private Sub GO_Click()
MSComm1.Output = "EG" & eg.Text & Chr(13)      'Electronic Gearing
MSComm1.Output = "AC" & acc.Text & Chr(13)     'Accel Rate
MSComm1.Output = "DE" & dec.Text & Chr(13)     'Decel Rate
MSComm1.Output = "VE" & vel.Text & Chr(13)      'Velocity Setting (For Feed Commands)
MSComm1.Output = "FP" & dis.Text & Chr(13)      'Feed to Position
End Sub

'= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
'            調整原點位置(JOG指令)
'
'        jogPositive -->  Close
'        jogNegative -->  Open
'
'  動作描述:按住按鈕移動,放開即停止
'= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Private Sub jogPositive_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MSComm1.Output = "JA10" & Chr(13)       'Jog Accel/Decel rate
MSComm1.Output = "JL10" & Chr(13)       'Jog Decel rate
MSComm1.Output = "JS0" & Chr(13)        'Jog Speed (不可為負值 -> 不可改方向)
MSComm1.Output = "CJ" & Chr(13)         'Commence Jogging
MSComm1.Output = "CS1" & Chr(13)        'Change Speed (可為負值 -> 可改方向)
End Sub

Private Sub jogPositive_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
MSComm1.Output = "SJ" & Chr(13)          'Stop Jogging
End Sub

Private Sub jogNegative_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) 
MSComm1.Output = "JA10" & Chr(13)       'Jog Accel/Decel rate
MSComm1.Output = "JL10" & Chr(13)        'Jog Decel rate
MSComm1.Output = "JS0" & Chr(13)         'Jog Speed
MSComm1.Output = "CJ" & Chr(13)          'Commence Jogging
MSComm1.Output = "CS-1" & Chr(13)        'Change Speed
End Sub

Private Sub jogNegative_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) 
MSComm1.Output = "SJ" & Chr(13)           'Stop Jogging
End Sub