Option Strict Off
Option Explicit On
Imports System.Text
Friend Class Form1
	Inherits System.Windows.Forms.Form
#Region "Windows tH[ fUCiɂĐꂽR[h"
	Public Sub New()
		MyBase.New()
		'̌ĂяóAWindows tH[ fUCiŕKvłB
		InitializeComponent()
	End Sub
	'Form ́AR|[lgꗗɌ㏈s邽߂ dispose I[o[Ch܂B
	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 tH[ fUCiŕKvłB
	Private components As System.ComponentModel.IContainer
	Public WithEvents CommandSetting As System.Windows.Forms.Button
	Public WithEvents Graph As System.Windows.Forms.PictureBox
	Public WithEvents TextDevice As System.Windows.Forms.TextBox
	Public WithEvents CommandInit As System.Windows.Forms.Button
	Public WithEvents CommandStart As System.Windows.Forms.Button
	Public WithEvents CommandInfo As System.Windows.Forms.Button
	Public WithEvents CommandStop As System.Windows.Forms.Button
	Public WithEvents CommandExit As System.Windows.Forms.Button
	Public WithEvents TextInfo As System.Windows.Forms.TextBox
	Public WithEvents Label4 As System.Windows.Forms.Label
	Public WithEvents LabelJudgeCount As System.Windows.Forms.Label
	Public WithEvents LabelStatus As System.Windows.Forms.Label
	Public WithEvents Label2 As System.Windows.Forms.Label
	Public WithEvents Label1 As System.Windows.Forms.Label
	' : ȉ̃vV[W Windows tH[ fUCiŕKvłB
	'Windows tH[ fUCigĕύXł܂B
	'R[hGfB^gďCȂłB


	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Me.CommandSetting = New System.Windows.Forms.Button()
		Me.Graph = New System.Windows.Forms.PictureBox()
		Me.TextDevice = New System.Windows.Forms.TextBox()
		Me.CommandInit = New System.Windows.Forms.Button()
		Me.CommandStart = New System.Windows.Forms.Button()
		Me.CommandInfo = New System.Windows.Forms.Button()
		Me.CommandStop = New System.Windows.Forms.Button()
		Me.CommandExit = New System.Windows.Forms.Button()
		Me.TextInfo = New System.Windows.Forms.TextBox()
		Me.Label4 = New System.Windows.Forms.Label()
		Me.LabelJudgeCount = New System.Windows.Forms.Label()
		Me.LabelStatus = New System.Windows.Forms.Label()
		Me.Label2 = New System.Windows.Forms.Label()
		Me.Label1 = New System.Windows.Forms.Label()
		Me.SuspendLayout()
		'
		'CommandSetting
		'
		Me.CommandSetting.BackColor = System.Drawing.SystemColors.Control
		Me.CommandSetting.Cursor = System.Windows.Forms.Cursors.Default
		Me.CommandSetting.ForeColor = System.Drawing.SystemColors.ControlText
		Me.CommandSetting.Location = New System.Drawing.Point(8, 88)
		Me.CommandSetting.Name = "CommandSetting"
		Me.CommandSetting.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.CommandSetting.Size = New System.Drawing.Size(81, 25)
		Me.CommandSetting.TabIndex = 11
		Me.CommandSetting.Text = "ݒ"
		'
		'Graph
		'
		Me.Graph.BackColor = System.Drawing.SystemColors.Window
		Me.Graph.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
		Me.Graph.Cursor = System.Windows.Forms.Cursors.Default
		Me.Graph.ForeColor = System.Drawing.SystemColors.WindowText
		Me.Graph.Location = New System.Drawing.Point(96, 8)
		Me.Graph.Name = "Graph"
		Me.Graph.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Graph.Size = New System.Drawing.Size(289, 233)
		Me.Graph.TabIndex = 8
		'
		'TextDevice
		'
		Me.TextDevice.AcceptsReturn = True
		Me.TextDevice.AutoSize = False
		Me.TextDevice.BackColor = System.Drawing.SystemColors.Window
		Me.TextDevice.Cursor = System.Windows.Forms.Cursors.IBeam
		Me.TextDevice.ForeColor = System.Drawing.SystemColors.WindowText
		Me.TextDevice.Location = New System.Drawing.Point(8, 32)
		Me.TextDevice.MaxLength = 0
		Me.TextDevice.Name = "TextDevice"
		Me.TextDevice.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.TextDevice.Size = New System.Drawing.Size(81, 18)
		Me.TextDevice.TabIndex = 6
		Me.TextDevice.Text = "DIG000"
		'
		'CommandInit
		'
		Me.CommandInit.BackColor = System.Drawing.SystemColors.Control
		Me.CommandInit.Cursor = System.Windows.Forms.Cursors.Default
		Me.CommandInit.ForeColor = System.Drawing.SystemColors.ControlText
		Me.CommandInit.Location = New System.Drawing.Point(8, 56)
		Me.CommandInit.Name = "CommandInit"
		Me.CommandInit.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.CommandInit.Size = New System.Drawing.Size(81, 25)
		Me.CommandInit.TabIndex = 5
		Me.CommandInit.Text = ""
		'
		'CommandStart
		'
		Me.CommandStart.BackColor = System.Drawing.SystemColors.Control
		Me.CommandStart.Cursor = System.Windows.Forms.Cursors.Default
		Me.CommandStart.ForeColor = System.Drawing.SystemColors.ControlText
		Me.CommandStart.Location = New System.Drawing.Point(8, 120)
		Me.CommandStart.Name = "CommandStart"
		Me.CommandStart.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.CommandStart.Size = New System.Drawing.Size(81, 25)
		Me.CommandStart.TabIndex = 4
		Me.CommandStart.Text = "Jn"
		'
		'CommandInfo
		'
		Me.CommandInfo.BackColor = System.Drawing.SystemColors.Control
		Me.CommandInfo.Cursor = System.Windows.Forms.Cursors.Default
		Me.CommandInfo.ForeColor = System.Drawing.SystemColors.ControlText
		Me.CommandInfo.Location = New System.Drawing.Point(8, 152)
		Me.CommandInfo.Name = "CommandInfo"
		Me.CommandInfo.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.CommandInfo.Size = New System.Drawing.Size(81, 25)
		Me.CommandInfo.TabIndex = 3
		Me.CommandInfo.Text = "Ԏ擾"
		'
		'CommandStop
		'
		Me.CommandStop.BackColor = System.Drawing.SystemColors.Control
		Me.CommandStop.Cursor = System.Windows.Forms.Cursors.Default
		Me.CommandStop.ForeColor = System.Drawing.SystemColors.ControlText
		Me.CommandStop.Location = New System.Drawing.Point(8, 184)
		Me.CommandStop.Name = "CommandStop"
		Me.CommandStop.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.CommandStop.Size = New System.Drawing.Size(81, 25)
		Me.CommandStop.TabIndex = 2
		Me.CommandStop.Text = "~"
		'
		'CommandExit
		'
		Me.CommandExit.BackColor = System.Drawing.SystemColors.Control
		Me.CommandExit.Cursor = System.Windows.Forms.Cursors.Default
		Me.CommandExit.ForeColor = System.Drawing.SystemColors.ControlText
		Me.CommandExit.Location = New System.Drawing.Point(8, 216)
		Me.CommandExit.Name = "CommandExit"
		Me.CommandExit.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.CommandExit.Size = New System.Drawing.Size(81, 25)
		Me.CommandExit.TabIndex = 1
		Me.CommandExit.Text = "I"
		'
		'TextInfo
		'
		Me.TextInfo.AcceptsReturn = True
		Me.TextInfo.AutoSize = False
		Me.TextInfo.BackColor = System.Drawing.SystemColors.Window
		Me.TextInfo.Cursor = System.Windows.Forms.Cursors.IBeam
		Me.TextInfo.ForeColor = System.Drawing.SystemColors.WindowText
		Me.TextInfo.Location = New System.Drawing.Point(8, 272)
		Me.TextInfo.MaxLength = 0
		Me.TextInfo.Multiline = True
		Me.TextInfo.Name = "TextInfo"
		Me.TextInfo.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.TextInfo.Size = New System.Drawing.Size(377, 25)
		Me.TextInfo.TabIndex = 0
		Me.TextInfo.Text = ""
		'
		'Label4
		'
		Me.Label4.BackColor = System.Drawing.SystemColors.Control
		Me.Label4.Cursor = System.Windows.Forms.Cursors.Default
		Me.Label4.ForeColor = System.Drawing.SystemColors.ControlText
		Me.Label4.Location = New System.Drawing.Point(8, 248)
		Me.Label4.Name = "Label4"
		Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label4.Size = New System.Drawing.Size(57, 17)
		Me.Label4.TabIndex = 13
		Me.Label4.Text = "NG"
		'
		'LabelJudgeCount
		'
		Me.LabelJudgeCount.BackColor = System.Drawing.SystemColors.Control
		Me.LabelJudgeCount.Cursor = System.Windows.Forms.Cursors.Default
		Me.LabelJudgeCount.ForeColor = System.Drawing.SystemColors.ControlText
		Me.LabelJudgeCount.Location = New System.Drawing.Point(80, 248)
		Me.LabelJudgeCount.Name = "LabelJudgeCount"
		Me.LabelJudgeCount.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.LabelJudgeCount.Size = New System.Drawing.Size(105, 17)
		Me.LabelJudgeCount.TabIndex = 12
		Me.LabelJudgeCount.Text = "0"
		'
		'LabelStatus
		'
		Me.LabelStatus.BackColor = System.Drawing.SystemColors.Control
		Me.LabelStatus.Cursor = System.Windows.Forms.Cursors.Default
		Me.LabelStatus.ForeColor = System.Drawing.SystemColors.ControlText
		Me.LabelStatus.Location = New System.Drawing.Point(280, 248)
		Me.LabelStatus.Name = "LabelStatus"
		Me.LabelStatus.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.LabelStatus.Size = New System.Drawing.Size(105, 17)
		Me.LabelStatus.TabIndex = 10
		Me.LabelStatus.Text = "0H"
		'
		'Label2
		'
		Me.Label2.BackColor = System.Drawing.SystemColors.Control
		Me.Label2.Cursor = System.Windows.Forms.Cursors.Default
		Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
		Me.Label2.Location = New System.Drawing.Point(208, 248)
		Me.Label2.Name = "Label2"
		Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label2.Size = New System.Drawing.Size(57, 17)
		Me.Label2.TabIndex = 9
		Me.Label2.Text = "Xe[^X"
		'
		'Label1
		'
		Me.Label1.BackColor = System.Drawing.SystemColors.Control
		Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
		Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
		Me.Label1.Location = New System.Drawing.Point(8, 8)
		Me.Label1.Name = "Label1"
		Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
		Me.Label1.Size = New System.Drawing.Size(65, 17)
		Me.Label1.TabIndex = 7
		Me.Label1.Text = "foCX"
		'
		'Form1
		'
		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
		Me.ClientSize = New System.Drawing.Size(393, 304)
		Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.CommandSetting, Me.Graph, Me.TextDevice, Me.CommandInit, Me.CommandStart, Me.CommandInfo, Me.CommandStop, Me.CommandExit, Me.TextInfo, Me.Label4, Me.LabelJudgeCount, Me.LabelStatus, Me.Label2, Me.Label1})
		Me.Location = New System.Drawing.Point(4, 30)
		Me.MaximizeBox = False
		Me.Name = "Form1"
		Me.Text = "g`@1(p}XNf[^) "
		Me.ResumeLayout(False)

	End Sub
