VERSION 5.00
Begin VB.Form frmRobot 
   BorderStyle     =   1  '固定(実線)
   Caption         =   "Robot"
   ClientHeight    =   11355
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   8670
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   11355
   ScaleWidth      =   8670
   StartUpPosition =   3  'Windows の既定値
   Begin VB.CommandButton cmdExit 
      Caption         =   "Exit"
      Height          =   405
      Left            =   7320
      TabIndex        =   6
      Top             =   10800
      Width           =   1215
   End
   Begin VB.Frame Frame2 
      Caption         =   "RobMaster"
      Height          =   9615
      Left            =   120
      TabIndex        =   8
      Top             =   1080
      Width           =   8415
      Begin VB.TextBox txtApproach 
         Height          =   315
         Left            =   5880
         TabIndex        =   79
         Text            =   "1"
         Top             =   4590
         Width           =   825
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Go!"
         Height          =   375
         Index           =   8
         Left            =   7050
         TabIndex        =   77
         Top             =   5640
         Width           =   1215
      End
      Begin VB.TextBox txtDepart 
         Height          =   315
         Left            =   4920
         TabIndex        =   76
         Text            =   "1"
         Top             =   5670
         Width           =   825
      End
      Begin VB.ComboBox cmbDepartComp 
         Height          =   300
         ItemData        =   "Robot.frx":0000
         Left            =   2280
         List            =   "Robot.frx":000A
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   75
         Top             =   5640
         Width           =   735
      End
      Begin VB.ComboBox cmbDepartPath 
         Height          =   300
         ItemData        =   "Robot.frx":0016
         Left            =   4060
         List            =   "Robot.frx":0023
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   74
         Top             =   5670
         Width           =   735
      End
      Begin VB.CheckBox chkNEXT 
         Caption         =   ",NEXT"
         Height          =   225
         Index           =   4
         Left            =   5940
         TabIndex        =   73
         Top             =   5730
         Width           =   1095
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Go!"
         Height          =   375
         Index           =   7
         Left            =   7050
         TabIndex        =   71
         Top             =   5040
         Width           =   1215
      End
      Begin VB.TextBox txtApproachVarIndex 
         Height          =   315
         Left            =   4080
         TabIndex        =   70
         Text            =   "1"
         Top             =   4590
         Width           =   825
      End
      Begin VB.ComboBox cmbApproachComp 
         Height          =   300
         ItemData        =   "Robot.frx":0032
         Left            =   2280
         List            =   "Robot.frx":003C
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   69
         Top             =   4590
         Width           =   735
      End
      Begin VB.ComboBox cmbApproachPath 
         Height          =   300
         ItemData        =   "Robot.frx":0048
         Left            =   5040
         List            =   "Robot.frx":0055
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   68
         Top             =   4590
         Width           =   735
      End
      Begin VB.ComboBox cmbApproachVarType 
         Height          =   300
         ItemData        =   "Robot.frx":0064
         Left            =   3240
         List            =   "Robot.frx":0071
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   67
         Top             =   4590
         Width           =   735
      End
      Begin VB.CheckBox chkNEXT 
         Caption         =   ",NEXT"
         Height          =   225
         Index           =   3
         Left            =   7080
         TabIndex        =   66
         Top             =   4650
         Width           =   1095
      End
      Begin VB.ComboBox cmbSuf 
         Height          =   300
         ItemData        =   "Robot.frx":007E
         Left            =   2280
         List            =   "Robot.frx":0094
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   57
         Top             =   3960
         Width           =   1005
      End
      Begin VB.OptionButton optSuf 
         Caption         =   "Option1"
         Height          =   195
         Index           =   1
         Left            =   1980
         TabIndex        =   56
         Top             =   4020
         Width           =   255
      End
      Begin VB.OptionButton optSuf 
         Caption         =   "Option1"
         Height          =   195
         Index           =   0
         Left            =   1980
         TabIndex        =   55
         Top             =   3570
         Width           =   255
      End
      Begin VB.CheckBox chkNEXT 
         Caption         =   ",NEXT"
         Height          =   255
         Index           =   2
         Left            =   7080
         TabIndex        =   54
         Top             =   3540
         Width           =   975
      End
      Begin VB.CheckBox chkNEXT 
         Caption         =   ",NEXT"
         Height          =   225
         Index           =   1
         Left            =   5940
         TabIndex        =   53
         Top             =   2970
         Width           =   945
      End
      Begin VB.CheckBox chkNEXT 
         Caption         =   ",NEXT"
         Height          =   225
         Index           =   0
         Left            =   5940
         TabIndex        =   52
         Top             =   300
         Width           =   1095
      End
      Begin VB.TextBox txtReply 
         Height          =   435
         Left            =   120
         Locked          =   -1  'True
         TabIndex        =   51
         Top             =   8010
         Width           =   8115
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Execute"
         Height          =   375
         Index           =   9
         Left            =   7080
         TabIndex        =   48
         Top             =   7590
         Width           =   1215
      End
      Begin VB.TextBox txtCommand 
         Height          =   435
         Left            =   120
         TabIndex        =   47
         Text            =   "10004, 1, 1"
         Top             =   7080
         Width           =   8115
      End
      Begin VB.TextBox txtRotDeg 
         Height          =   315
         Left            =   5310
         TabIndex        =   46
         Text            =   "30.0"
         Top             =   3510
         Width           =   615
      End
      Begin VB.TextBox txtV 
         Height          =   315
         Index           =   2
         Left            =   3900
         TabIndex        =   45
         Text            =   "3"
         Top             =   3510
         Width           =   465
      End
      Begin VB.TextBox txtV 
         Height          =   315
         Index           =   1
         Left            =   3210
         TabIndex        =   44
         Text            =   "2"
         Top             =   3510
         Width           =   465
      End
      Begin VB.TextBox txtV 
         Height          =   315
         Index           =   0
         Left            =   2520
         TabIndex        =   43
         Text            =   "1"
         Top             =   3510
         Width           =   465
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Rotate"
         Height          =   375
         Index           =   6
         Left            =   7080
         TabIndex        =   41
         Top             =   3930
         Width           =   1215
      End
      Begin VB.TextBox txtV 
         Height          =   315
         Index           =   3
         Left            =   6150
         TabIndex        =   40
         Text            =   "0"
         Top             =   3510
         Width           =   525
      End
      Begin VB.ComboBox cmbRotAt 
         Height          =   300
         ItemData        =   "Robot.frx":00B3
         Left            =   4560
         List            =   "Robot.frx":00C0
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   39
         Top             =   3510
         Width           =   735
      End
      Begin VB.ComboBox cmbDrvAt 
         Height          =   300
         ItemData        =   "Robot.frx":00CD
         Left            =   3210
         List            =   "Robot.frx":00DA
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   38
         Top             =   2940
         Width           =   735
      End
      Begin VB.ComboBox cmbJn 
         Height          =   300
         ItemData        =   "Robot.frx":00E7
         Left            =   4060
         List            =   "Robot.frx":00F4
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   37
         Top             =   2940
         Width           =   735
      End
      Begin VB.TextBox txtDrvDeg 
         Height          =   315
         Left            =   4920
         TabIndex        =   35
         Text            =   "30.0"
         Top             =   2940
         Width           =   825
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Drive"
         Height          =   375
         Index           =   5
         Left            =   7080
         TabIndex        =   34
         Top             =   2910
         Width           =   1215
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Speed"
         Height          =   375
         Index           =   4
         Left            =   7080
         TabIndex        =   31
         Top             =   2370
         Width           =   1215
      End
      Begin VB.TextBox txtSpeed 
         Height          =   315
         Left            =   4920
         TabIndex        =   30
         Text            =   "80.0"
         Top             =   2400
         Width           =   825
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Decel"
         Height          =   375
         Index           =   3
         Left            =   7080
         TabIndex        =   28
         Top             =   1830
         Width           =   1215
      End
      Begin VB.TextBox txtDecel 
         Height          =   315
         Left            =   4920
         TabIndex        =   27
         Text            =   "50.0"
         Top             =   1860
         Width           =   825
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Accel"
         Height          =   375
         Index           =   2
         Left            =   7080
         TabIndex        =   25
         Top             =   1290
         Width           =   1215
      End
      Begin VB.TextBox txtAccel 
         Height          =   315
         Left            =   4920
         TabIndex        =   24
         Text            =   "50.0"
         Top             =   1320
         Width           =   825
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Change"
         Height          =   375
         Index           =   1
         Left            =   7080
         TabIndex        =   22
         Top             =   750
         Width           =   1215
      End
      Begin VB.TextBox txtChange 
         Height          =   315
         Left            =   4920
         TabIndex        =   21
         Text            =   "1"
         Top             =   780
         Width           =   825
      End
      Begin VB.ComboBox cmbChange 
         Height          =   300
         ItemData        =   "Robot.frx":0101
         Left            =   2280
         List            =   "Robot.frx":010B
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   20
         Top             =   780
         Width           =   1125
      End
      Begin VB.CommandButton cmdRobCancel 
         Caption         =   "Cancel"
         Height          =   375
         Left            =   7080
         TabIndex        =   19
         Top             =   6270
         Width           =   1215
      End
      Begin VB.Timer Timer1 
         Left            =   7920
         Top             =   9090
      End
      Begin VB.ComboBox cmbVarType 
         Height          =   300
         ItemData        =   "Robot.frx":011B
         Left            =   4140
         List            =   "Robot.frx":0128
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   14
         Top             =   240
         Width           =   735
      End
      Begin VB.ComboBox cmbPath 
         Height          =   300
         ItemData        =   "Robot.frx":0135
         Left            =   3210
         List            =   "Robot.frx":0142
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   13
         Top             =   240
         Width           =   735
      End
      Begin VB.ComboBox cmbComp 
         Height          =   300
         ItemData        =   "Robot.frx":0151
         Left            =   2280
         List            =   "Robot.frx":015B
         Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
         TabIndex        =   12
         Top             =   240
         Width           =   735
      End
      Begin VB.TextBox txtVarIndex 
         Height          =   315
         Left            =   4920
         TabIndex        =   4
         Text            =   "1"
         Top             =   240
         Width           =   825
      End
      Begin VB.CommandButton cmdRobMaster 
         Caption         =   "Go!"
         Height          =   375
         Index           =   0
         Left            =   7080
         TabIndex        =   5
         Top             =   210
         Width           =   1215
      End
      Begin VB.Label Label 
         Caption         =   ","
         Height          =   255
         Left            =   4920
         TabIndex        =   80
         Top             =   4680
         Width           =   135
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   10
         X1              =   1200
         X2              =   8280
         Y1              =   5520
         Y2              =   5520
      End
      Begin VB.Label Label8 
         Caption         =   "DEPART"
         Height          =   375
         Left            =   1200
         TabIndex        =   78
         Top             =   5730
         Width           =   5175
      End
      Begin VB.Label Label7 
         Caption         =   "APPROACH"
         Height          =   375
         Left            =   1200
         TabIndex        =   72
         Top             =   4680
         Width           =   5175
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   9
         X1              =   1200
         X2              =   8280
         Y1              =   4440
         Y2              =   4440
      End
      Begin VB.Label Label6 
         Caption         =   ",V"
         Height          =   195
         Index           =   13
         Left            =   5970
         TabIndex        =   65
         Top             =   3570
         Width           =   195
      End
      Begin VB.Label Label6 
         Caption         =   ",V"
         Height          =   195
         Index           =   12
         Left            =   3720
         TabIndex        =   64
         Top             =   3570
         Width           =   195
      End
      Begin VB.Label Label6 
         Caption         =   ",V"
         Height          =   195
         Index           =   11
         Left            =   3030
         TabIndex        =   63
         Top             =   3570
         Width           =   195
      End
      Begin VB.Label Label6 
         Caption         =   "( V"
         Height          =   195
         Index           =   10
         Left            =   2220
         TabIndex        =   62
         Top             =   3570
         Width           =   255
      End
      Begin VB.Label Label6 
         Caption         =   "("
         Height          =   195
         Index           =   9
         Left            =   3940
         TabIndex        =   61
         Top             =   3000
         Width           =   105
      End
      Begin VB.Label Label6 
         Caption         =   ","
         Height          =   195
         Index           =   8
         Left            =   4830
         TabIndex        =   60
         Top             =   3000
         Width           =   75
      End
      Begin VB.Label Label6 
         Caption         =   "),"
         Height          =   195
         Index           =   7
         Left            =   4440
         TabIndex        =   59
         Top             =   3570
         Width           =   105
      End
      Begin VB.Label Label6 
         Caption         =   ")"
         Height          =   195
         Index           =   6
         Left            =   5790
         TabIndex        =   58
         Top             =   3000
         Width           =   105
      End
      Begin VB.Label Label3 
         Caption         =   "Execute :                                                                                     (input with comma separator)"
         Height          =   255
         Index           =   1
         Left            =   150
         TabIndex        =   50
         Top             =   6840
         Width           =   8085
      End
      Begin VB.Label Label4 
         Caption         =   "Reply : "
         Height          =   255
         Index           =   1
         Left            =   120
         TabIndex        =   49
         Top             =   7710
         Width           =   6855
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   8
         X1              =   150
         X2              =   8280
         Y1              =   6750
         Y2              =   6750
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   7
         X1              =   1170
         X2              =   8280
         Y1              =   3390
         Y2              =   3390
      End
      Begin VB.Label Label6 
         Caption         =   " ROTATE"
         Height          =   225
         Index           =   5
         Left            =   1110
         TabIndex        =   42
         Top             =   3570
         Width           =   735
      End
      Begin VB.Label Label6 
         Caption         =   "DRIVEEx"
         Height          =   195
         Index           =   4
         Left            =   1170
         TabIndex        =   36
         Top             =   3000
         Width           =   735
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   6
         X1              =   1170
         X2              =   8280
         Y1              =   2820
         Y2              =   2820
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   5
         X1              =   1170
         X2              =   8280
         Y1              =   2280
         Y2              =   2280
      End
      Begin VB.Label Label6 
         Caption         =   "SPEED"
         Height          =   375
         Index           =   3
         Left            =   1170
         TabIndex        =   32
         Top             =   2460
         Width           =   5175
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   4
         X1              =   1170
         X2              =   8280
         Y1              =   6120
         Y2              =   6120
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   3
         X1              =   1170
         X2              =   8280
         Y1              =   1740
         Y2              =   1740
      End
      Begin VB.Label Label6 
         Caption         =   "DECEL"
         Height          =   375
         Index           =   2
         Left            =   1170
         TabIndex        =   29
         Top             =   1920
         Width           =   5175
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   2
         X1              =   1170
         X2              =   8280
         Y1              =   1200
         Y2              =   1200
      End
      Begin VB.Label Label6 
         Caption         =   "ACCEL"
         Height          =   375
         Index           =   1
         Left            =   1170
         TabIndex        =   26
         Top             =   1380
         Width           =   5175
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   1
         X1              =   1170
         X2              =   8280
         Y1              =   660
         Y2              =   660
      End
      Begin VB.Label Label6 
         Caption         =   "CHANGE"
         Height          =   375
         Index           =   0
         Left            =   1170
         TabIndex        =   23
         Top             =   840
         Width           =   5175
      End
      Begin VB.Label lblPos 
         Caption         =   "P(?,?,?..)"
         Height          =   255
         Left            =   1320
         TabIndex        =   18
         Top             =   9270
         Width           =   6435
      End
      Begin VB.Label lblMoving 
         Caption         =   "?"
         Height          =   255
         Left            =   1290
         TabIndex        =   17
         Top             =   9000
         Width           =   1095
      End
      Begin VB.Label Label5 
         Caption         =   "Position :  "
         Height          =   195
         Left            =   420
         TabIndex        =   16
         Top             =   9300
         Width           =   885
      End
      Begin VB.Label Label1 
         Caption         =   "Moving :  "
         Height          =   225
         Left            =   420
         TabIndex        =   15
         Top             =   9000
         Width           =   885
      End
      Begin VB.Line Line1 
         BorderColor     =   &H8000000C&
         Index           =   0
         X1              =   150
         X2              =   8280
         Y1              =   8520
         Y2              =   8520
      End
      Begin VB.Label lblMove 
         Caption         =   "MOVE "
         Height          =   375
         Left            =   1170
         TabIndex        =   11
         Top             =   300
         Width           =   5175
      End
      Begin VB.Label Label4 
         Caption         =   "Robot Status : "
         Height          =   225
         Index           =   0
         Left            =   150
         TabIndex        =   10
         Top             =   8640
         Width           =   8055
      End
      Begin VB.Label Label3 
         Caption         =   "Command : "
         Height          =   255
         Index           =   0
         Left            =   150
         TabIndex        =   9
         Top             =   300
         Width           =   6765
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Connection"
      Height          =   855
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   8415
      Begin VB.CommandButton cmdConnect 
         Caption         =   "Connect"
         Height          =   375
         Left            =   5760
         TabIndex        =   2
         Top             =   300
         Width           =   1215
      End
      Begin VB.CommandButton cmdDisconnect 
         Caption         =   "Disconnect"
         Height          =   375
         Left            =   7080
         TabIndex        =   3
         Top             =   300
         Width           =   1215
      End
      Begin VB.ComboBox cmbParameter 
         Height          =   300
         Left            =   1320
         TabIndex        =   1
         Top             =   360
         Width           =   4365
      End
      Begin VB.Label Label2 
         Alignment       =   1  '右揃え
         Caption         =   "Parameter : "
         Height          =   255
         Left            =   240
         TabIndex        =   7
         Top             =   360
         Width           =   975
      End
   End
   Begin VB.Label lblDebug 
      Height          =   285
      Left            =   180
      TabIndex        =   33
      Top             =   10920
      Width           =   7065
   End
