Visual Basic(.NET2002以降)¶
開発環境の設定¶
-
Ydx.vb をプロジェクトフォルダにコピーします。
-
Ydx.vb をプロジェクトに追加します。
コントロール¶
変数¶
Dim id As Integer
Dim result As Integer
実行結果の表示¶
Private Sub ResultShow(ByVal title As String, ByVal resultCode As Integer)
Dim resultString As New StringBuilder(256)
YdxCnvResultToString(resultCode, resultString)
Select Case resultCode
Case 0, Ydx.YDX_RESULT_DI_EXCEED_DATA_NUM, Ydx.YDX_RESULT_DI_EXCEED_BUF_SIZ
MessageBox.Show(resultString.ToString(), title, MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Case Else
MessageBox.Show(resultString.ToString(), title, MessageBoxButtons.OK, MessageBoxIcon.Hand)
End Select
End Sub
フォームロード¶
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' ユニット識別スイッチ
unitSwitchComboBox.ResetText()
unitSwitchComboBox.Items.AddRange(New String() { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" })
unitSwitchComboBox.SelectedIndex = 0
' 型名
modelNameComboBox.ResetText()
modelNameComboBox.Items.AddRange(New String() { "DIO-16/16C-USC", "DIO-16/16D-UBC", "DIO-16/16D-USC" })
modelNameComboBox.SelectedIndex = 0
' 入力チャネル
inputChannelComboBox.ResetText()
inputChannelComboBox.Items.AddRange(New String() { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" })
inputChannelComboBox.SelectedIndex = 0
' 出力チャネル
outputChannelComboBox.ResetText()
outputChannelComboBox.Items.AddRange(New String() { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" })
outputChannelComboBox.SelectedIndex = 0
' 出力データ
outputDataComboBox.ResetText()
outputDataComboBox.Items.AddRange(New String() { "0", "1" })
outputDataComboBox.SelectedIndex = 0
End Sub
オープン¶
Private Sub openButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles openButton.Click
result = YdxOpen(unitSwitchComboBox.SelectedIndex, modelNameComboBox.Text, 0, id)
If result <> 0 Then
ResultShow("YdxOpen", result)
Else
unitSwitchComboBox.Enabled = False
modelNameComboBox.Enabled = False
ResultShow("オープン", result)
End If
End Sub
入力¶
Private Sub inputButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles inputButton.Click
Dim data(0) As Integer
result = YdxDiInputBit(id, inputChannelComboBox.SelectedIndex, 1, 0, data)
If result <> 0 Then
ResultShow("YdxDiInputBit", result)
Else
MessageBox.Show("データ : " & data(0).ToString(), "入力", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
出力¶
Private Sub outputButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles outputButton.Click
Dim data(0) As Integer
data(0) = outputDataComboBox.SelectedIndex
result = YdxDoOutputBit(id, outputChannelComboBox.SelectedIndex, 1, data)
ResultShow("出力", result)
End Sub
クローズ¶
Private Sub closeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles closeButton.Click
unitSwitchComboBox.Enabled = True
modelNameComboBox.Enabled = True
result = YdxClose(id)
If result <> 0 Then
ResultShow("YdxClose", result)
Else
ResultShow("クローズ", result)
End If
End Sub
フォームクローズ¶
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
result = YdxClose(id)
If result <> 0 And result <> YDX_RESULT_NOT_OPEN Then
ResultShow("YdxClose", result)
End If
End Sub