VERSION 5.00
Begin VB.Form frmVPSTester 
   Caption         =   "VPS Tester"
   ClientHeight    =   6300
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   8190
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   ScaleHeight     =   6300
   ScaleWidth      =   8190
   StartUpPosition =   3  'Windows の既定値
   Begin VB.CommandButton cmdClear 
      Caption         =   "Clear"
      Height          =   315
      Left            =   6870
      TabIndex        =   27
      Top             =   120
      Width           =   1155
   End
   Begin VB.ListBox lstMessage 
      Height          =   5640
      Left            =   4230
      TabIndex        =   26
      Top             =   480
      Width           =   3765
   End
   Begin VB.Frame Frame4 
      Caption         =   "Execute"
      Height          =   1095
      Left            =   150
      TabIndex        =   20
      Top             =   5010
      Width           =   3975
      Begin VB.CommandButton cmdExecute 
         Caption         =   "Execute"
         Height          =   315
         Left            =   2550
         TabIndex        =   23
         Top             =   630
         Width           =   1155
      End
      Begin VB.TextBox txtExePara 
         Height          =   285
         Left            =   1110
         TabIndex        =   21
         Text            =   "010A0201000000FF"
         Top             =   240
         Width           =   2595
      End
      Begin VB.Label Label6 
         Alignment       =   1  '右揃え
         Caption         =   "Parameter :"
         Height          =   195
         Left            =   120
         TabIndex        =   22
         Top             =   300
         Width           =   915
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Variable"
      Height          =   2805
      Left            =   150
      TabIndex        =   8
      Top             =   2070
      Width           =   3975
      Begin VB.CommandButton cmdPutVal 
         Caption         =   "Put"
         Height          =   315
         Left            =   1260
         TabIndex        =   19
         Top             =   2340
         Width           =   1155
      End
      Begin VB.CommandButton cmdGetVal 
         Caption         =   "Get"
         Height          =   315
         Left            =   2550
         TabIndex        =   18
         Top             =   2340
         Width           =   1155
      End
      Begin VB.TextBox txtValue 
         Alignment       =   1  '右揃え
         Height          =   270
         Left            =   1140
         TabIndex        =   16
         Text            =   "500"
         Top             =   1920
         Width           =   1275
      End
      Begin VB.Frame Frame3 
         Caption         =   "Name"
         Height          =   1515
         Left            =   120
         TabIndex        =   9
         Top             =   300
         Width           =   3735
         Begin VB.CommandButton cmdVarAdd 
            Caption         =   "Add"
            Height          =   315
            Left            =   1140
            TabIndex        =   29
            Top             =   1050
            Width           =   1155
         End
         Begin VB.CommandButton cmdVarRemove 
            Caption         =   "Remove"
            Height          =   315
            Left            =   2430
            TabIndex        =   24
            Top             =   1050
            Width           =   1155
         End
         Begin VB.TextBox txtCmdName 
            Height          =   285
            Left            =   810
            TabIndex        =   15
            Text            =   "1:0A:2:1"
            Top             =   630
            Width           =   2775
         End
         Begin VB.OptionButton optValType 
            Caption         =   "Option1"
            Height          =   180
            Index           =   1
            Left            =   270
            TabIndex        =   13
            Top             =   690
            Width           =   255
         End
         Begin VB.OptionButton optValType 
            Caption         =   "Option1"
            Height          =   180
            Index           =   0
            Left            =   270
            TabIndex        =   12
            Top             =   300
            Value           =   -1  'True
            Width           =   255
         End
         Begin VB.TextBox txtPinNo 
            Alignment       =   1  '右揃え
            Height          =   285
            Left            =   1620
            TabIndex        =   11
            Text            =   "0"
            Top             =   240
            Width           =   465
         End
         Begin VB.ComboBox cmbValType 
            Height          =   300
            ItemData        =   "frmVPSTester.frx":0000
            Left            =   570
            List            =   "frmVPSTester.frx":000D
            Style           =   2  'ﾄﾞﾛｯﾌﾟﾀﾞｳﾝ ﾘｽﾄ
            TabIndex        =   10
            Top             =   240
            Width           =   1005
         End
         Begin VB.Label Label4 
            Caption         =   "M"
            Height          =   165
            Left            =   600
            TabIndex        =   14
            Top             =   690
            Width           =   135
         End
      End
      Begin VB.Label Label5 
         Alignment       =   1  '右揃え
         Caption         =   "Value :"
         Height          =   195
         Left            =   120
         TabIndex        =   17
         Top             =   1950
         Width           =   915
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Connect"
      Height          =   1815
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   4005
      Begin VB.CommandButton cmdConnect 
         Caption         =   "Connect"
         Height          =   315
         Left            =   1410
         TabIndex        =   28
         Top             =   1350
         Width           =   1155
      End
      Begin VB.CommandButton cmdDisconnect 
         Caption         =   "Disconnect"
         Height          =   315
         Left            =   2700
         TabIndex        =   7
         Top             =   1350
         Width           =   1155
      End
      Begin VB.TextBox txtTimeout 
         Alignment       =   1  '右揃え
         Height          =   270
         Left            =   1140
         TabIndex        =   6
         Text            =   "500"
         Top             =   990
         Width           =   1395
      End
      Begin VB.TextBox txtCliMax 
         Alignment       =   1  '右揃え
         Height          =   270
         Left            =   1140
         TabIndex        =   4
         Text            =   "1"
         Top             =   630
         Width           =   1395
      End
      Begin VB.TextBox txtPort 
         Alignment       =   1  '右揃え
         Height          =   270
         Left            =   1140
         TabIndex        =   2
         Text            =   "5006"
         Top             =   270
         Width           =   1395
      End
      Begin VB.Label Label3 
         Alignment       =   1  '右揃え
         Caption         =   "Timeout :"
         Height          =   195
         Left            =   120
         TabIndex        =   5
         Top             =   1020
         Width           =   915
      End
      Begin VB.Label Label2 
         Alignment       =   1  '右揃え
         Caption         =   "ClientMax :"
         Height          =   195
         Left            =   120
         TabIndex        =   3
         Top             =   660
         Width           =   915
      End
      Begin VB.Label Label1 
         Alignment       =   1  '右揃え
         Caption         =   "Port0 :"
         Height          =   195
         Left            =   120
         TabIndex        =   1
         Top             =   300
         Width           =   915
      End
   End
   Begin VB.Label Label7 
      Caption         =   "Message : "
      Height          =   195
      Left            =   4260
      TabIndex        =   25
      Top             =   120
      Width           =   915
   End