End
Attribute VB_Name = "frmRobot"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private caoEng As New CaoEngine
Private caoCtrls As CaoControllers
Private WithEvents caoCtrl  As CaoController
Attribute caoCtrl.VB_VarHelpID = -1
Private caoRob  As CaoRobot
Private caoRobVar As CaoVariable
Private caoRobPos As CaoVariable
Const CAO_ONMESS_ROBOT_NOTIFY = 9

Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


' ----------------------------------------------------
Private Sub Form_Load()

    With cmbParameter
        .Clear
        .AddItem "eth:192.168.0.1:4112" ' <- Change this for your controller IP setting. "eth:<controller IP>:4112
        .AddItem "com:1:38400:N:8:1" ' <- Change this for your controller RS-232C setting. "com:<COM port no.>:<speed>:N:8:1"
        .ListIndex = 0
    End With
    
    With cmbComp
        .Clear
        .AddItem "P,"
        .AddItem "L,"
        .ListIndex = 0
    End With
    
    With cmbPath
        .Clear
        .AddItem " "
        .AddItem "@P "
        .AddItem "@E "
        .ListIndex = 0
    End With
    
    With cmbVarType
        .Clear
        .AddItem "P"
        .AddItem "T"
        .AddItem "J"
        .ListIndex = 0
    End With
    
    With cmbChange
        .Clear
        .AddItem "TOOL"
        .AddItem "WORK"
        .ListIndex = 0
    End With
    
    txtVarIndex.Text = "100"
    
    With cmbDrvAt
        .Clear
        .AddItem " "
        .AddItem "@P "
        .AddItem "@E "
        .ListIndex = 0
    
        .ItemData(0) = 0
        .ItemData(1) = -1
        .ItemData(2) = -2
    End With
    With cmbJn
        .Clear
        .AddItem "1"
        .AddItem "2"
        .AddItem "3"
        .AddItem "4"
        .AddItem "5"
        .AddItem "6"
        .AddItem "7"
        .AddItem "8"
        .ListIndex = 0
    End With
    
    With cmbRotAt
        .Clear
        .AddItem " "
        .AddItem "@P "
        .AddItem "@E "
        .ListIndex = 0
    End With

    With cmbSuf
        .ListIndex = 0
    End With

    optSuf(0).Value = True

    With Timer1
        .Enabled = False
        .Interval = 150
    End With
    
    cmdDisconnect_Click

    Set caoEng = New CaoEngine
    Set caoCtrls = caoEng.Workspaces(0).Controllers

