Option Strict Off
Option Explicit On 
Imports System.Runtime.InteropServices

Friend Class frmTempFan
    Inherits System.Windows.Forms.Form

#Region " Windows tH[ fUCiŐꂽR[h "

    Public Sub New()
        MyBase.New()

        ' ̌Ăяo Windows tH[ fUCiŕKvłB
        InitializeComponent()

        ' InitializeComponent() Ăяǒɏǉ܂B

    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

    '  : ȉ̃vV[ẂAWindows tH[ fUCiŕKvłB
    'Windows tH[ fUCigĕύXĂB  
    ' R[h GfB^gĕύXȂłB
    Public WithEvents Frame2 As System.Windows.Forms.GroupBox
    Public WithEvents lblTemp1 As System.Windows.Forms.Label
    Public WithEvents lblTemp2 As System.Windows.Forms.Label
    Public WithEvents Frame4 As System.Windows.Forms.GroupBox
    Public WithEvents _lblFan_0 As System.Windows.Forms.Label
    Public WithEvents _lblFan_1 As System.Windows.Forms.Label
    Public WithEvents _lblFan_2 As System.Windows.Forms.Label
    Public WithEvents _lblFan_3 As System.Windows.Forms.Label
    Public WithEvents _lblFan_4 As System.Windows.Forms.Label
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmTempFan))
        Me.Frame2 = New System.Windows.Forms.GroupBox
        Me.lblTemp1 = New System.Windows.Forms.Label
        Me.lblTemp2 = New System.Windows.Forms.Label
        Me.Frame4 = New System.Windows.Forms.GroupBox
        Me._lblFan_0 = New System.Windows.Forms.Label
        Me._lblFan_1 = New System.Windows.Forms.Label
        Me._lblFan_2 = New System.Windows.Forms.Label
        Me._lblFan_3 = New System.Windows.Forms.Label
        Me._lblFan_4 = New System.Windows.Forms.Label
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.Frame2.SuspendLayout()
        Me.Frame4.SuspendLayout()
        Me.SuspendLayout()
        '
        'Frame2
        '
        Me.Frame2.BackColor = System.Drawing.SystemColors.Control
        Me.Frame2.Controls.Add(Me.lblTemp1)
        Me.Frame2.Controls.Add(Me.lblTemp2)
        Me.Frame2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame2.Location = New System.Drawing.Point(11, 9)
        Me.Frame2.Name = "Frame2"
        Me.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame2.Size = New System.Drawing.Size(105, 105)
        Me.Frame2.TabIndex = 1
        Me.Frame2.TabStop = False
        Me.Frame2.Text = "Temp"
        '
        'lblTemp1
        '
        Me.lblTemp1.BackColor = System.Drawing.SystemColors.Control
        Me.lblTemp1.Cursor = System.Windows.Forms.Cursors.Default
        Me.lblTemp1.Font = New System.Drawing.Font("lr SVbN", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblTemp1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.lblTemp1.Location = New System.Drawing.Point(16, 19)
        Me.lblTemp1.Name = "lblTemp1"
        Me.lblTemp1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.lblTemp1.Size = New System.Drawing.Size(74, 17)
        Me.lblTemp1.TabIndex = 2
        Me.lblTemp1.Text = "Label1"
        '
        'lblTemp2
        '
        Me.lblTemp2.BackColor = System.Drawing.SystemColors.Control
        Me.lblTemp2.Cursor = System.Windows.Forms.Cursors.Default
        Me.lblTemp2.Font = New System.Drawing.Font("lr SVbN", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.lblTemp2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.lblTemp2.Location = New System.Drawing.Point(16, 35)
        Me.lblTemp2.Name = "lblTemp2"
        Me.lblTemp2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.lblTemp2.Size = New System.Drawing.Size(74, 17)
        Me.lblTemp2.TabIndex = 1
        Me.lblTemp2.Text = "Label1"
        '
        'Frame4
        '
        Me.Frame4.BackColor = System.Drawing.SystemColors.Control
        Me.Frame4.Controls.Add(Me._lblFan_0)
        Me.Frame4.Controls.Add(Me._lblFan_1)
        Me.Frame4.Controls.Add(Me._lblFan_2)
        Me.Frame4.Controls.Add(Me._lblFan_3)
        Me.Frame4.Controls.Add(Me._lblFan_4)
        Me.Frame4.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame4.Location = New System.Drawing.Point(128, 9)
        Me.Frame4.Name = "Frame4"
        Me.Frame4.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame4.Size = New System.Drawing.Size(105, 105)
        Me.Frame4.TabIndex = 4
        Me.Frame4.TabStop = False
        Me.Frame4.Text = "FAN"
        '
        '_lblFan_0
        '
        Me._lblFan_0.AutoSize = True
        Me._lblFan_0.BackColor = System.Drawing.SystemColors.Control
        Me._lblFan_0.Cursor = System.Windows.Forms.Cursors.Default
        Me._lblFan_0.Font = New System.Drawing.Font("lr SVbN", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me._lblFan_0.ForeColor = System.Drawing.SystemColors.ControlText
        Me._lblFan_0.Location = New System.Drawing.Point(16, 19)
        Me._lblFan_0.Name = "_lblFan_0"
        Me._lblFan_0.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me._lblFan_0.Size = New System.Drawing.Size(42, 15)
        Me._lblFan_0.TabIndex = 8
        Me._lblFan_0.Text = "Label1"
        '
        '_lblFan_1
        '
        Me._lblFan_1.AutoSize = True
        Me._lblFan_1.BackColor = System.Drawing.SystemColors.Control
        Me._lblFan_1.Cursor = System.Windows.Forms.Cursors.Default
        Me._lblFan_1.Font = New System.Drawing.Font("lr SVbN", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me._lblFan_1.ForeColor = System.Drawing.SystemColors.ControlText
        Me._lblFan_1.Location = New System.Drawing.Point(16, 35)
        Me._lblFan_1.Name = "_lblFan_1"
        Me._lblFan_1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me._lblFan_1.Size = New System.Drawing.Size(42, 15)
        Me._lblFan_1.TabIndex = 7
        Me._lblFan_1.Text = "Label1"
        '
        '_lblFan_2
        '
        Me._lblFan_2.AutoSize = True
        Me._lblFan_2.BackColor = System.Drawing.SystemColors.Control
        Me._lblFan_2.Cursor = System.Windows.Forms.Cursors.Default
        Me._lblFan_2.Font = New System.Drawing.Font("lr SVbN", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me._lblFan_2.ForeColor = System.Drawing.SystemColors.ControlText
        Me._lblFan_2.Location = New System.Drawing.Point(16, 51)
        Me._lblFan_2.Name = "_lblFan_2"
        Me._lblFan_2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me._lblFan_2.Size = New System.Drawing.Size(42, 15)
        Me._lblFan_2.TabIndex = 6
        Me._lblFan_2.Text = "Label1"
        '
        '_lblFan_3
        '
        Me._lblFan_3.AutoSize = True
        Me._lblFan_3.BackColor = System.Drawing.SystemColors.Control
        Me._lblFan_3.Cursor = System.Windows.Forms.Cursors.Default
        Me._lblFan_3.Font = New System.Drawing.Font("lr SVbN", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me._lblFan_3.ForeColor = System.Drawing.SystemColors.ControlText
        Me._lblFan_3.Location = New System.Drawing.Point(16, 67)
        Me._lblFan_3.Name = "_lblFan_3"
        Me._lblFan_3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me._lblFan_3.Size = New System.Drawing.Size(42, 15)
        Me._lblFan_3.TabIndex = 5
        Me._lblFan_3.Text = "Label1"
        '
        '_lblFan_4
        '
        Me._lblFan_4.AutoSize = True
        Me._lblFan_4.BackColor = System.Drawing.SystemColors.Control
        Me._lblFan_4.Cursor = System.Windows.Forms.Cursors.Default
        Me._lblFan_4.Font = New System.Drawing.Font("lr SVbN", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me._lblFan_4.ForeColor = System.Drawing.SystemColors.ControlText
        Me._lblFan_4.Location = New System.Drawing.Point(16, 83)
        Me._lblFan_4.Name = "_lblFan_4"
        Me._lblFan_4.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me._lblFan_4.Size = New System.Drawing.Size(42, 15)
        Me._lblFan_4.TabIndex = 4
        Me._lblFan_4.Text = "Label1"
        '
        'Timer1
        '
        '
        'frmTempFan
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(244, 125)
        Me.Controls.Add(Me.Frame4)
        Me.Controls.Add(Me.Frame2)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Location = New System.Drawing.Point(3, 22)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmTempFan"
        Me.Text = "Temp/Fan State"
        Me.Frame2.ResumeLayout(False)
        Me.Frame4.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    '*****************************************************************************
    '   t@C F frmTenpFan.vb
    '
    '   @\ F x^FANXe[^X\@\
    '
    '
    ' Copyright (C) NEC Corporation 2009
    '*****************************************************************************


    '*****************************************************************************
    ' x/FAN擾p萔`
    '*****************************************************************************

    ' RETURNXe[^X
    Private Const FCSRASAPI_SUCCESS As Short = &H0S
    Private Const FCSRASAPI_DRVERR As Short = &H1S

    Private strFan(4) As String

    ' xRg[z̃tB[h쐬
    Private lblFanAry() As System.Windows.Forms.Label

    '*****************************************************************************
    ' \tgRASI/F`
    '*****************************************************************************
    Private Declare Function fcsoftrasOpen Lib "FcSrasapiP.dll" Alias "fcsoftrasOpenP" () As Integer
    Private Declare Function fcsoftrasClose Lib "FcSrasapiP.dll" Alias "fcsoftrasCloseP" () As Integer
    Private Declare Function fcsoftrasGetTemp Lib "FcSrasapiP.dll" Alias "fcsoftrasGetTempP" (<MarshalAs(UnmanagedType.SafeArray)> ByRef buff() As Byte) As Integer
    Private Declare Function fcsoftrasGetFan Lib "FcSrasapiP.dll" Alias "fcsoftrasGetFanP" (<MarshalAs(UnmanagedType.SafeArray)> ByRef buff() As Byte) As Integer
    Private Declare Function fcsoftrasGetFanInf Lib "FcSrasapiP.dll" Alias "fcsoftrasGetFanInfP" (<MarshalAs(UnmanagedType.SafeArray)> ByRef buff() As Byte) As Integer

    '****************************************************
    '   ֐ F frmTempFan_Load
    '   @\   Fʂ̋N()
    '      F Ȃ
    '   ߂l F Ȃ
    '****************************************************
    Private Sub frmTempFan_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

        ' xRg[z̍쐬
        Me.lblFanAry = New System.Windows.Forms.Label(4) {}

        ' xRg[̔zɂłɍ쐬ĂCX^X
        lblFanAry(0) = _lblFan_0
        lblFanAry(1) = _lblFan_1
        lblFanAry(2) = _lblFan_2
        lblFanAry(3) = _lblFan_3
        lblFanAry(4) = _lblFan_4

        ' ƃtH_st@CtH_ɕύX DLLǂݏo
        ChDrive(Application.StartupPath)
        ChDir(Application.StartupPath)

        ' \tgRAS̃Cu
        Call fcsoftrasOpen()

        strFan(0) = "FAN1 :"
        strFan(1) = "FAN2 :"
        strFan(2) = "FAN3 :"
        strFan(3) = "FAN4 :"
        strFan(4) = "FAN5 :"

        ' ݂̏Ԃ擾Ɖʂւ̔f
        Call subSetTemp()
        Call subSetFan()

        ' ʍXVp̃^C}[ݒ
        Timer1.Interval = 10000     ' PObݒ
        Timer1.Enabled = True       ' L

    End Sub

    '****************************************************
    '   ֐ F frmTempFan_Closed
    '   @\   Fʂ̏I(㏈)
    '      F Ȃ
    '   ߂l F Ȃ
    '****************************************************
    Private Sub frmTempFan_Closed(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Closed
        ' \tgRAS̃CuI
        Call fcsoftrasClose()
    End Sub


    '****************************************************
    '   ֐ F Timer1_Tick
    '   @\   F^C}[ɂʍXV
    '      F Ȃ
    '   ߂l F Ȃ
    '****************************************************
    Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
        ' ݂̏Ԃ擾Ɖʂւ̔f
        Call subSetTemp()
        Call subSetFan()
    End Sub

    '****************************************************
    '   ֐ F subSetTemp
    '   @\   Fx̏Ԃ擾Aʂ̍XVsȂ
    '      F Ȃ
    '   ߂l F Ȃ
    '****************************************************
    Private Sub subSetTemp()
        Dim buff(3) As Byte ' xXe[^Xۑp
        Dim Ret As Short ' ߂lۑp

        Ret = fcsoftrasGetTemp(buff)
        ' xf[^擾H
        If FCSRASAPI_SUCCESS = Ret Then
            lblTemp1.Text = "CPU   :" & buff(2)
            lblTemp2.Text = "SYSTEM:" & buff(3)
        Else
            lblTemp1.Text = "NG"
            lblTemp2.Text = "NG"
            Timer1.Enabled = False
        End If

    End Sub

    '****************************************************
    '   ֐ F subSetFan
    '   @\   FFAN̏Ԃ擾Aʂ̍XVsȂ
    '      F Ȃ
    '   ߂l F Ȃ
    '****************************************************
    Private Sub subSetFan()
        Dim buff1(0) As Byte ' FANڑXe[^Xۑp
        Dim buff2(10) As Byte ' FANXe[^Xۑp
        Dim count1 As Short
        Dim Ret As Short ' ߂lۑp

        Ret = fcsoftrasGetFanInf(buff1)
        ' FANڑ擾H
        If FCSRASAPI_SUCCESS = Ret Then
            Ret = fcsoftrasGetFan(buff2)
            ' FANf[^擾H
            If FCSRASAPI_SUCCESS = Ret Then
                For count1 = 0 To 4
                    If ((buff1(0) And (2 ^ count1)) <> 0) Then
                        ' FANڑ
                        lblFanAry(count1).Text = strFan(count1) & (buff2(count1 * 2 + 1) + (buff2(count1 * 2 + 2) * &H100S))
                    Else
                        ' FANڑȂ
                        lblFanAry(count1).Text = strFan(count1) & "None"
                    End If
                Next count1
            Else
                lblFanAry(0).Text = "NG"
                Timer1.Enabled = False
            End If
        Else
            lblFanAry(0).Text = "NG"
            Timer1.Enabled = False
        End If

    End Sub
End Class
