Public Class measure
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    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

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
	Friend WithEvents GroupBox1 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 btnOK As System.Windows.Forms.Button
	Friend WithEvents btnCancel As System.Windows.Forms.Button
	Friend WithEvents cboLinearize As System.Windows.Forms.ComboBox
	Friend WithEvents cboUpdate As System.Windows.Forms.ComboBox
	Friend WithEvents cboAverage As System.Windows.Forms.ComboBox
	Friend WithEvents txtAvCondition As System.Windows.Forms.TextBox
	Friend WithEvents Label6 As System.Windows.Forms.Label
	Friend WithEvents Label7 As System.Windows.Forms.Label
	Friend WithEvents txtDisable As System.Windows.Forms.TextBox
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Me.GroupBox1 = New System.Windows.Forms.GroupBox()
		Me.Label7 = New System.Windows.Forms.Label()
		Me.txtDisable = New System.Windows.Forms.TextBox()
		Me.Label6 = New System.Windows.Forms.Label()
		Me.Label5 = New System.Windows.Forms.Label()
		Me.txtAvCondition = New System.Windows.Forms.TextBox()
		Me.cboAverage = New System.Windows.Forms.ComboBox()
		Me.cboUpdate = New System.Windows.Forms.ComboBox()
		Me.cboLinearize = New System.Windows.Forms.ComboBox()
		Me.Label4 = New System.Windows.Forms.Label()
		Me.Label3 = New System.Windows.Forms.Label()
		Me.Label2 = New System.Windows.Forms.Label()
		Me.Label1 = New System.Windows.Forms.Label()
		Me.btnOK = New System.Windows.Forms.Button()
		Me.btnCancel = New System.Windows.Forms.Button()
		Me.GroupBox1.SuspendLayout()
		Me.SuspendLayout()
		'
		'GroupBox1
		'
		Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label7, Me.txtDisable, Me.Label6, Me.Label5, Me.txtAvCondition, Me.cboAverage, Me.cboUpdate, Me.cboLinearize, Me.Label4, Me.Label3, Me.Label2, Me.Label1})
		Me.GroupBox1.Location = New System.Drawing.Point(17, 15)
		Me.GroupBox1.Name = "GroupBox1"
		Me.GroupBox1.Size = New System.Drawing.Size(430, 190)
		Me.GroupBox1.TabIndex = 0
		Me.GroupBox1.TabStop = False
		Me.GroupBox1.Text = "Measurement Setting"
		'
		'Label7
		'
		Me.Label7.Location = New System.Drawing.Point(356, 153)
		Me.Label7.Name = "Label7"
		Me.Label7.Size = New System.Drawing.Size(56, 16)
		Me.Label7.TabIndex = 11
		Me.Label7.Text = "Hex"
		'
		'txtDisable
		'
		Me.txtDisable.Location = New System.Drawing.Point(212, 151)
		Me.txtDisable.Name = "txtDisable"
		Me.txtDisable.Size = New System.Drawing.Size(136, 20)
		Me.txtDisable.TabIndex = 10
		Me.txtDisable.Text = ""
		'
		'Label6
		'
		Me.Label6.Location = New System.Drawing.Point(6, 153)
		Me.Label6.Name = "Label6"
		Me.Label6.Size = New System.Drawing.Size(200, 16)
		Me.Label6.TabIndex = 9
		Me.Label6.Text = "Conversion Disabled Channels (0 - F) :"
		Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight
		'
		'Label5
		'
		Me.Label5.Location = New System.Drawing.Point(356, 124)
		Me.Label5.Name = "Label5"
		Me.Label5.Size = New System.Drawing.Size(56, 16)
		Me.Label5.TabIndex = 8
		Me.Label5.Text = "Times/ms"
		'
		'txtAvCondition
		'
		Me.txtAvCondition.Location = New System.Drawing.Point(212, 122)
		Me.txtAvCondition.Name = "txtAvCondition"
		Me.txtAvCondition.Size = New System.Drawing.Size(136, 20)
		Me.txtAvCondition.TabIndex = 7
		Me.txtAvCondition.Text = ""
		'
		'cboAverage
		'
		Me.cboAverage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.cboAverage.Items.AddRange(New Object() {"Not Averaging", "Average on Times", "Average on Time"})
		Me.cboAverage.Location = New System.Drawing.Point(212, 92)
		Me.cboAverage.Name = "cboAverage"
		Me.cboAverage.Size = New System.Drawing.Size(136, 21)
		Me.cboAverage.TabIndex = 6
		'
		'cboUpdate
		'
		Me.cboUpdate.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.cboUpdate.Items.AddRange(New Object() {"150ms", "40ms", "5ms", "1.5ms"})
		Me.cboUpdate.Location = New System.Drawing.Point(212, 62)
		Me.cboUpdate.Name = "cboUpdate"
		Me.cboUpdate.Size = New System.Drawing.Size(136, 21)
		Me.cboUpdate.TabIndex = 5
		'
		'cboLinearize
		'
		Me.cboLinearize.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.cboLinearize.Items.AddRange(New Object() {"Temperature", "Resistance Capacity"})
		Me.cboLinearize.Location = New System.Drawing.Point(212, 32)
		Me.cboLinearize.Name = "cboLinearize"
		Me.cboLinearize.Size = New System.Drawing.Size(136, 21)
		Me.cboLinearize.TabIndex = 4
		'
		'Label4
		'
		Me.Label4.Location = New System.Drawing.Point(94, 124)
		Me.Label4.Name = "Label4"
		Me.Label4.Size = New System.Drawing.Size(112, 16)
		Me.Label4.TabIndex = 3
		Me.Label4.Text = "Averaging Condition :"
		Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
		'
		'Label3
		'
		Me.Label3.Location = New System.Drawing.Point(142, 94)
		Me.Label3.Name = "Label3"
		Me.Label3.Size = New System.Drawing.Size(64, 16)
		Me.Label3.TabIndex = 2
		Me.Label3.Text = "Averaging :"
		Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
		'
		'Label2
		'
		Me.Label2.Location = New System.Drawing.Point(126, 64)
		Me.Label2.Name = "Label2"
		Me.Label2.Size = New System.Drawing.Size(80, 16)
		Me.Label2.TabIndex = 1
		Me.Label2.Text = "Update Rate :"
		Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
		'
		'Label1
		'
		Me.Label1.Location = New System.Drawing.Point(150, 34)
		Me.Label1.Name = "Label1"
		Me.Label1.Size = New System.Drawing.Size(56, 16)
		Me.Label1.TabIndex = 0
		Me.Label1.Text = "Linearize :"
		Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
		'
		'btnOK
		'
		Me.btnOK.Location = New System.Drawing.Point(231, 224)
		Me.btnOK.Name = "btnOK"
		Me.btnOK.Size = New System.Drawing.Size(96, 24)
		Me.btnOK.TabIndex = 1
		Me.btnOK.Text = "OK"
		'
		'btnCancel
		'
		Me.btnCancel.Location = New System.Drawing.Point(335, 224)
		Me.btnCancel.Name = "btnCancel"
		Me.btnCancel.Size = New System.Drawing.Size(96, 24)
		Me.btnCancel.TabIndex = 2
		Me.btnCancel.Text = "Cancel"
		'
		'measure
		'
		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
		Me.ClientSize = New System.Drawing.Size(474, 264)
		Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnCancel, Me.btnOK, Me.GroupBox1})
		Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
		Me.MaximizeBox = False
		Me.MinimizeBox = False
		Me.Name = "measure"
		Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
		Me.Text = "Measurement Setting"
		Me.GroupBox1.ResumeLayout(False)
		Me.ResumeLayout(False)

	End Sub

