﻿Option Strict Off
Option Explicit On 
Imports System.Text

Friend Class S_ConditionDlg
    Inherits System.Windows.Forms.Form

#Region " Windows フォーム デザイナで生成されたコード "

    Public Sub New()
        MyBase.New()

        ' この呼び出しは Windows フォーム デザイナで必要です。
        InitializeComponent()

        ' InitializeComponent() 呼び出しの後に初期化を追加します。

    End Sub

    ' Form は dispose をオーバーライドしてコンポーネント一覧を消去します。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    ' Windows フォーム デザイナで必要です。
    Private components As System.ComponentModel.IContainer

    ' メモ : 以下のプロシージャは、Windows フォーム デザイナで必要です。
    ' Windows フォーム デザイナを使って変更してください。  
    ' コード エディタは使用しないでください。
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Edit_StopNum As System.Windows.Forms.TextBox
    Friend WithEvents Combo_StartTrg As System.Windows.Forms.ComboBox
    Friend WithEvents Combo_ClockTrg As System.Windows.Forms.ComboBox
    Friend WithEvents Combo_StopTrg As System.Windows.Forms.ComboBox
    Friend WithEvents Radio_WriteOnce As System.Windows.Forms.RadioButton
    Friend WithEvents Radio_WriteRing As System.Windows.Forms.RadioButton
    Friend WithEvents Edit_NotifyNumber As System.Windows.Forms.TextBox
    Friend WithEvents Button_Ok As System.Windows.Forms.Button
    Friend WithEvents Button_Cancel As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.Edit_StopNum = New System.Windows.Forms.TextBox()
        Me.Combo_StartTrg = New System.Windows.Forms.ComboBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Combo_ClockTrg = New System.Windows.Forms.ComboBox()
        Me.Combo_StopTrg = New System.Windows.Forms.ComboBox()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.Radio_WriteOnce = New System.Windows.Forms.RadioButton()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.Radio_WriteRing = New System.Windows.Forms.RadioButton()
        Me.GroupBox3 = New System.Windows.Forms.GroupBox()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.Edit_NotifyNumber = New System.Windows.Forms.TextBox()
        Me.Button_Ok = New System.Windows.Forms.Button()
        Me.Button_Cancel = New System.Windows.Forms.Button()
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Edit_StopNum, Me.Combo_StartTrg, Me.Label1, Me.Label2, Me.Label3, Me.Combo_ClockTrg, Me.Combo_StopTrg, Me.Label4})
        Me.GroupBox1.Location = New System.Drawing.Point(8, 8)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(400, 120)
        Me.GroupBox1.TabIndex = 5
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "サンプリング条件"
        '
        'Edit_StopNum
        '
        Me.Edit_StopNum.Location = New System.Drawing.Point(296, 88)
        Me.Edit_StopNum.Name = "Edit_StopNum"
        Me.Edit_StopNum.Size = New System.Drawing.Size(96, 19)
        Me.Edit_StopNum.TabIndex = 5
        Me.Edit_StopNum.Text = "TextBox1"
        Me.Edit_StopNum.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Combo_StartTrg
        '
        Me.Combo_StartTrg.Location = New System.Drawing.Point(104, 16)
        Me.Combo_StartTrg.Name = "Combo_StartTrg"
        Me.Combo_StartTrg.Size = New System.Drawing.Size(120, 20)
        Me.Combo_StartTrg.TabIndex = 2
        Me.Combo_StartTrg.Text = "ComboBox1"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 18)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(80, 14)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "スタート条件："
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 54)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(72, 18)
        Me.Label2.TabIndex = 0
        Me.Label2.Text = "クロック条件："
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(16, 90)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(72, 14)
        Me.Label3.TabIndex = 0
        Me.Label3.Text = "ストップ条件："
        '
        'Combo_ClockTrg
        '
        Me.Combo_ClockTrg.Location = New System.Drawing.Point(104, 52)
        Me.Combo_ClockTrg.Name = "Combo_ClockTrg"
        Me.Combo_ClockTrg.Size = New System.Drawing.Size(120, 20)
        Me.Combo_ClockTrg.TabIndex = 3
        Me.Combo_ClockTrg.Text = "ComboBox1"
        '
        'Combo_StopTrg
        '
        Me.Combo_StopTrg.Location = New System.Drawing.Point(104, 88)
        Me.Combo_StopTrg.Name = "Combo_StopTrg"
        Me.Combo_StopTrg.Size = New System.Drawing.Size(120, 20)
        Me.Combo_StopTrg.TabIndex = 4
        Me.Combo_StopTrg.Text = "ComboBox1"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(234, 90)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(72, 14)
        Me.Label4.TabIndex = 0
        Me.Label4.Text = "停止個数："
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.Radio_WriteOnce, Me.Label5, Me.Radio_WriteRing})
        Me.GroupBox2.Location = New System.Drawing.Point(8, 136)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(400, 56)
        Me.GroupBox2.TabIndex = 7
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "バッファ条件設定"
        '
        'Radio_WriteOnce
        '
        Me.Radio_WriteOnce.Location = New System.Drawing.Point(104, 24)
        Me.Radio_WriteOnce.Name = "Radio_WriteOnce"
        Me.Radio_WriteOnce.Size = New System.Drawing.Size(72, 16)
        Me.Radio_WriteOnce.TabIndex = 6
        Me.Radio_WriteOnce.Text = "一回転送"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(17, 23)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(63, 17)
        Me.Label5.TabIndex = 0
        Me.Label5.Text = "転送条件："
        '
        'Radio_WriteRing
        '
        Me.Radio_WriteRing.Location = New System.Drawing.Point(224, 24)
        Me.Radio_WriteRing.Name = "Radio_WriteRing"
        Me.Radio_WriteRing.Size = New System.Drawing.Size(88, 16)
        Me.Radio_WriteRing.TabIndex = 7
        Me.Radio_WriteRing.Text = "無限回転送"
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label6, Me.Edit_NotifyNumber})
        Me.GroupBox3.Location = New System.Drawing.Point(8, 200)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(400, 48)
        Me.GroupBox3.TabIndex = 8
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "転送個数イベント通知"
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(120, 19)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(80, 13)
        Me.Label6.TabIndex = 1
        Me.Label6.Text = "データ毎に通知"
        '
        'Edit_NotifyNumber
        '
        Me.Edit_NotifyNumber.Location = New System.Drawing.Point(16, 16)
        Me.Edit_NotifyNumber.Name = "Edit_NotifyNumber"
        Me.Edit_NotifyNumber.Size = New System.Drawing.Size(96, 19)
        Me.Edit_NotifyNumber.TabIndex = 8
        Me.Edit_NotifyNumber.Text = "TextBox2"
        Me.Edit_NotifyNumber.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'Button_Ok
        '
        Me.Button_Ok.Location = New System.Drawing.Point(232, 256)
        Me.Button_Ok.Name = "Button_Ok"
        Me.Button_Ok.Size = New System.Drawing.Size(80, 24)
        Me.Button_Ok.TabIndex = 0
        Me.Button_Ok.Text = "OK"
        '
        'Button_Cancel
        '
        Me.Button_Cancel.Location = New System.Drawing.Point(328, 256)
        Me.Button_Cancel.Name = "Button_Cancel"
        Me.Button_Cancel.Size = New System.Drawing.Size(80, 24)
        Me.Button_Cancel.TabIndex = 1
        Me.Button_Cancel.Text = "ｷｬﾝｾﾙ"
        '
        'S_ConditionDlg
        '
        Me.AcceptButton = Me.Button_Ok
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(424, 286)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button_Ok, Me.GroupBox1, Me.GroupBox2, Me.GroupBox3, Me.Button_Cancel})
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "S_ConditionDlg"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "スレーブサンプリング条件設定"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Dim Ret As Integer                       '戻り値
    Dim szError As New StringBuilder("", 256)
    Public Shared NumberOfData As Integer
    Public Shared IsRing As Integer

    '=========================================================
    ' フォームロード
    '=========================================================
    Private Sub S_CONDITIONDLG_DIALOG_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

        '--------------------------------
        ' 画面項目の初期化
        '--------------------------------
        NumberOfData = 500
        IsRing = DIODM_WRITE_ONCE
        Edit_StopNum.Text = "1000"
        Edit_NotifyNumber.Text = Str(NumberOfData)
        If IsRing = DIODM_WRITE_ONCE Then
            Radio_WriteOnce.Checked = True
        Else
            Radio_WriteRing.Checked = True
        End If
        '--------------------------------
        ' スタート条件初期化
        '--------------------------------
        With Combo_StartTrg
            .Items.Clear()
            .Items.Add(("ExtSig1"))
            .Items.Add(("ExtSig2"))
            .Items.Add(("ExtSig3"))
            .SelectedIndex = 1
        End With
        '--------------------------------
        ' クロック条件初期化
        '--------------------------------
        With Combo_ClockTrg
            .Items.Clear()
            .Items.Add(("ExtSig1"))
            .Items.Add(("ExtSig2"))
            .Items.Add(("ExtSig3"))
            .SelectedIndex = 0
        End With
        '--------------------------------
        ' ストップ条件初期化
        '--------------------------------
        With Combo_StopTrg
            .Items.Clear()
            .Items.Add(("ExtSig1"))
            .Items.Add(("ExtSig2"))
            .Items.Add(("ExtSig3"))
            .Items.Add(("Number"))
            .SelectedIndex = 2
        End With
    End Sub

    '=========================================================
    ' ストップ条件設定変更
    '=========================================================
    Private Sub Combo_StopTrg_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Combo_StopTrg.SelectedIndexChanged
        '--------------------------------
        ' 停止個数の有効、無効を切り替え
        '--------------------------------
        If Combo_StopTrg.Text = "Number" Then
            Edit_StopNum.Enabled = True
        Else
            Edit_StopNum.Enabled = False
        End If
    End Sub

    '=========================================================
    ' OKボタン
    '=========================================================
    Private Sub BUTTON_OK_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_Ok.Click
        Dim StartTrg As Short
        Dim ClockTrg As Short
        Dim StopTrg As Short
        Dim ExtSig1 As Short
        Dim ExtSig2 As Short
        Dim ExtSig3 As Short
        Dim Direction As Short

        '--------------------------------
        ' 表示データを取得
        '--------------------------------
        NumberOfData = Val(Edit_NotifyNumber.Text)
        If Radio_WriteOnce.Checked = True Then
            IsRing = DIODM_WRITE_ONCE
        Else
            IsRing = DIODM_WRITE_RING
        End If
        '--------------------------------
        ' 設定値を数値に変換
        '--------------------------------
        '--------------------------------
        ' スタート条件
        '--------------------------------
        StartTrg = 0
        ExtSig1 = 0
        ExtSig2 = 0
        ExtSig3 = 0
        If Combo_StartTrg.Text = "ExtSig1" Then
            StartTrg = DIODM_START_EXTSIG_1
            ExtSig1 = 1
        End If
        If Combo_StartTrg.Text = "ExtSig2" Then
            StartTrg = DIODM_START_EXTSIG_2
            ExtSig2 = 1
        End If
        If Combo_StartTrg.Text = "ExtSig3" Then
            StartTrg = DIODM_START_EXTSIG_3
            ExtSig3 = 1
        End If
        '--------------------------------
        ' クロック条件
        '--------------------------------
        ClockTrg = 0
        If Combo_ClockTrg.Text = "ExtSig1" Then
            ClockTrg = DIODM_CLK_EXTSIG_1
            ExtSig1 = 1
        End If
        If Combo_ClockTrg.Text = "ExtSig2" Then
            ClockTrg = DIODM_CLK_EXTSIG_2
            ExtSig2 = 1
        End If
        If Combo_ClockTrg.Text = "ExtSig3" Then
            ClockTrg = DIODM_CLK_EXTSIG_3
            ExtSig3 = 1
        End If
        '--------------------------------
        ' ストップ条件
        '--------------------------------
        StopTrg = 0
        If Combo_StopTrg.Text = "ExtSig1" Then
            StopTrg = DIODM_STOP_EXTSIG_1
            ExtSig1 = 1
        End If
        If Combo_StopTrg.Text = "ExtSig2" Then
            StopTrg = DIODM_STOP_EXTSIG_2
            ExtSig2 = 1
        End If
        If Combo_StopTrg.Text = "ExtSig3" Then
            StopTrg = DIODM_STOP_EXTSIG_3
            ExtSig3 = 1
        End If
        If Combo_StopTrg.Text = "Number" Then
            StopTrg = DIODM_STOP_NUM
            ExtSig3 = 1
        End If
        '--------------------------------
        ' サンプリング条件を設定
        '--------------------------------
        Direction = DIODM_DIR_IN
        '--------------------------------
        ' 入出力方向設定(全点入力)
        '--------------------------------
        Ret = DioDmSetDirection(Sync.S_Id, PI_32)
        If Ret <> 0 Then
            Call DioGetErrorString(Ret, szError)
            MsgBox("DioDmSetDirection Ret = " & Ret & ":" & szError.ToString(), 0, "Sync")
            Exit Sub
        End If
        '--------------------------------
        ' スレーブ設定
        '--------------------------------
        Ret = DioDmSetSlave(Sync.S_Id, ExtSig1, ExtSig2, ExtSig3, 1, 1)
        If Ret <> 0 Then
            Call DioGetErrorString(Ret, szError)
            MsgBox("DioDmSetSlave Ret = " & Ret & ":" & szError.ToString(), 0, "Sync")
            Exit Sub
        End If
        '--------------------------------
        ' スタート条件設定
        '--------------------------------
        Ret = DioDmSetStartTrigger(Sync.S_Id, Direction, StartTrg)
        If Ret <> 0 Then
            Call DioGetErrorString(Ret, szError)
            MsgBox("DioDmSetStartTrigger Ret = " & Ret & ":" & szError.ToString(), 0, "Sync")
            Exit Sub
        End If
        '--------------------------------
        ' クロック条件設定
        '--------------------------------
        Ret = DioDmSetClockTrigger(Sync.S_Id, Direction, ClockTrg)
        If Ret <> 0 Then
            Call DioGetErrorString(Ret, szError)
            MsgBox("DioDmSetClockTrigger Ret = " & Ret & ":" & szError.ToString(), 0, "Sync")
            Exit Sub
        End If
        '--------------------------------
        ' ストップ条件設定
        '--------------------------------
        Ret = DioDmSetStopTrigger(Sync.S_Id, Direction, StopTrg)
        If Ret <> 0 Then
            Call DioGetErrorString(Ret, szError)
            MsgBox("DioDmSetStopTrigger Ret = " & Ret & ":" & szError.ToString(), 0, "Sync")
            Exit Sub
        End If
        '--------------------------------
        ' 停止個数設定
        '--------------------------------
        Ret = DioDmSetStopNumber(Sync.S_Id, Direction, Val(Edit_StopNum.Text))
        If Ret <> 0 Then
            Call DioGetErrorString(Ret, szError)
            MsgBox("DioDmSetStopNumber Ret = " & Ret & ":" & szError.ToString(), 0, "Sync")
            Exit Sub
        End If
        Hide()
    End Sub

    '=========================================================
    ' キャンセルボタン
    '=========================================================
    Private Sub BUTTON_CANCEL_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_Cancel.Click
        Hide()
    End Sub
End Class
