﻿Option Strict Off
Option Explicit On 
Imports System.Text

Friend Class Sync
    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 GroupBox4 As System.Windows.Forms.GroupBox
    Friend WithEvents GroupBox5 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 Label7 As System.Windows.Forms.Label
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents Label10 As System.Windows.Forms.Label
    Friend WithEvents Edit_S_DevName As System.Windows.Forms.TextBox
    Friend WithEvents Edit_M_DevName As System.Windows.Forms.TextBox
    Friend WithEvents Edit_M_TransCount As System.Windows.Forms.TextBox
    Friend WithEvents Edit_M_Status As System.Windows.Forms.TextBox
    Friend WithEvents Edit_M_Error As System.Windows.Forms.TextBox
    Friend WithEvents Edit_M_Return As System.Windows.Forms.TextBox
    Friend WithEvents Edit_S_TransCount As System.Windows.Forms.TextBox
    Friend WithEvents Edit_S_Status As System.Windows.Forms.TextBox
    Friend WithEvents Edit_S_Error As System.Windows.Forms.TextBox
    Friend WithEvents Edit_S_Return As System.Windows.Forms.TextBox
    Friend WithEvents Button_S_DioInit As System.Windows.Forms.Button
    Friend WithEvents Button_S_Condition As System.Windows.Forms.Button
    Friend WithEvents Button_S_Start As System.Windows.Forms.Button
    Friend WithEvents Button_S_Stop As System.Windows.Forms.Button
    Friend WithEvents Button_S_Data As System.Windows.Forms.Button
    Friend WithEvents Button_S_Count As System.Windows.Forms.Button
    Friend WithEvents Button_S_Status As System.Windows.Forms.Button
    Friend WithEvents Button_S_DioExit As System.Windows.Forms.Button
    Friend WithEvents Button_M_DioInit As System.Windows.Forms.Button
    Friend WithEvents Button_M_Condition As System.Windows.Forms.Button
    Friend WithEvents Button_M_Start As System.Windows.Forms.Button
    Friend WithEvents Button_M_Stop As System.Windows.Forms.Button
    Friend WithEvents Button_M_Data As System.Windows.Forms.Button
    Friend WithEvents Button_M_Count As System.Windows.Forms.Button
    Friend WithEvents Button_M_Status As System.Windows.Forms.Button
    Friend WithEvents Button_M_DioExit As System.Windows.Forms.Button
    Friend WithEvents Button_Exit As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.Edit_S_DevName = New System.Windows.Forms.TextBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Edit_M_DevName = New System.Windows.Forms.TextBox()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.Edit_M_TransCount = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.Edit_M_Status = New System.Windows.Forms.TextBox()
        Me.Edit_M_Error = New System.Windows.Forms.TextBox()
        Me.Edit_M_Return = New System.Windows.Forms.TextBox()
        Me.GroupBox3 = New System.Windows.Forms.GroupBox()
        Me.Edit_S_TransCount = New System.Windows.Forms.TextBox()
        Me.Label7 = New System.Windows.Forms.Label()
        Me.Label8 = New System.Windows.Forms.Label()
        Me.Label9 = New System.Windows.Forms.Label()
        Me.Label10 = New System.Windows.Forms.Label()
        Me.Edit_S_Status = New System.Windows.Forms.TextBox()
        Me.Edit_S_Error = New System.Windows.Forms.TextBox()
        Me.Edit_S_Return = New System.Windows.Forms.TextBox()
        Me.GroupBox4 = New System.Windows.Forms.GroupBox()
        Me.Button_S_DioInit = New System.Windows.Forms.Button()
        Me.Button_S_Condition = New System.Windows.Forms.Button()
        Me.Button_S_Start = New System.Windows.Forms.Button()
        Me.Button_S_Stop = New System.Windows.Forms.Button()
        Me.Button_S_Data = New System.Windows.Forms.Button()
        Me.Button_S_Count = New System.Windows.Forms.Button()
        Me.Button_S_Status = New System.Windows.Forms.Button()
        Me.Button_S_DioExit = New System.Windows.Forms.Button()
        Me.GroupBox5 = New System.Windows.Forms.GroupBox()
        Me.Button_M_DioInit = New System.Windows.Forms.Button()
        Me.Button_M_Condition = New System.Windows.Forms.Button()
        Me.Button_M_Start = New System.Windows.Forms.Button()
        Me.Button_M_Stop = New System.Windows.Forms.Button()
        Me.Button_M_Data = New System.Windows.Forms.Button()
        Me.Button_M_Count = New System.Windows.Forms.Button()
        Me.Button_M_Status = New System.Windows.Forms.Button()
        Me.Button_M_DioExit = New System.Windows.Forms.Button()
        Me.Button_Exit = New System.Windows.Forms.Button()
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.GroupBox4.SuspendLayout()
        Me.GroupBox5.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Edit_S_DevName, Me.Label1, Me.Label2, Me.Edit_M_DevName})
        Me.GroupBox1.Location = New System.Drawing.Point(16, 16)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(328, 56)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "デバイス名"
        '
        'Edit_S_DevName
        '
        Me.Edit_S_DevName.Location = New System.Drawing.Point(224, 24)
        Me.Edit_S_DevName.Name = "Edit_S_DevName"
        Me.Edit_S_DevName.Size = New System.Drawing.Size(88, 19)
        Me.Edit_S_DevName.TabIndex = 2
        Me.Edit_S_DevName.Text = "TextBox1"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(168, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(56, 16)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "スレーブ："
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 24)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(48, 16)
        Me.Label2.TabIndex = 0
        Me.Label2.Text = "マスター："
        '
        'Edit_M_DevName
        '
        Me.Edit_M_DevName.Location = New System.Drawing.Point(64, 24)
        Me.Edit_M_DevName.Name = "Edit_M_DevName"
        Me.Edit_M_DevName.Size = New System.Drawing.Size(96, 19)
        Me.Edit_M_DevName.TabIndex = 1
        Me.Edit_M_DevName.Text = "TextBox1"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.Edit_M_TransCount, Me.Label3, Me.Label4, Me.Label5, Me.Label6, Me.Edit_M_Status, Me.Edit_M_Error, Me.Edit_M_Return})
        Me.GroupBox2.Location = New System.Drawing.Point(16, 80)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(328, 120)
        Me.GroupBox2.TabIndex = 0
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "マスターステータス"
        '
        'Edit_M_TransCount
        '
        Me.Edit_M_TransCount.Location = New System.Drawing.Point(80, 13)
        Me.Edit_M_TransCount.Name = "Edit_M_TransCount"
        Me.Edit_M_TransCount.Size = New System.Drawing.Size(240, 19)
        Me.Edit_M_TransCount.TabIndex = 1
        Me.Edit_M_TransCount.Text = "TextBox3"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(16, 16)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(48, 16)
        Me.Label3.TabIndex = 0
        Me.Label3.Text = "カウント："
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(16, 42)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(64, 16)
        Me.Label4.TabIndex = 0
        Me.Label4.Text = "ステータス："
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(16, 68)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(40, 16)
        Me.Label5.TabIndex = 0
        Me.Label5.Text = "エラー："
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(16, 94)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(48, 16)
        Me.Label6.TabIndex = 0
        Me.Label6.Text = "戻り値："
        '
        'Edit_M_Status
        '
        Me.Edit_M_Status.Location = New System.Drawing.Point(80, 38)
        Me.Edit_M_Status.Name = "Edit_M_Status"
        Me.Edit_M_Status.Size = New System.Drawing.Size(240, 19)
        Me.Edit_M_Status.TabIndex = 1
        Me.Edit_M_Status.Text = "TextBox3"
        '
        'Edit_M_Error
        '
        Me.Edit_M_Error.Location = New System.Drawing.Point(80, 63)
        Me.Edit_M_Error.Name = "Edit_M_Error"
        Me.Edit_M_Error.Size = New System.Drawing.Size(240, 19)
        Me.Edit_M_Error.TabIndex = 1
        Me.Edit_M_Error.Text = "TextBox3"
        '
        'Edit_M_Return
        '
        Me.Edit_M_Return.Location = New System.Drawing.Point(80, 88)
        Me.Edit_M_Return.Name = "Edit_M_Return"
        Me.Edit_M_Return.Size = New System.Drawing.Size(240, 19)
        Me.Edit_M_Return.TabIndex = 1
        Me.Edit_M_Return.Text = "TextBox3"
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.AddRange(New System.Windows.Forms.Control() {Me.Edit_S_TransCount, Me.Label7, Me.Label8, Me.Label9, Me.Label10, Me.Edit_S_Status, Me.Edit_S_Error, Me.Edit_S_Return})
        Me.GroupBox3.Location = New System.Drawing.Point(16, 208)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(328, 120)
        Me.GroupBox3.TabIndex = 0
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "スレーブステータス"
        '
        'Edit_S_TransCount
        '
        Me.Edit_S_TransCount.Location = New System.Drawing.Point(80, 16)
        Me.Edit_S_TransCount.Name = "Edit_S_TransCount"
        Me.Edit_S_TransCount.Size = New System.Drawing.Size(240, 19)
        Me.Edit_S_TransCount.TabIndex = 1
        Me.Edit_S_TransCount.Text = "TextBox7"
        '
        'Label7
        '
        Me.Label7.Location = New System.Drawing.Point(16, 88)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(48, 16)
        Me.Label7.TabIndex = 0
        Me.Label7.Text = "戻り値："
        '
        'Label8
        '
        Me.Label8.Location = New System.Drawing.Point(17, 16)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(47, 16)
        Me.Label8.TabIndex = 0
        Me.Label8.Text = "カウント："
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(16, 40)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(64, 16)
        Me.Label9.TabIndex = 0
        Me.Label9.Text = "ステータス："
        '
        'Label10
        '
        Me.Label10.Location = New System.Drawing.Point(16, 64)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(40, 16)
        Me.Label10.TabIndex = 0
        Me.Label10.Text = "エラー："
        '
        'Edit_S_Status
        '
        Me.Edit_S_Status.Location = New System.Drawing.Point(80, 40)
        Me.Edit_S_Status.Name = "Edit_S_Status"
        Me.Edit_S_Status.Size = New System.Drawing.Size(240, 19)
        Me.Edit_S_Status.TabIndex = 1
        Me.Edit_S_Status.Text = "TextBox7"
        '
        'Edit_S_Error
        '
        Me.Edit_S_Error.Location = New System.Drawing.Point(80, 64)
        Me.Edit_S_Error.Name = "Edit_S_Error"
        Me.Edit_S_Error.Size = New System.Drawing.Size(240, 19)
        Me.Edit_S_Error.TabIndex = 1
        Me.Edit_S_Error.Text = "TextBox7"
        '
        'Edit_S_Return
        '
        Me.Edit_S_Return.Location = New System.Drawing.Point(80, 88)
        Me.Edit_S_Return.Name = "Edit_S_Return"
        Me.Edit_S_Return.Size = New System.Drawing.Size(240, 19)
        Me.Edit_S_Return.TabIndex = 1
        Me.Edit_S_Return.Text = "TextBox7"
        '
        'GroupBox4
        '
        Me.GroupBox4.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button_S_DioInit, Me.Button_S_Condition, Me.Button_S_Start, Me.Button_S_Stop, Me.Button_S_Data, Me.Button_S_Count, Me.Button_S_Status, Me.Button_S_DioExit})
        Me.GroupBox4.Location = New System.Drawing.Point(496, 16)
        Me.GroupBox4.Name = "GroupBox4"
        Me.GroupBox4.Size = New System.Drawing.Size(120, 312)
        Me.GroupBox4.TabIndex = 1
        Me.GroupBox4.TabStop = False
        Me.GroupBox4.Text = "スレーブ"
        '
        'Button_S_DioInit
        '
        Me.Button_S_DioInit.Location = New System.Drawing.Point(16, 24)
        Me.Button_S_DioInit.Name = "Button_S_DioInit"
        Me.Button_S_DioInit.Size = New System.Drawing.Size(88, 24)
        Me.Button_S_DioInit.TabIndex = 4
        Me.Button_S_DioInit.Text = "DioInit"
        '
        'Button_S_Condition
        '
        Me.Button_S_Condition.Location = New System.Drawing.Point(16, 59)
        Me.Button_S_Condition.Name = "Button_S_Condition"
        Me.Button_S_Condition.Size = New System.Drawing.Size(88, 24)
        Me.Button_S_Condition.TabIndex = 4
        Me.Button_S_Condition.Text = "条件設定..."
        '
        'Button_S_Start
        '
        Me.Button_S_Start.Location = New System.Drawing.Point(16, 94)
        Me.Button_S_Start.Name = "Button_S_Start"
        Me.Button_S_Start.Size = New System.Drawing.Size(88, 24)
        Me.Button_S_Start.TabIndex = 4
        Me.Button_S_Start.Text = "転送スタート"
        '
        'Button_S_Stop
        '
        Me.Button_S_Stop.Location = New System.Drawing.Point(16, 129)
        Me.Button_S_Stop.Name = "Button_S_Stop"
        Me.Button_S_Stop.Size = New System.Drawing.Size(88, 24)
        Me.Button_S_Stop.TabIndex = 4
        Me.Button_S_Stop.Text = "転送ストップ"
        '
        'Button_S_Data
        '
        Me.Button_S_Data.Location = New System.Drawing.Point(16, 164)
        Me.Button_S_Data.Name = "Button_S_Data"
        Me.Button_S_Data.Size = New System.Drawing.Size(88, 24)
        Me.Button_S_Data.TabIndex = 4
        Me.Button_S_Data.Text = "取得データ..."
        '
        'Button_S_Count
        '
        Me.Button_S_Count.Location = New System.Drawing.Point(16, 199)
        Me.Button_S_Count.Name = "Button_S_Count"
        Me.Button_S_Count.Size = New System.Drawing.Size(88, 24)
        Me.Button_S_Count.TabIndex = 4
        Me.Button_S_Count.Text = "転送カウント"
        '
        'Button_S_Status
        '
        Me.Button_S_Status.Location = New System.Drawing.Point(16, 234)
        Me.Button_S_Status.Name = "Button_S_Status"
        Me.Button_S_Status.Size = New System.Drawing.Size(88, 24)
        Me.Button_S_Status.TabIndex = 4
        Me.Button_S_Status.Text = "転送ステータス"
        '
        'Button_S_DioExit
        '
        Me.Button_S_DioExit.Location = New System.Drawing.Point(16, 269)
        Me.Button_S_DioExit.Name = "Button_S_DioExit"
        Me.Button_S_DioExit.Size = New System.Drawing.Size(88, 24)
        Me.Button_S_DioExit.TabIndex = 4
        Me.Button_S_DioExit.Text = "DioExit"
        '
        'GroupBox5
        '
        Me.GroupBox5.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button_M_DioInit, Me.Button_M_Condition, Me.Button_M_Start, Me.Button_M_Stop, Me.Button_M_Data, Me.Button_M_Count, Me.Button_M_Status, Me.Button_M_DioExit})
        Me.GroupBox5.Location = New System.Drawing.Point(360, 16)
        Me.GroupBox5.Name = "GroupBox5"
        Me.GroupBox5.Size = New System.Drawing.Size(120, 312)
        Me.GroupBox5.TabIndex = 0
        Me.GroupBox5.TabStop = False
        Me.GroupBox5.Text = "マスター"
        '
        'Button_M_DioInit
        '
        Me.Button_M_DioInit.Location = New System.Drawing.Point(18, 24)
        Me.Button_M_DioInit.Name = "Button_M_DioInit"
        Me.Button_M_DioInit.Size = New System.Drawing.Size(88, 24)
        Me.Button_M_DioInit.TabIndex = 3
        Me.Button_M_DioInit.Text = "DioInit"
        '
        'Button_M_Condition
        '
        Me.Button_M_Condition.Location = New System.Drawing.Point(18, 59)
        Me.Button_M_Condition.Name = "Button_M_Condition"
        Me.Button_M_Condition.Size = New System.Drawing.Size(88, 24)
        Me.Button_M_Condition.TabIndex = 3
        Me.Button_M_Condition.Text = "条件設定..."
        '
        'Button_M_Start
        '
        Me.Button_M_Start.Location = New System.Drawing.Point(18, 94)
        Me.Button_M_Start.Name = "Button_M_Start"
        Me.Button_M_Start.Size = New System.Drawing.Size(88, 24)
        Me.Button_M_Start.TabIndex = 3
        Me.Button_M_Start.Text = "転送スタート"
        '
        'Button_M_Stop
        '
        Me.Button_M_Stop.Location = New System.Drawing.Point(18, 129)
        Me.Button_M_Stop.Name = "Button_M_Stop"
        Me.Button_M_Stop.Size = New System.Drawing.Size(88, 24)
        Me.Button_M_Stop.TabIndex = 3
        Me.Button_M_Stop.Text = "転送ストップ"
        '
        'Button_M_Data
        '
        Me.Button_M_Data.Location = New System.Drawing.Point(18, 164)
        Me.Button_M_Data.Name = "Button_M_Data"
        Me.Button_M_Data.Size = New System.Drawing.Size(88, 24)
        Me.Button_M_Data.TabIndex = 3
        Me.Button_M_Data.Text = "取得データ..."
        '
        'Button_M_Count
        '
        Me.Button_M_Count.Location = New System.Drawing.Point(18, 199)
        Me.Button_M_Count.Name = "Button_M_Count"
        Me.Button_M_Count.Size = New System.Drawing.Size(88, 24)
        Me.Button_M_Count.TabIndex = 3
        Me.Button_M_Count.Text = "転送カウント"
        '
        'Button_M_Status
        '
        Me.Button_M_Status.Location = New System.Drawing.Point(18, 234)
        Me.Button_M_Status.Name = "Button_M_Status"
        Me.Button_M_Status.Size = New System.Drawing.Size(88, 24)
        Me.Button_M_Status.TabIndex = 3
        Me.Button_M_Status.Text = "転送ステータス"
        '
        'Button_M_DioExit
        '
        Me.Button_M_DioExit.Location = New System.Drawing.Point(18, 269)
        Me.Button_M_DioExit.Name = "Button_M_DioExit"
        Me.Button_M_DioExit.Size = New System.Drawing.Size(88, 24)
        Me.Button_M_DioExit.TabIndex = 3
        Me.Button_M_DioExit.Text = "DioExit"
        '
        'Button_Exit
        '
        Me.Button_Exit.Location = New System.Drawing.Point(448, 336)
        Me.Button_Exit.Name = "Button_Exit"
        Me.Button_Exit.Size = New System.Drawing.Size(88, 24)
        Me.Button_Exit.TabIndex = 5
        Me.Button_Exit.Text = "Exit"
        '
        'Sync
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(640, 374)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button_Exit, Me.GroupBox1, Me.GroupBox2, Me.GroupBox3, Me.GroupBox4, Me.GroupBox5})
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Sync"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "同期サンプリング"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox4.ResumeLayout(False)
        Me.GroupBox5.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Shared M_Id As Integer            'マスターデバイスID
    Public Shared S_Id As Integer            'スレーブデバイスID
    Dim M_GCh As GCHandle                    'マスターガベージコレクションハンドル
    Dim S_GCh As GCHandle                    'スレーブガベージコレクションハンドル
    Dim pMBmBuf As IntPtr                    'マスターバスマスタ用バッファへのポインタ
    Dim pSBmBuf As IntPtr                    'スレーブバスマスタ用バッファへのポインタ
    Const DATA_SIZE As Short = 1000          'バスマスタ用バッファサイズ
    Dim M_BmBuffer(DATA_SIZE) As Integer     'マスターバスマスタ用バッファ
    Dim S_BmBuffer(DATA_SIZE) As Integer     'スレーブバスマスタ用バッファ
    Dim szError As New StringBuilder("", 256)
    Dim Ret As Integer                       '戻り値
    Dim gM_ConditionDlg As New M_ConditionDlg()
    Dim gS_ConditionDlg As New S_ConditionDlg()

    '=========================================================
    ' ダイアログ初期化
    '=========================================================
    Private Sub SYNC_DIALOG_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        '--------------------------------
        ' 画面表示の初期化
        '--------------------------------
        Edit_M_TransCount.Text = ""
        Edit_M_Status.Text = ""
        Edit_M_Error.Text = ""
        Edit_M_Return.Text = ""
        Edit_S_TransCount.Text = ""
        Edit_S_Status.Text = ""
        Edit_S_Error.Text = ""
        Edit_S_Return.Text = ""
        Edit_M_DevName.Text = "DIO000"
        Edit_S_DevName.Text = "DIO001"
        '--------------------------------
        ' M_BmBufferにPinnedタイプハンドルを割り当てます
        '--------------------------------
        If M_GCh.IsAllocated = False Then
            M_GCh = GCHandle.Alloc(M_BmBuffer, GCHandleType.Pinned)
        End If
        '--------------------------------
        ' S_BmBufferにPinnedタイプハンドルを割り当てます
        '--------------------------------
        If S_GCh.IsAllocated = False Then
            S_GCh = GCHandle.Alloc(S_BmBuffer, GCHandleType.Pinned)
        End If
    End Sub

    '=========================================================
    ' マスター DioInit()
    '=========================================================
    Private Sub BUTTON_M_DIO_INIT_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_M_DioInit.Click
        '--------------------------------
        ' 初期化処理
        '--------------------------------
        Ret = DioInit(Edit_M_DevName.Text, M_Id)
        Call DioGetErrorString(Ret, szError)
        Edit_M_Return.Text = "DioInit Ret = " & Ret & ":" & szError.ToString()
    End Sub

    '=========================================================
    ' スレーブ DioInit()
    '=========================================================
    Private Sub BUTTON_S_DIO_INIT_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_S_DioInit.Click
        '--------------------------------
        ' 初期化処理
        '--------------------------------
        Ret = DioInit(Edit_S_DevName.Text, S_Id)
        Call DioGetErrorString(Ret, szError)
        Edit_S_Return.Text = "DioInit Ret = " & Ret & ":" & szError.ToString()
    End Sub

    '=========================================================
    ' マスター条件設定
    '=========================================================
    Private Sub BUTTON_M_CONDITION_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_M_Condition.Click
        gM_ConditionDlg.Show()
    End Sub

    '=========================================================
    ' スレーブ条件設定
    '=========================================================
    Private Sub BUTTON_S_CONDITION_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_S_Condition.Click
        gS_ConditionDlg.Show()
    End Sub

    '=========================================================
    ' マスター転送スタート
    '=========================================================
    Private Sub BUTTON_M_START_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_M_Start.Click
        Dim Direction As Integer

        '--------------------------------
        ' 表示初期化
        '--------------------------------
        Edit_M_TransCount.Text = ""
        Edit_M_Status.Text = ""
        Edit_M_Error.Text = ""
        '--------------------------------
        ' 転送完了イベント設定
        '--------------------------------
        Direction = DIODM_DIR_IN
        Ret = DioDmSetStopEvent(M_Id, Direction, Me.Handle)
        If Ret <> 0 Then
            Call DioGetErrorString(Ret, szError)
            Edit_M_Return.Text = "DioDmSetStopEvent Ret = " & Ret & ":" & szError.ToString()
            Exit Sub
        End If
        '--------------------------------
        ' 指定個数転送完了イベント設定
        '--------------------------------
        Ret = DioDmSetCountEvent(M_Id, Direction, M_ConditionDlg.NumberOfData, Me.Handle)
        If Ret <> 0 Then
            Call DioGetErrorString(Ret, szError)
            Edit_M_Return.Text = "DioDmSetCountEvent Ret = " & Ret & ":" & szError.ToString()
            Exit Sub
        End If
        '--------------------------------
        ' FIFOのリセット(入力)
        '--------------------------------
        Ret = DioDmFifoReset(M_Id, DIODM_RESET_FIFO_IN)
        If Ret <> 0 Then
            Call DioGetErrorString(Ret, szError)
            Edit_M_Return.Text = "DioDmFifoReset Ret = " & Ret & ":" & szError.ToString()
            Exit Sub
        End If
        '--------------------------------
        ' M_BmBufferを初期化、0に設定します
        '--------------------------------
        System.Array.Clear(M_BmBuffer, 0, M_BmBuffer.Length)
        '--------------------------------
        ' Pinned ハンドル内のオブジェクトのアドレスを取得します
        '--------------------------------
        pMBmBuf = M_GCh.AddrOfPinnedObject()
        '--------------------------------
        ' データバッファを設定
        '--------------------------------
        Ret = DioDmSetBuffer(M_Id, Direction, pMBmBuf, DATA_SIZE, M_ConditionDlg.IsRing)
        If Ret <> 0 Then
            Call DioGetErrorString(Ret, szError)
            Edit_M_Return.Text = "DioDmSetBuffer Ret = " & Ret & ":" & szError.ToString()
            Exit Sub
        End If
        '--------------------------------
        ' 転送スタート
        '--------------------------------
        Ret = DioDmTransferStart(M_Id, Direction)
        Call DioGetErrorString(Ret, szError)
        Edit_M_Return.Text = "DioDmTransferStart Ret = " & Ret & ":" & szError.ToString()
    End Sub

    '=========================================================
    ' スレーブ転送スタート
    '=========================================================
    Private Sub BUTTON_S_START_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_S_Start.Click
        Dim Direction As Integer

        '--------------------------------
        ' 表示初期化
        '--------------------------------
        Edit_S_TransCount.Text = ""
        Edit_S_Status.Text = ""
        Edit_S_Error.Text = ""
        '--------------------------------
        ' 転送完了イベント設定
        '--------------------------------
        Direction = DIODM_DIR_IN
        Ret = DioDmSetStopEvent(S_Id, Direction, Me.Handle)
        If Ret <> 0 Then
            Call DioGetErrorString(Ret, szError)
            Edit_S_Return.Text = "DioDmSetStopEvent Ret = " & Ret & ":" & szError.ToString()
            Exit Sub
        End If
        '--------------------------------
        ' 指定個数転送完了イベント設定
        '--------------------------------
        Ret = DioDmSetCountEvent(S_Id, Direction, S_ConditionDlg.NumberOfData, Me.Handle)
        If Ret <> 0 Then
            Call DioGetErrorString(Ret, szError)
            Edit_S_Return.Text = "DioDmSetCountEvent Ret = " & Ret & ":" & szError.ToString()
            Exit Sub
        End If
        '--------------------------------
        ' FIFOのリセット(入力)
        '--------------------------------
        Ret = DioDmFifoReset(S_Id, DIODM_RESET_FIFO_IN)
        If Ret <> 0 Then
            Call DioGetErrorString(Ret, szError)
            Edit_S_Return.Text = "DioDmFifoReset Ret = " & Ret & ":" & szError.ToString()
            Exit Sub
        End If
        '--------------------------------
        ' S_BmBufferを初期化、0に設定します
        '--------------------------------
        System.Array.Clear(S_BmBuffer, 0, S_BmBuffer.Length)
        '--------------------------------
        ' Pinned ハンドル内のオブジェクトのアドレスを取得します
        '--------------------------------
        pSBmBuf = S_GCh.AddrOfPinnedObject()
        '--------------------------------
        ' データバッファを設定
        '--------------------------------
        Ret = DioDmSetBuffer(S_Id, Direction, pSBmBuf, DATA_SIZE, S_ConditionDlg.IsRing)
        If Ret <> 0 Then
            Call DioGetErrorString(Ret, szError)
            Edit_S_Return.Text = "DioDmSetBuffer Ret = " & Ret & ":" & szError.ToString()
            Exit Sub
        End If
        '--------------------------------
        ' 転送スタート
        '--------------------------------
        Ret = DioDmTransferStart(S_Id, Direction)
        Call DioGetErrorString(Ret, szError)
        Edit_S_Return.Text = "DioDmTransferStart Ret = " & Ret & ":" & szError.ToString()
    End Sub

    '=========================================================
    ' マスター転送ストップ
    '=========================================================
    Private Sub BUTTON_M_STOP_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_M_Stop.Click
        '--------------------------------
        ' 転送ストップ
        '--------------------------------
        Ret = DioDmTransferStop(M_Id, DIODM_DIR_IN)
        Call DioGetErrorString(Ret, szError)
        Edit_M_Return.Text = "DioDmTransferStop Ret = " & Ret & ":" & szError.ToString()

    End Sub

    '=========================================================
    ' スレーブ転送ストップ
    '=========================================================
    Private Sub BUTTON_S_STOP_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_S_Stop.Click
        '--------------------------------
        ' 転送ストップ
        '--------------------------------
        Ret = DioDmTransferStop(S_Id, DIODM_DIR_IN)
        Call DioGetErrorString(Ret, szError)
        Edit_S_Return.Text = "DioDmTransferStop Ret = " & Ret & ":" & szError.ToString()
    End Sub

    '=========================================================
    ' マスター取得データ
    '=========================================================
    Private Sub BUTTON_M_DATA_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_M_Data.Click
        Dim szExeFilePath As String
        Dim szFileName As String
        Dim szLine As String
        Dim i As Integer

        szFileName = "MSamplingData.csv"
        '--------------------------------
        ' ファイルを開く
        '--------------------------------
        FileOpen(1, szFileName, OpenMode.Output)
        '--------------------------------
        ' ファイルに取得データを書き込みます
        '--------------------------------
        For i = 0 To DATA_SIZE - 1
            szLine = String.Format("{0:d8}: ,{1:X8}", i, M_BmBuffer(i))
            PrintLine(1, szLine)
        Next i
        '--------------------------------
        ' ファイルを閉じる
        '--------------------------------
        FileClose(1)
        '--------------------------------
        ' データファイルをメモ帳で開く
        '--------------------------------
        szExeFilePath = "notepad.exe " & szFileName
        Shell(szExeFilePath, 1)
    End Sub

    '=========================================================
    ' スレーブ取得データ
    '=========================================================
    Private Sub BUTTON_S_DATA_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_S_Data.Click
        Dim szExeFilePath As String
        Dim szFileName As String
        Dim szLine As String
        Dim i As Integer

        szFileName = "SSamplingData.csv"
        '--------------------------------
        ' ファイルを開く
        '--------------------------------
        FileOpen(1, szFileName, OpenMode.Output)
        '--------------------------------
        ' ファイルに取得データを書き込みます
        '--------------------------------
        For i = 0 To DATA_SIZE - 1
            szLine = String.Format("{0:d8}: ,{1:X8}", i, S_BmBuffer(i))
            PrintLine(1, szLine)
        Next i
        '--------------------------------
        ' ファイルを閉じる
        '--------------------------------
        FileClose(1)
        '--------------------------------
        ' データファイルをメモ帳で開く
        '--------------------------------
        szExeFilePath = "notepad.exe " & szFileName
        Shell(szExeFilePath, 1)
    End Sub

    '=========================================================
    ' マスター転送カウント
    '=========================================================
    Private Sub BUTTON_M_COUNT_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_M_Count.Click
        Dim Count As Integer
        Dim Carry As Integer

        '--------------------------------
        ' 転送カウント取得
        '--------------------------------
        Ret = DioDmGetCount(M_Id, DIODM_DIR_IN, Count, Carry)
        Call DioGetErrorString(Ret, szError)
        Edit_M_Return.Text = "DioDmGetCount Ret = " & Ret & ":" & szError.ToString()
        Edit_M_TransCount.Text = Str(Count)
    End Sub

    '=========================================================
    ' スレーブ転送カウント
    '=========================================================
    Private Sub BUTTON_S_COUNT_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_S_Count.Click
        Dim Count As Integer
        Dim Carry As Integer

        '--------------------------------
        ' 転送カウント取得
        '--------------------------------
        Ret = DioDmGetCount(S_Id, DIODM_DIR_IN, Count, Carry)
        Call DioGetErrorString(Ret, szError)
        Edit_S_Return.Text = "DioDmGetCount Ret = " & Ret & ":" & szError.ToString()
        Edit_S_TransCount.Text = Str(Count)
    End Sub

    '=========================================================
    ' マスター転送ステータス
    '=========================================================
    Private Sub BUTTON_M_STATUS_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_M_Status.Click
        Dim Status As Integer
        Dim Err As Integer
		Dim szMsg As String

        '--------------------------------
        ' 転送ステータス取得
        '--------------------------------
        Ret = DioDmGetStatus(M_Id, DIODM_DIR_IN, Status, Err)
        Call DioGetErrorString(Ret, szError)
        Edit_M_Return.Text = "DioDmGetStatus Ret = " & Ret & ":" & szError.ToString()
        If Ret = DIO_ERR_SUCCESS Then
            '--------------------------------
            ' ステータス
            '--------------------------------
            szMsg = ""
            If (Status And DIODM_STATUS_BMSTOP) <> 0 Then szMsg = szMsg & "BmStop,"
            If (Status And DIODM_STATUS_PIOSTART) <> 0 Then szMsg = szMsg & "PioStart,"
            If (Status And DIODM_STATUS_PIOSTOP) <> 0 Then szMsg = szMsg & "PioStop,"
            If (Status And DIODM_STATUS_TRGIN) <> 0 Then szMsg = szMsg & "TrgIn,"
            If (Status And DIODM_STATUS_OVERRUN) <> 0 Then szMsg = szMsg & "Overrun"
            Edit_M_Status.Text = szMsg
            '--------------------------------
            ' エラー
            '--------------------------------
            szMsg = ""
            If (Err And DIODM_STATUS_FIFOEMPTY) <> 0 Then szMsg = szMsg & "FifoEmpty,"
            If (Err And DIODM_STATUS_FIFOFULL) <> 0 Then szMsg = szMsg & "FifoFull,"
            If (Err And DIODM_STATUS_SGOVERIN) <> 0 Then szMsg = szMsg & "S/GOverIn,"
            If (Err And DIODM_STATUS_TRGERR) <> 0 Then szMsg = szMsg & "TrgErr,"
            If (Err And DIODM_STATUS_CLKERR) <> 0 Then szMsg = szMsg & "ClkErr,"
            If (Err And DIODM_STATUS_SLAVEHALT) <> 0 Then szMsg = szMsg & "SlaveHalt,"
            If (Err And DIODM_STATUS_MASTERHALT) <> 0 Then szMsg = szMsg & "MasterHalt"
            Edit_M_Error.Text = szMsg
        Else
            Edit_M_Status.Text = ""
            Edit_M_Error.Text = ""
        End If
    End Sub

    '=========================================================
    ' スレーブ転送ステータス
    '=========================================================
    Private Sub BUTTON_S_STATUS_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_S_Status.Click
        Dim Status As Integer
        Dim Err As Integer
        Dim szMsg As String

        '--------------------------------
        ' 転送ステータス取得
        '--------------------------------
        Ret = DioDmGetStatus(S_Id, DIODM_DIR_IN, Status, Err)
        Call DioGetErrorString(Ret, szError)
        Edit_S_Return.Text = "DioDmGetStatus Ret = " & Ret & ":" & szError.ToString()
        '--------------------------------
        ' ステータス
        '--------------------------------
        szMsg = ""
        If (Status And DIODM_STATUS_BMSTOP) <> 0 Then szMsg = szMsg & "BmStop,"
        If (Status And DIODM_STATUS_PIOSTART) <> 0 Then szMsg = szMsg & "PioStart,"
        If (Status And DIODM_STATUS_PIOSTOP) <> 0 Then szMsg = szMsg & "PioStop,"
        If (Status And DIODM_STATUS_TRGIN) <> 0 Then szMsg = szMsg & "TrgIn,"
        If (Status And DIODM_STATUS_OVERRUN) <> 0 Then szMsg = szMsg & "Overrun"
        Edit_S_Status.Text = szMsg
        '--------------------------------
        ' エラー
        '--------------------------------
        szMsg = ""
        If (Err And DIODM_STATUS_FIFOEMPTY) <> 0 Then szMsg = szMsg & "FifoEmpty,"
        If (Err And DIODM_STATUS_FIFOFULL) <> 0 Then szMsg = szMsg & "FifoFull,"
        If (Err And DIODM_STATUS_SGOVERIN) <> 0 Then szMsg = szMsg & "S/GOverIn,"
        If (Err And DIODM_STATUS_TRGERR) <> 0 Then szMsg = szMsg & "TrgErr,"
        If (Err And DIODM_STATUS_CLKERR) <> 0 Then szMsg = szMsg & "ClkErr,"
        If (Err And DIODM_STATUS_SLAVEHALT) <> 0 Then szMsg = szMsg & "SlaveHalt,"
        If (Err And DIODM_STATUS_MASTERHALT) <> 0 Then szMsg = szMsg & "MasterHalt"
        Edit_S_Error.Text = szMsg
    End Sub

    '=========================================================
    ' マスターDioExit
    '=========================================================
    Private Sub BUTTON_M_DIO_EXIT_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_M_DioExit.Click
        '--------------------------------
        ' DioExit関数
        '--------------------------------
        Ret = DioExit(M_Id)
        Call DioGetErrorString(Ret, szError)
        Edit_M_Return.Text = "DioExit Ret = " & Ret & ":" & szError.ToString()
    End Sub

    '=========================================================
    ' スレーブDioExit
    '=========================================================
    Private Sub BUTTON_S_DIO_EXIT_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_S_DioExit.Click
        '--------------------------------
        ' DioExit関数
        '--------------------------------
        Ret = DioExit(S_Id)
        Call DioGetErrorString(Ret, szError)
        Edit_S_Return.Text = "DioExit Ret = " & Ret & ":" & szError.ToString()
    End Sub

    '=========================================================
    ' ダイアログExit
    '=========================================================
    Private Sub BUTTON_EXIT_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button_Exit.Click

        Ret = DioExit(M_Id)
        Ret = DioExit(S_Id)
        End
    End Sub

    '=========================================================
    ' ダイアログClose
    '=========================================================
    Private Sub Sync_Closed(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Closed
        Ret = DioExit(M_Id)
        Ret = DioExit(S_Id)

        '--------------------------------
        ' GCHandleを解放します
        '--------------------------------
        If M_GCh.IsAllocated = True Then
            M_GCh.Free()
        End If
        If S_GCh.IsAllocated = True Then
            S_GCh.Free()
        End If
        End
    End Sub

    '=========================================================
    ' メッセージハンドラ
    '=========================================================
    Protected Overrides Sub WndProc(ByRef m As Message)
        Dim Count As Integer
        Dim Carry As Integer

        '--------------------------------
        ' 転送カウントメッセージ or 転送完了メッセージ
        '--------------------------------
        If m.Msg = DIO_DMM_COUNT Or m.Msg = DIO_DMM_STOP Then
            If m.WParam.ToInt32 = M_Id Then
                Ret = DioDmGetCount(M_Id, DIODM_DIR_IN, Count, Carry)
                Edit_M_TransCount.Text = Str(Count)
            ElseIf m.WParam.ToInt32 = S_Id Then
                Ret = DioDmGetCount(S_Id, DIODM_DIR_IN, Count, Carry)
                Edit_S_TransCount.Text = Str(Count)
            End If
        End If
        '--------------------------------
        ' 転送完了メッセージ
        '--------------------------------
        If m.Msg = DIO_DMM_STOP Then
            If m.WParam.ToInt32 = M_Id Then
                Edit_M_Status.Text = "Stopped!"
                BUTTON_M_COUNT_Click(Button_M_Count, New System.EventArgs())
            ElseIf m.WParam.ToInt32 = S_Id Then
                Edit_S_Status.Text = "Stopped!"
                BUTTON_S_COUNT_Click(Button_S_Count, New System.EventArgs())
            End If
        End If
        MyBase.WndProc(m)
    End Sub

End Class
