コンテンツにスキップ
サンプルプログラム > デジタル入出力 > Dio >

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.AddItem "AIO-04/4/1B-USC"
    cboModelName.ListIndex = 0
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
        Call ResultShow("オープン", result)
    End If
End Sub

デジタル入力

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

    Const DI_CHANNEL_NUM As Long = 4
    Dim data(DI_CHANNEL_NUM - 1) As Long
    result = YdxDiInputBit(id, 0, DI_CHANNEL_NUM, 0, data(0))
    If result <> 0 Then
        Call ResultShow("YdxDiInputBit", result)
        Exit Sub
    End If

    Dim txt As String
    txt = ""
    Dim channel As Long
    For channel = 0 To DI_CHANNEL_NUM - 1
        txt = txt + "CH" + Format(channel) + " : " + Format(data(channel)) + vbCrLf
    Next

    txtInputData.Text = txt
End Sub

デジタル出力

Private Sub cmdOutput_Click()
    Dim data(0) As Long
    data(0) = txtOutputData.Text
    result = YdxDoOutputBit(id, 0, 1, data(0))
    Call ResultShow("デジタル出力", result)
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