End Sub

' ----------------------------------------------------
Private Sub Form_Unload(Cancel As Integer)

    cmdDisconnect_Click
    
    Set caoCtrls = Nothing
    Set caoEng = Nothing
    
End Sub

Private Sub caoCtrl_OnMessage(ByVal pICaoMess As CAOLib.ICaoMessage)

    Static bLock As Boolean
    
    If bLock = True Then Exit Sub
    bLock = True
    With pICaoMess
        If .Number = CAO_ONMESS_ROBOT_NOTIFY Then 'Robot Notify
            DoEvents ' for [Cancel] can be clicked
            Sleep 10 ' *** THIS IS HIGHLY IMPORTANT FOR [cmdRobCancel_Click] !!! ***

            Timer1_Timer ' Update Robot Status on command locking
            lblDebug.Caption = "ROBOT_NOTIFY_ON " + LStr(GetTickCount())
        End If
    End With
    bLock = False
    
End Sub

Private Sub cmdRobCancel_Click()
    caoRob.Halt 'for return from command locking mode
End Sub


' ----------------------------------------------------
Private Sub cmdConnect_Click()

    On Error GoTo ErrProc
    
    Dim sConn As String
    
    cmdDisconnect_Click
    
    sConn = "Conn=" & cmbParameter.Text
    
    Set caoCtrl = caoCtrls.Add("RC1", "CaoProv.DENSO.NetwoRC", "", sConn)
    
    Set caoRob = caoCtrl.AddRobot("RobSlave")
    
    Set caoRobVar = caoRob.AddVariable("@BUSY_STATUS")
    
    Set caoRobPos = caoRob.AddVariable("@CURRENT_POSITION")
    
    
    'Unlock all command buttons
    Dim i%
    For i = cmdRobMaster.LBound To cmdRobMaster.UBound
        cmdRobMaster(i).Enabled = True
    Next i
    cmdRobCancel.Enabled = True
    
    Timer1.Enabled = True
    
    Exit Sub