#End Region
	Dim m_Id As Short

	'	Get the caller ID
	Public Sub SetId(ByVal id As Short)

		m_Id = id

	End Sub

	'	Initialize dialog
	Private Sub measure_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		Dim ret As Integer
		Dim linearize, averagetype As Short
		Dim updatetiming, averagedata As Integer
		Dim channeldisable As Integer

		txtAvCondition.Text = "0"
		' Get the linearize function
		ret = PtGetLinearise(m_Id, linearize)
		If ret <> 0 Then
			ErrorHandling("PtGetLinearise", ret)
			Exit Sub
		End If
		cboLinearize.SelectedIndex = linearize

		' Get the update timing
		ret = PtGetUpdateTiming(m_Id, updatetiming)
		If ret <> 0 Then
			ErrorHandling("PtGetUpdateTiming", ret)
			Exit Sub
		End If
		Select Case updatetiming
			Case SPEED_150MS
				cboUpdate.SelectedIndex = 0
			Case SPEED_40MS
				cboUpdate.SelectedIndex = 1
			Case SPEED_5MS
				cboUpdate.SelectedIndex = 2
			Case SPEED_1P5MS
				cboUpdate.SelectedIndex = 3
		End Select

		' Get the average function
		ret = PtGetAverage(m_Id, averagetype, averagedata)
		If ret <> 0 Then
			ErrorHandling("PtGetAverage", ret)
			Exit Sub
		End If
		cboAverage.SelectedIndex = averagetype
		txtAvCondition.Text = averagedata

		' Get the conversion disabled channels
		ret = PtGetChannelDisable(m_Id, channeldisable)
		If ret <> 0 Then
			ErrorHandling("PtGetChannelDisable", ret)
			Exit Sub
		End If
		TxtDisable.Text = Hex(channeldisable)

	End Sub

	'	Click the [OK] button
	Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

		Dim ret As Integer
		Dim index As Integer
		Dim updatetiming As Integer
		Dim str As New String("", 100)
		Dim channeldisable As Integer

		' Set the linearize function
		index = cboLinearize.SelectedIndex
		ret = PtSetLinearise(m_Id, index)
		If ret <> 0 Then
			ErrorHandling("PtSetLinearise", ret)
		End If

		' Set the update timing
		index = cboUpdate.SelectedIndex
		Select Case index
			Case 0
				updatetiming = SPEED_150MS
			Case 1
				updatetiming = SPEED_40MS
			Case 2
				updatetiming = SPEED_5MS
			Case 3
				updatetiming = SPEED_1P5MS
		End Select
		ret = PtSetUpdateTiming(m_Id, updatetiming)
		If ret <> 0 Then
			ErrorHandling("PtSetUpdateTiming", ret)
		End If

		' Set the average function
		index = cboAverage.SelectedIndex
		ret = PtSetAverage(m_Id, index, Val(txtAvCondition.Text))
		If ret <> 0 Then
			ErrorHandling("PtSetAverage", ret)
		End If

		' Set the conversion disabled channels
		channeldisable = Val("&H" + txtDisable.Text)
		ret = PtSetChannelDisable(m_Id, channeldisable)
		If ret <> 0 Then
			ErrorHandling("PtSetChannelDisable", ret)
		End If

		Me.Close()

	End Sub

	'	Click the [Cancel] button
	Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click

		Me.Close()

	End Sub

	'	Process error
	Private Sub ErrorHandling(ByVal Dfunction As String, ByVal ret As Integer)

		Dim errstr As New System.Text.StringBuilder("", 256)
		PtGetErrorString(ret, errstr)
		MsgBox(errstr.ToString(), MsgBoxStyle.OKOnly, Dfunction)

	End Sub
End Class