End
Attribute VB_Name = "frmVPSTester"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private caoEng As CaoEngine
Private WithEvents caoCtrl As CaoController
Attribute caoCtrl.VB_VarHelpID = -1
Private caoVar As CaoVariable

' フォームロード
Private Sub Form_Load()
    cmbValType.ListIndex = 0
    
    Set caoEng = New CaoEngine
    
    ChangeDisplay
End Sub

'コントローラ接続
Private Sub cmdConnect_Click()
    
    On Error GoTo ErrProc
    
    Set caoCtrl = caoEng.Workspaces(0).AddController("Test", "CaoProv.Fujitsu.VPS", "", "Port0=" & txtPort & ",ClientMax=" & txtCliMax & ",Timeout=" & txtTimeout)
    ChangeDisplay
    
    Exit Sub
ErrProc:
    MsgBox Err.Description
End Sub

' コントローラ切断
Private Sub cmdDisconnect_Click()

    If Not caoCtrl Is Nothing Then
        caoEng.Workspaces(0).Controllers.Remove (caoCtrl.Index)
        Set caoCtrl = Nothing
        Set caoVar = Nothing
    End If
    
    ChangeDisplay
End Sub

' 変数生成
Private Sub cmdVarAdd_Click()
    
    On Error GoTo ErrProc
    
    Dim strVarName As String
    If optValType(0).Value Then
        strVarName = cmbValType.Text & txtPinNo
    Else
        strVarName = "M" & txtCmdName
    End If
    
    Set caoVar = caoCtrl.AddVariable(strVarName)
    
    ChangeDisplay

    Exit Sub
ErrProc:
    MsgBox Err.Description
End Sub

'変数削除
Private Sub cmdVarRemove_Click()
    
    If Not caoVar Is Nothing Then
        caoCtrl.Variables.Remove (caoVar.Index)
        Set caoVar = Nothing
    End If
    
    ChangeDisplay
    
End Sub

' 変数値設定
Private Sub cmdPutVal_Click()

    On Error GoTo ErrProc

    caoVar.Value = txtValue
    
    Exit Sub
ErrProc:
    MsgBox Err.Description
End Sub

' 変数値取得
Private Sub cmdGetVal_Click()
    
    On Error GoTo ErrProc
    
    txtValue = caoVar.Value
    
    Exit Sub
ErrProc:
    MsgBox Err.Description
End Sub

' 拡張コマンド実行
Private Sub cmdExecute_Click()

    On Error GoTo ErrProc
    
    caoCtrl.Execute "PutSTR", CStr(txtExePara)
    
    Exit Sub
ErrProc:
    MsgBox Err.Description
End Sub

' メッセージイベント
Private Sub caoCtrl_OnMessage(ByVal pICaoMess As CAOLib.ICaoMessage)

    Dim strOutput As String

    strOutput = "Type : "
    Select Case pICaoMess.Number
    Case 1
        strOutput = strOutput & "PIO, "
    Case 2
        strOutput = strOutput & "DA, "
    Case 3
        strOutput = strOutput & "PC, "
    Case 4
        strOutput = strOutput & "STR, "
    End Select
    
    strOutput = strOutput & "No : " & pICaoMess.Source & ", Value : " & pICaoMess.Value
    
    lstMessage.AddItem strOutput

End Sub

' リストクリア
Private Sub cmdClear_Click()
    lstMessage.Clear
End Sub

' 画面更新
Private Sub ChangeDisplay()

    Dim bCtrl As Boolean
    Dim bVar As Boolean

    bCtrl = Not caoCtrl Is Nothing
    bVar = Not caoVar Is Nothing


    ' Connect
    txtPort.Enabled = Not bCtrl
    txtCliMax.Enabled = Not bCtrl
    txtTimeout.Enabled = Not bCtrl
    cmdConnect.Enabled = Not bCtrl
    cmdDisconnect.Enabled = bCtrl
    
    ' Variable
    optValType(0).Enabled = bCtrl And Not bVar
    optValType(1).Enabled = bCtrl And Not bVar
    cmbValType.Enabled = (bCtrl And optValType(0).Value) And Not bVar
    txtPinNo.Enabled = (bCtrl And optValType(0).Value) And Not bVar
    txtCmdName.Enabled = (bCtrl And optValType(1).Value) And Not bVar
    cmdVarAdd.Enabled = bCtrl And Not bVar
    cmdVarRemove.Enabled = bCtrl And bVar
    
    txtValue.Enabled = bVar
    cmdPutVal.Enabled = bVar
    cmdGetVal.Enabled = bVar
    
    ' Execute
    txtExePara.Enabled = bCtrl
    cmdExecute.Enabled = bCtrl
    
    ' Message
    cmdClear.Enabled = bCtrl

End Sub