ErrProc:
    MsgBox Err.Description
    
End Sub

' ----------------------------------------------------
Private Sub cmdDisconnect_Click()

    'Lock all command buttons
    Dim i%
    For i = cmdRobMaster.LBound To cmdRobMaster.UBound
        cmdRobMaster(i).Enabled = False
    Next i
    cmdRobCancel.Enabled = False

    Timer1.Enabled = False

    If Not caoRobPos Is Nothing Then
        Set caoRobPos = Nothing
    End If

    If Not caoRobVar Is Nothing Then
        Set caoRobVar = Nothing
    End If

    If Not caoRob Is Nothing Then
        Set caoRob = Nothing
    End If

    If Not caoCtrl Is Nothing Then
        caoCtrls.Remove caoCtrl.Index
        Set caoCtrl = Nothing
    End If
    
End Sub

' Send a command to "RobSlave.pac" program running into the target controller
Private Sub cmdRobMaster_Click(Index As Integer)

    Dim i%
    Dim sOpt$
    'Lock all command buttons
    For i = cmdRobMaster.LBound To cmdRobMaster.UBound
        cmdRobMaster(i).Enabled = False
    Next i
    cmdRobCancel.Enabled = True

    ' Check if "ROBSLAVE" task is running
    If Not IsRobSlaveRunning() Then
        MsgBox """ROBSLAVE"" task is not running into the controller !"
        GoTo DoExit
    End If

    On Error GoTo ErrProc

    Select Case Index
    Case 0: 'MOVE
        If chkNEXT(0).Value = 1 Then
            caoRob.Move LLng(cmbComp.ListIndex + 1), cmbPath.Text & cmbVarType.Text & txtVarIndex.Text, "NEXT"
        Else
            caoRob.Move LLng(cmbComp.ListIndex + 1), cmbPath.Text & cmbVarType.Text & txtVarIndex.Text
        End If
    Case 1: 'CHANGE
        caoRob.Change cmbChange.Text + txtChange.Text
    Case 2: 'ACCEL
        caoRob.Accelerate LSng(-1), LSng(txtAccel.Text)
    Case 3: 'DECEL
        caoRob.Accelerate LSng(-1), LSng(-1), LSng(txtDecel.Text)   '-1:Do not care
    Case 4: 'SPEED
        caoRob.Speed LSng(-1), LSng(txtSpeed.Text)
    Case 5: 'DRIVEEx
        
        If chkNEXT(1).Value = 1 Then
            caoRob.Execute "DriveEx", Array(cmbDrvAt.Text & "(" & LLng(cmbJn.ListIndex + 1) & "," & LSng(txtDrvDeg.Text) & ")", "NEXT")
        Else
            caoRob.Execute "DriveEx", cmbDrvAt.Text & "(" & LLng(cmbJn.ListIndex + 1) & "," & LSng(txtDrvDeg.Text) & ")"
        End If
    
    Case 6: 'ROTATE
        
        sOpt = Trim(cmbRotAt.Text)
        If chkNEXT(2).Value = 1 Then
            If Len(sOpt) > 0 Then
                sOpt = sOpt + ",NEXT"
            Else
                sOpt = ",NEXT"
            End If
        End If
        
        If (optSuf(0).Value) Then
            ' Vn1,Vn2,Vn3
            caoRob.Rotate txtV(0).Text & "," & txtV(1).Text & "," & txtV(2).Text, LSng(txtRotDeg.Text), txtV(3).Text, sOpt
        Else
            ' XY,YZ,ZX ...
            caoRob.Rotate cmbSuf.Text, LSng(txtRotDeg.Text), txtV(3).Text, sOpt
        End If
    
    Case 7: 'APPROACH
        If chkNEXT(3).Value = 1 Then
            caoRob.Execute "Approach", Array(cmbApproachComp.ItemData(cmbApproachComp.ListIndex), _
                                             cmbApproachVarType.List(cmbApproachVarType.ListIndex) & txtApproachVarIndex.Text, _
                                             cmbApproachPath.List(cmbApproachPath.ListIndex) & " " & txtApproach.Text, _
                                             "NEXT")
        Else
            caoRob.Execute "Approach", Array(cmbApproachComp.ItemData(cmbApproachComp.ListIndex), _
                                             cmbApproachVarType.List(cmbApproachVarType.ListIndex) & txtApproachVarIndex.Text, _
                                             cmbApproachPath.List(cmbApproachPath.ListIndex) & " " & txtApproach.Text)
        End If
    
    Case 8: 'DEPART
        If chkNEXT(4).Value = 1 Then
            caoRob.Execute "Depart", Array(cmbDepartComp.ItemData(cmbDepartComp.ListIndex), _
                                           cmbDepartPath.List(cmbDepartPath.ListIndex) & " " & txtDepart.Text, _
                                           "NEXT")
        Else
            caoRob.Execute "Depart", Array(cmbDepartComp.ItemData(cmbDepartComp.ListIndex), _
                                           cmbDepartPath.List(cmbDepartPath.ListIndex) & " " & txtDepart.Text)
        End If
    
    Case 9: 'CaoRobot.Execute
        RobotExecute
    End Select
    
DoExit:
    'Unlock all command buttons
    For i = cmdRobMaster.LBound To cmdRobMaster.UBound
        cmdRobMaster(i).Enabled = True
    Next i
    cmdRobCancel.Enabled = True
    Exit Sub

ErrProc:
    MsgBox Err.Description
    GoTo DoExit
    
End Sub

' ----------------------------------------------------
Private Sub RobotExecute()
    
    On Error GoTo ErrProc

    Dim vCmd As Variant
    Dim vReply As Variant
    Dim vTmp As Variant
    
    vCmd = Split(txtCommand.Text, ",")
    
    Dim vaCmd() As Variant
    Dim l As Long
    
    ReDim vaCmd(0 To UBound(vCmd))
    l = 0
    For Each vTmp In vCmd
        vaCmd(l) = LVar(Trim(vTmp))
        l = l + 1
    Next
    vCmd = vaCmd
    vReply = caoRob.Execute("UserExt", vCmd)
    
    Dim sReply$
    
    sReply = LStr(Now) + " : "
    If IsEmpty(vReply) Then
        sReply = "(No Return)"
    Else
        For Each vTmp In vReply
            sReply = sReply + LStr(vTmp) + ","
        Next
    End If
    
    txtReply.Text = sReply
    Exit Sub
    
ErrProc:
    txtReply.Text = "ERROR!"
    MsgBox Err.Description
    
End Sub

' ----------------------------------------------------
Private Sub cmdExit_Click()

    Unload Me
    
End Sub

Private Sub cmbSuf_Click()

    optSuf(0).Value = False
    optSuf(1).Value = True
    
End Sub


'Update Robot Status
Private Sub Timer1_Timer()

    'Moving = True / False
    If Not caoRobVar Is Nothing Then
        lblMoving.Caption = LStr(caoRobVar.Value)
    End If
    'Current Position
    If Not caoRobPos Is Nothing Then
        Dim vPos As Variant
        vPos = caoRobPos.Value
        
        Dim i%, imin%, imax%
        imin = LBound(vPos): imax = UBound(vPos)
        lblPos.Caption = "P( "
        For i = imin To imax - 1
            lblPos.Caption = lblPos.Caption + LStr(Format(vPos(i), "0.0#")) + ", "
        Next
        lblPos.Caption = lblPos.Caption + LStr(Format(vPos(imax), "0.0#")) + " )"
    End If
    
End Sub

' Check if "ROBSLAVE" task is running
Private Function IsRobSlaveRunning() As Boolean

    IsRobSlaveRunning = False
    Dim Task As CaoTask
    Dim Var As CaoVariable
    
    On Error GoTo ErrExit
    
    Set Task = caoCtrl.AddTask("ROBSLAVE")
    Set Var = Task.AddVariable("@STATUS")
    
    If Var.Value = 3 Then 'Running
        IsRobSlaveRunning = True
    End If
    
    Task.Variables.Remove Var.Index
    caoCtrl.Tasks.Remove Task.Index
    
    Exit Function
ErrExit:
    
End Function

'-----------------------------------------------------------
Public Function LLng(ByRef expression) As Long
    
    LLng = CLng(Val(expression))

End Function

'-----------------------------------------------------------------------------
Public Function LInt(ByRef expression) As Integer
    
    LInt = CInt(Val(expression))

End Function

'-----------------------------------------------------------------------------
Public Function LByte(ByRef expression) As Byte
    
    LByte = CByte(Val(expression))

End Function

'-----------------------------------------------------------------------------
Public Function LDbl(ByRef expression) As Double
    
    LDbl = CDbl(Val(expression))

End Function

'-----------------------------------------------------------------------------
Public Function LSng(ByRef expression) As Single
    
    LSng = CSng(Val(expression))

End Function

'-----------------------------------------------------------------------------
Public Function LBool(ByRef expression) As Boolean
    
    LBool = CBool(Val(expression))

End Function

'-----------------------------------------------------------------------------
Public Function LVar(ByRef expression) As Variant
    
    LVar = CVar(Val(expression))

End Function

'-----------------------------------------------------------
Public Function LStr(ByRef expression) As String
    
    On Error Resume Next
    
    LStr = expression
    LStr = LTrim$(Str(expression))

End Function


