Visual Basic(.NET2002以降)¶
開発環境の設定¶
-
Ydx.vb をプロジェクトフォルダにコピーします。
-
Ydx.vb をプロジェクトに追加します。
コントロール¶
変数¶
Dim id As Short
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() { "AIO-64/4/1B-USC", "AIO-04/4/1B-USC" })
modelNameComboBox.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 outputButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles outputButton.Click
Const CHANNEL_NUM As Integer = 4
Dim data(CHANNEL_NUM) As Single
Dim dataText As String = ""
For i As Integer = 0 To CHANNEL_NUM - 1
Select Case (i)
Case 0
dataText = data0TextBox.Text
Case 1
dataText = data1TextBox.Text
Case 2
dataText = data2TextBox.Text
Case 3
dataText = data3TextBox.Text
End Select
Dim doubleData As Double
If Double.TryParse(dataText, Globalization.NumberStyles.Float, Nothing, doubleData) = False Then
MessageBox.Show("CH" + i.ToString() + "のデータが不正です", "", MessageBoxButtons.OK, MessageBoxIcon.Hand)
Exit Sub
End If
data(i) = CType(doubleData, Single)
Next
result = YdxAoOutputVolt(id, 0, CHANNEL_NUM, 0, 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