#End Region 
	Dim Id As Short	' foCXID
	Const MAX_SAMPLES As Short = 512	' őTvO
	Dim Data(MAX_SAMPLES) As Integer	' 擾f[^̔z
	Dim UpperData(MAX_SAMPLES) As Integer	' g`f[^̔z
	Dim LowerData(MAX_SAMPLES) As Integer	' g`艺f[^̔z
	Dim Judge(1) As Short	  ' g`茋
	Dim JudgeDetail(MAX_SAMPLES) As Short	' g`茋ʏڍ
	Dim Records As Integer	' 擾R[h
	Dim Resolution As Integer	' foCX̕\
	Dim bmp As Bitmap	' rbg}bv

	Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
		bmp = New Bitmap(Graph.Size.Width, Graph.Size.Height)		  ' OtƓTCỸrbg}bv𐶐
	End Sub

	'==================================
	' 
	'==================================
	Private Sub CommandInit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandInit.Click
		Dim Ret As Integer	   ' ߂l
		Dim Ret2 As Integer	   ' ߂l2
        Dim ErrorString As New StringBuilder("", 256)     ' G[

		'----------------------------------
		' 
		'----------------------------------
		Ret = DigInit(TextDevice.Text, Id)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigInit = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' foCX̃Zbg
		'----------------------------------
		Ret = DigResetDevice(Id)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigResetDevice = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		TextInfo.Text = " : I"
	End Sub

	'==================================
	' foCXݒ
	'==================================
	Private Sub CommandSetting_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandSetting.Click
		Dim Ret As Integer		  ' ߂l
		Dim Ret2 As Integer		  ' ߂l2
        Dim ErrorString As New StringBuilder("", 256)     ' G[

		'----------------------------------
		' ϐ
		'----------------------------------
		Records = 0
		Resolution = 1024		 ' DIG-100M1002-PCIpAŒݒ

		'----------------------------------
		' 샂[hݒFg`@[h
		'----------------------------------
		Ret = DigSetDigitizerMode(Id, DIG_MODE_JUDGE)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetDigitizerMode = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' ~vFTvONbNG[Ag`JEgvA
		'      foCXI[o[t[
		'----------------------------------
		Ret = DigSetHaltCondition(Id, DIG_HALT_CLOCK_ERROR Or DIG_HALT_JUDGE_COUNT Or DIG_HALT_DEVMEM_OVERFLOW)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetHaltCondition = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' TvONbN\[XݒF{[hU@
		'----------------------------------
		Ret = DigSetClockSource(Id, DIG_ECU_SRC_CLOCK)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetClockSource = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' TvO[gݒF1MHz
		'----------------------------------
		Ret = DigSetSampleRate(Id, 1000000)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetSampleRate = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' R[hݒF512Tv
		'----------------------------------
		Ret = DigSetRecordLength(Id, MAX_SAMPLES)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetRecordLength = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' R[hW񐔐ݒF
		'----------------------------------
		Ret = DigSetRecordNumber(Id, 0)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetRecordNumber = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' f[eBݒF50%
		'----------------------------------
		Ret = DigSetDutyCycle(Id, 50)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetDutyCycle = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' `lݒF0`l̂ݗL
		'----------------------------------
		' 0`lLɂ
		Ret = DigSetChannel(Id, DIG_CHANNEL0, DIG_ENABLE)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetChannel = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		' 1`l𖳌ɂ
		Ret = DigSetChannel(Id, DIG_CHANNEL1, DIG_DISABLE)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetChannel = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' WݒF}20V
		'----------------------------------
		Ret = DigSetRange(Id, DIG_CHANNEL0, DIG_RANGE_40VPP)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetRange = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' vgKނ̐ݒF
		'----------------------------------
		Ret = DigSetPreTriggerType(Id, DIG_TRIGGERTYPE_AUTO)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetPreTriggerType = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' |XggKނ̐ݒFAiOGbWgK
		'----------------------------------
		Ret = DigSetPostTriggerType(Id, DIG_TRIGGERTYPE_AIEDGE)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetPostTriggerType = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' |XggK̏ڍאݒFgKM0`lAgKx0VAGbWA1
		'----------------------------------
		Ret = DigSetPostTriggerAiEdge(Id, DIG_CHANNEL0, 0, DIG_TRIGGER_SLOPE_RISE, 1)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetPostTriggerAiEdge = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' g`s`lݒF0`l
		'----------------------------------
		Ret = DigSetJudgeChannel(Id, DIG_CHANNEL0, DIG_ENABLE)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetJudgeChannel = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' g`茋ʂ̃JEg񐔂ݒFs񐔂JEgAJEg1
		'----------------------------------
		Ret = DigSetJudgeCountLimit(Id, DIG_CHANNEL0, DIG_JUDGE_NG, 1)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetJudgeCountLimit = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' g`pf[^ݒF}[W}10f[^A}[W}50f[^AVK쐬
		'----------------------------------
		Ret = DigSetAutoMask(Id, DIG_CHANNEL0, 10, 50, DIG_AUTOMASK_NEW)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigSetAutoMask = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		' ۂɐݒ肳ꂽf[^̎擾
        Ret = DigGetJudgeData32(Id, DIG_CHANNEL0, MAX_SAMPLES, UpperData, LowerData)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigGetJudgeData = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		TextInfo.Text = "foCXݒFI"
	End Sub

	'==================================
	' Jn
	'==================================
	Private Sub CommandStart_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandStart.Click
		Dim Ret As Integer		  ' ߂l
		Dim Ret2 As Integer		  ' ߂l2
        Dim ErrorString As New StringBuilder("", 256)     ' G[

		'----------------------------------
		' Jn
		'----------------------------------
		Ret = DigStart(Id)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigStart = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If
		TextInfo.Text = "WJn : I"

		'----------------------------------
		' 쒆Xe[^XOFFɂȂ܂Ń|[O
		'----------------------------------
		Dim Status As Integer
		Dim NgCount As Integer		 ' g`̎s

		Do
			System.Windows.Forms.Application.DoEvents()			 ' _CAOLɂ邽߂̏
			'----------------------------------
			' hCoR[h擾
			'----------------------------------
			Ret = DigGetDriverMemoryRecords(Id, Records)
			If Ret <> 0 Then
				Ret2 = DigGetErrorString(Ret, ErrorString)
                TextInfo.Text = "DigGetDriverMemoryRecords = " & Ret & " : " & ErrorString.ToString()
				Exit Sub
			End If

			'----------------------------------
			' hCoɃR[h݂΁AVf[^擾
			'----------------------------------
			If Records > 0 Or Records = -1 Then
                Ret = DigReadLatestRecords32(Id, DIG_RECORD_DATA, 1, Data, Judge, JudgeDetail)
				If Ret <> 0 Then
					Ret2 = DigGetErrorString(Ret, ErrorString)
                    TextInfo.Text = "DigReadLatestRecords = " & Ret & " : " & ErrorString.ToString()
					Exit Sub
				End If
				'----------------------------------
				' Ot̕`
				'----------------------------------
				DrawGraph()
			End If

			'----------------------------------
			' g`̎s񐔂擾
			'----------------------------------
			Ret = DigGetJudgeCount(Id, NgCount)
			If Ret <> 0 Then
				Ret2 = DigGetErrorString(Ret, ErrorString)
                TextInfo.Text = "DigGetJudgeCount = " & Ret & " : " & ErrorString.ToString()
				Exit Sub
			End If
			LabelJudgeCount.Text = NgCount.ToString

			'----------------------------------
			' Xe[^X̎擾
			'----------------------------------
			Ret = DigGetStatus(Id, Status)
			If Ret <> 0 Then
				Ret2 = DigGetErrorString(Ret, ErrorString)
                TextInfo.Text = "DigGetStatus = " & Ret & " : " & ErrorString.ToString()
				Exit Sub
			End If
			LabelStatus.Text = Hex(Status) & "H"
		Loop While (Status And DIG_STATUS_BUSY) = DIG_STATUS_BUSY

		'----------------------------------
		' g`̎s񐔂擾
		'----------------------------------
		Ret = DigGetJudgeCount(Id, NgCount)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigGetJudgeCount = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If
		LabelJudgeCount.Text = NgCount.ToString

		'----------------------------------
		' ~hCoɎcĂ郌R[h擾
		'----------------------------------
		Ret = DigGetDriverMemoryRecords(Id, Records)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigGetDriverMemoryRecords = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		'----------------------------------
		' hCoɃR[h݂΁AVf[^擾
		'----------------------------------
		If Records > 0 Or Records = -1 Then
            Ret = DigReadLatestRecords32(Id, DIG_RECORD_DATA, 1, Data, Judge, JudgeDetail)
			If Ret <> 0 Then
				Ret2 = DigGetErrorString(Ret, ErrorString)
                TextInfo.Text = "DigReadLatestRecords = " & Ret & " : " & ErrorString.ToString()
				Exit Sub
			End If
			'----------------------------------
			' Ot̕`
			'----------------------------------
			DrawGraph()
		End If
	End Sub

	'==================================
	' Ԏ擾
	'==================================
	Private Sub CommandInfo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandInfo.Click
		Dim Ret As Integer		  ' ߂l
		Dim Ret2 As Integer		  ' ߂l2
        Dim ErrorString As New StringBuilder("", 256)     ' G[
		Dim Status As Integer		  ' Xe[^X

		'----------------------------------
		' Xe[^X̎擾
		'----------------------------------
		Ret = DigGetStatus(Id, Status)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigGetStatus = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If
		LabelStatus.Text = Hex(Status) & "H"

		TextInfo.Text = "Ԏ擾 : I"
	End Sub

	'==================================
	' W~
	'==================================
	Private Sub CommandStop_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandStop.Click
		Dim Ret As Integer		  ' ߂l
		Dim Ret2 As Integer		  ' ߂l2
        Dim ErrorString As New StringBuilder("", 256)     ' G[

		Ret = DigStop(Id)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigExit = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		TextInfo.Text = "W~ : I"
	End Sub


	'==================================
	' I
	'==================================
	Private Sub CommandExit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CommandExit.Click
		Dim Ret As Integer		  ' ߂l
		Dim Ret2 As Integer		  ' ߂l2
        Dim ErrorString As New StringBuilder("", 256)     ' G[

		Ret = DigExit(Id)
		If Ret <> 0 Then
			Ret2 = DigGetErrorString(Ret, ErrorString)
            TextInfo.Text = "DigExit = " & Ret & " : " & ErrorString.ToString()
			Exit Sub
		End If

		TextInfo.Text = "I : I"
	End Sub

	'==================================
	' tH[̃A[h
	'==================================
	Private Sub Form1_Closed(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Closed
		Dim Ret As Integer		  ' ߂l
		Ret = DigExit(Id)
	End Sub

	'==================================
	' Ot`
	'==================================
	Private Sub DrawGraph()
		Dim XUnit As Single		  ' X`C^[o
		Dim PosX As Single		  ' X`ʒu
		Dim PosY As Single		  ' Y`ʒu
		Dim OldX As Single		  ' XWޔp
		Dim OldY As Single		  ' YWޔp
		Dim i As Integer
		Dim j As Integer

		'-----------------------------------------
		' ݂̃f[^Otɕ`悵܂B
		'-----------------------------------------
		Dim pen As New Pen(System.Drawing.Color.Red, 1)		' ԐFy̍쐬
		Graph.Image = bmp
		Dim grp As Graphics = Graphics.FromImage(Graph.Image)		' rbg}bv`ΏۃIuWFNg𐶐
		grp.Clear(Graph.BackColor)									' OtNA

		XUnit = Graph.Size.Width() / CSng(MAX_SAMPLES)		' 1f[^̉ړsNZvZ
		For i = 0 To 2
			OldX = 0
			Select Case i
				Case 0
					' f[^̕`ʒu_ݒ
					OldY = Graph.Height * (Resolution - UpperData(0)) / CSng(Resolution)					' Y̏lvZ
				Case 1
					' f[^̕`ʒu_ݒ
					OldY = Graph.Height * (Resolution - LowerData(0)) / CSng(Resolution)					' Y̏lvZ

				Case 2
					' Wf[^̕`ʒu_ݒ
					OldY = Graph.Height * (Resolution - Data(0)) / CSng(Resolution)					' Y̏lvZ
			End Select
			If OldY >= Graph.Height Then
				OldY = Graph.Height - 1				  ' Y̏lOt̕`̈𒴂ꍇAʒuC
			End If
			If OldY < 0 Then
				OldY = 0				 ' Y̏lOt̕`̈ꍇAʒuC
			End If

			'----------------------------------------------------
			' Wf[^A`揈JԂ܂B
			'----------------------------------------------------
			For j = 1 To MAX_SAMPLES - 1
				PosX = OldX + XUnit				  ' X̍WvZ
				Select Case i
					Case 0
						' f[^̕`ʒuݒ
						PosY = Graph.Height * (Resolution - UpperData(j)) / CSng(Resolution)						  ' Y̕`ʒuvZ
					Case 1
						' f[^̕`ʒuݒ
						PosY = Graph.Height * (Resolution - LowerData(j)) / CSng(Resolution)						  ' Y̕`ʒuvZ

					Case 2
						' Wf[^̕`ʒuݒ
						PosY = Graph.Height * (Resolution - Data(j)) / CSng(Resolution)						  ' Y̕`ʒuvZ
				End Select
				If PosY >= Graph.Height() Then
					' Y̍W`̈𒴂ꍇ
					PosY = Graph.Height() - 1					  ' `ʒȕC

				ElseIf PosY < 0 Then
					' Y̍W`̈ꍇ
					PosY = 0					  ' `ʒȕC
				End If
				grp.DrawLine(pen, OldX, OldY, PosX, PosY)				 ' `

				OldX = PosX				  ' X̍W`pɕێ
				OldY = PosY				  ' Y̍W`pɕێ
			Next j
		Next i
		pen.Dispose()		 ' \[X̉
		grp.Dispose()		 ' \[X̉
	End Sub

End Class