コンテンツにスキップ
サンプルプログラム > アナログ入力 > AiInputVolt >

Visual Basic 6.0

開発環境の設定

  1. Ydx.bas をプロジェクトフォルダにコピーします。

  2. Ydx.bas をプロジェクトに追加します。

コントロール

変数

Dim id As Long
Dim result As Long

実行結果の表示

Private Sub ResultShow(ByVal title As String, ByVal resultCode As Long)
    Dim resultString As String
    Call YdxCnvResultToString(resultCode, resultString)
    Select Case resultCode
        Case 0, Ydx.YDX_RESULT_AI_EXCEED_DATA_NUM, Ydx.YDX_RESULT_AI_EXCEED_BUF_SIZ
            MsgBox resultString, vbInformation, title
        Case Else
            MsgBox resultString, vbCritical, title
    End Select
End Sub

フォームロード

Private Sub Form_Load()
    ' ユニット識別スイッチ
    cboUnitSwitch.AddItem "0"
    cboUnitSwitch.AddItem "1"
    cboUnitSwitch.AddItem "2"
    cboUnitSwitch.AddItem "3"
    cboUnitSwitch.AddItem "4"
    cboUnitSwitch.AddItem "5"
    cboUnitSwitch.AddItem "6"
    cboUnitSwitch.AddItem "7"
    cboUnitSwitch.AddItem "8"
    cboUnitSwitch.AddItem "9"
    cboUnitSwitch.AddItem "A"
    cboUnitSwitch.AddItem "B"
    cboUnitSwitch.AddItem "C"
    cboUnitSwitch.AddItem "D"
    cboUnitSwitch.AddItem "E"
    cboUnitSwitch.AddItem "F"
    cboUnitSwitch.ListIndex = 0

    ' 型名
    cboModelName.AddItem "AIO-64/4/1B-USC"
    cboModelName.AddItem "AIO-60/4/1B-USC"
    cboModelName.ListIndex = 0

    ' レンジ
    cboRangeType.AddItem "-10 ~ +10V"
    cboRangeType.AddItem "-5 ~ +5V"
End Sub

オープン

Private Sub cmdOpen_Click()
    result = YdxOpen(cboUnitSwitch.ListIndex, cboModelName.Text, 0, id)
    If result <> 0 Then
        Call ResultShow("YdxOpen", result)
    Else
        cboUnitSwitch.Enabled = False
        cboModelName.Enabled = False
        cboRangeType.ListIndex = 0
        Call ResultShow("オープン", result)
    End If
End Sub

レンジ切り替え

Private Sub cboRangeType_Click()
    result = YdxAiSetRange(id, cboRangeType.ListIndex)
    If result <> 0 Then
        Call ResultShow("YdxAiSetRange", result)
    End If
End Sub

アナログ入力

Private Sub cmdInput_Click()
    txtData.Text = ""
    DoEvents

    Const CHANNEL_NUM As Long = 6
    Dim data(CHANNEL_NUM - 1) As Single
    result = YdxAiInputVolt(id, 0, CHANNEL_NUM, data(0))
    If result <> 0 Then
        Call ResultShow("YdxAiInput", result)
        Exit Sub
    End If

    Dim txt As String
    txt = ""
    Dim channel As Long
    For channel = 0 To CHANNEL_NUM - 1
        txt = txt + "CH" + Format(channel) + " : " + Right(" " & Format(data(channel), " 0.000;-0.000"), 7) + "V" + vbCrLf
    Next

    txtData.Text = txt
End Sub

クローズ

Private Sub cmdClose_Click()
    cboUnitSwitch.Enabled = True
    cboModelName.Enabled = True
    result = YdxClose(id)
    If result <> 0 Then
        Call ResultShow("YdxClose", result)
    Else
        Call ResultShow("クローズ", result)
    End If
End Sub

フォームアンロード

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    result = YdxClose(id)
    If result <> 0 And result <> YDX_RESULT_NOT_OPEN Then
        Call ResultShow("YdxClose", result)
    End If
End Sub