Public Class alarm
    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 Label6 As System.Windows.Forms.Label
	Friend WithEvents btnGet As System.Windows.Forms.Button
	Friend WithEvents btnSet As System.Windows.Forms.Button
	Friend WithEvents btnOK As System.Windows.Forms.Button
	Friend WithEvents txtLL As System.Windows.Forms.TextBox
	Friend WithEvents txtLU As System.Windows.Forms.TextBox
	Friend WithEvents txtUL As System.Windows.Forms.TextBox
	Friend WithEvents txtUU As System.Windows.Forms.TextBox
	Friend WithEvents cboAlarm As System.Windows.Forms.ComboBox
	Friend WithEvents txtChannel As System.Windows.Forms.TextBox
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Me.GroupBox1 = New System.Windows.Forms.GroupBox()
		Me.txtLL = New System.Windows.Forms.TextBox()
		Me.txtLU = New System.Windows.Forms.TextBox()
		Me.txtUL = New System.Windows.Forms.TextBox()
		Me.txtUU = New System.Windows.Forms.TextBox()
		Me.cboAlarm = New System.Windows.Forms.ComboBox()
		Me.txtChannel = New System.Windows.Forms.TextBox()
		Me.Label6 = New System.Windows.Forms.Label()
		Me.Label5 = New System.Windows.Forms.Label()
		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.btnGet = New System.Windows.Forms.Button()
		Me.btnSet = New System.Windows.Forms.Button()
		Me.btnOK = New System.Windows.Forms.Button()
		Me.GroupBox1.SuspendLayout()
		Me.SuspendLayout()
		'
		'GroupBox1
		'
		Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtLL, Me.txtLU, Me.txtUL, Me.txtUU, Me.cboAlarm, Me.txtChannel, Me.Label6, Me.Label5, Me.Label4, Me.Label3, Me.Label2, Me.Label1})
		Me.GroupBox1.Location = New System.Drawing.Point(18, 16)
		Me.GroupBox1.Name = "GroupBox1"
		Me.GroupBox1.Size = New System.Drawing.Size(312, 208)
		Me.GroupBox1.TabIndex = 0
		Me.GroupBox1.TabStop = False
		Me.GroupBox1.Text = "Alarm Setting"
		'
		'txtLL
		'
		Me.txtLL.Location = New System.Drawing.Point(137, 168)
		Me.txtLL.Name = "txtLL"
		Me.txtLL.Size = New System.Drawing.Size(96, 20)
		Me.txtLL.TabIndex = 11
		Me.txtLL.Text = ""
		'
		'txtLU
		'
		Me.txtLU.Location = New System.Drawing.Point(137, 141)
		Me.txtLU.Name = "txtLU"
		Me.txtLU.Size = New System.Drawing.Size(96, 20)
		Me.txtLU.TabIndex = 10
		Me.txtLU.Text = ""
		'
		'txtUL
		'
		Me.txtUL.Location = New System.Drawing.Point(137, 114)
		Me.txtUL.Name = "txtUL"
		Me.txtUL.Size = New System.Drawing.Size(96, 20)
		Me.txtUL.TabIndex = 9
		Me.txtUL.Text = ""
		'
		'txtUU
		'
		Me.txtUU.Location = New System.Drawing.Point(137, 87)
		Me.txtUU.Name = "txtUU"
		Me.txtUU.Size = New System.Drawing.Size(96, 20)
		Me.txtUU.TabIndex = 8
		Me.txtUU.Text = ""
		'
		'cboAlarm
		'
		Me.cboAlarm.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
		Me.cboAlarm.Items.AddRange(New Object() {"Disable", "Enable"})
		Me.cboAlarm.Location = New System.Drawing.Point(137, 59)
		Me.cboAlarm.Name = "cboAlarm"
		Me.cboAlarm.Size = New System.Drawing.Size(96, 21)
		Me.cboAlarm.TabIndex = 7
		'
		'txtChannel
		'
		Me.txtChannel.Location = New System.Drawing.Point(137, 32)
		Me.txtChannel.Name = "txtChannel"
		Me.txtChannel.Size = New System.Drawing.Size(96, 20)
		Me.txtChannel.TabIndex = 6
		Me.txtChannel.Text = ""
		'
		'Label6
		'
		Me.Label6.Location = New System.Drawing.Point(24, 170)
		Me.Label6.Name = "Label6"
		Me.Label6.Size = New System.Drawing.Size(112, 16)
		Me.Label6.TabIndex = 5
		Me.Label6.Text = "Lower Low-limit :"
		Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight
		'
		'Label5
		'
		Me.Label5.Location = New System.Drawing.Point(24, 142)
		Me.Label5.Name = "Label5"
		Me.Label5.Size = New System.Drawing.Size(112, 16)
		Me.Label5.TabIndex = 4
		Me.Label5.Text = "Higher Low-limit :"
		Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight
		'
		'Label4
		'
		Me.Label4.Location = New System.Drawing.Point(24, 116)
		Me.Label4.Name = "Label4"
		Me.Label4.Size = New System.Drawing.Size(112, 16)
		Me.Label4.TabIndex = 3
		Me.Label4.Text = "Lower High-limit :"
		Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
		'
		'Label3
		'
		Me.Label3.Location = New System.Drawing.Point(24, 89)
		Me.Label3.Name = "Label3"
		Me.Label3.Size = New System.Drawing.Size(112, 16)
		Me.Label3.TabIndex = 2
		Me.Label3.Text = "Higher High-limit :"
		Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
		'
		'Label2
		'
		Me.Label2.Location = New System.Drawing.Point(24, 60)
		Me.Label2.Name = "Label2"
		Me.Label2.Size = New System.Drawing.Size(112, 16)
		Me.Label2.TabIndex = 1
		Me.Label2.Text = "Alarm Enable :"
		Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
		'
		'Label1
		'
		Me.Label1.Location = New System.Drawing.Point(24, 34)
		Me.Label1.Name = "Label1"
		Me.Label1.Size = New System.Drawing.Size(112, 16)
		Me.Label1.TabIndex = 0
		Me.Label1.Text = "Channel Mumber :"
		Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
		'
		'btnGet
		'
		Me.btnGet.Location = New System.Drawing.Point(18, 248)
		Me.btnGet.Name = "btnGet"
		Me.btnGet.Size = New System.Drawing.Size(96, 28)
		Me.btnGet.TabIndex = 1
		Me.btnGet.Text = "Read"
		'
		'btnSet
		'
		Me.btnSet.Location = New System.Drawing.Point(126, 248)
		Me.btnSet.Name = "btnSet"
		Me.btnSet.Size = New System.Drawing.Size(96, 28)
		Me.btnSet.TabIndex = 2
		Me.btnSet.Text = "Set"
		'
		'btnOK
		'
		Me.btnOK.Location = New System.Drawing.Point(234, 248)
		Me.btnOK.Name = "btnOK"
		Me.btnOK.Size = New System.Drawing.Size(96, 28)
		Me.btnOK.TabIndex = 3
		Me.btnOK.Text = "Close"
		'
		'alarm
		'
		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
		Me.ClientSize = New System.Drawing.Size(350, 287)
		Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnOK, Me.btnSet, Me.btnGet, Me.GroupBox1})
		Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
		Me.MaximizeBox = False
		Me.MinimizeBox = False
		Me.Name = "alarm"
		Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
		Me.Text = "Alarm 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 alarm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		txtChannel.Text = "0"
		txtUU.Text = "0"
		txtUL.Text = "0"
		txtLU.Text = "0"
		txtLL.Text = "0"

		' Set the channel number to 0
		cboAlarm.SelectedIndex = 0
		btnGet_Click(btnGet, New System.EventArgs())

	End Sub

	'	Click the [Read] button
	Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click

		Dim ret As Integer
		Dim enable As Short
		Dim uu, ul, lu, ll As Integer

		' Get the alarm setting status
		ret = PtGetAlarm(m_Id, Val(txtChannel.Text), enable, uu, ul, lu, ll)
		If ret <> 0 Then
			ErrorHandling("PtGetAlarm", ret)
			Exit Sub
		End If

		' Reflect the setting status in dialog
		cboAlarm.SelectedIndex = enable
		txtUU.Text = uu / 100
		txtUL.Text = ul / 100
		txtLU.Text = lu / 100
		txtLL.Text = ll / 100

	End Sub

	'	Click the [Set] button
	Private Sub btnSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSet.Click

		Dim ret As Integer
		Dim enable As Short
		Dim uu, ul, lu, ll As Integer

		' Get the setting in the dialog
		enable = cboAlarm.SelectedIndex
		uu = Val(txtUU.Text) * 100
		ul = Val(txtUL.Text) * 100
		lu = Val(txtLU.Text) * 100
		ll = Val(txtLL.Text) * 100

		' Set alarm
		ret = PtSetAlarm(m_Id, Val(txtChannel.Text), enable, uu, ul, lu, ll)
		If ret <> 0 Then
			ErrorHandling("PtSetAlarm", ret)
			Exit Sub
		End If

	End Sub

	'	Click the [Close] button
	Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.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
