Option Strict Off
Option Explicit On 

Imports System.Runtime.InteropServices

Module Module1
	'/***********************************************************************/
	'/*                                                                     */
	'/*     IF_50  ＡＰＩ用ヘッダーファイル                                 */
	'/*                                                                     */
	'/*     Copyright(c) 2012  TEXIO TECHNOLOGY CORPORATION                 */
	'/***********************************************************************/

    Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

	'IF_50用標準モジュール
	
	'********************************************************************************
	'   構造体宣言
	'********************************************************************************
	'モニターデータ構造体
    <StructLayout(LayoutKind.Sequential)> Public Structure MONITOR_DATA
        Dim Current As Double '電流モニター値
        Dim Voltage As Double '電圧モニター値
        Dim Wattage As Double '電力モニター値
    End Structure

    '放電負荷モード設定データ構造体
    <StructLayout(LayoutKind.Sequential)> Public Structure MODE_DATA
        Dim Mode As Integer '放電負荷モード設定
        Dim Reference As Integer 'コントロールリファレンス設定
    End Structure

    'スイッチング時間設定データ構造体
    <StructLayout(LayoutKind.Sequential)> Public Structure TIME_DATA
        Dim Ta As Double '時間ｔａ設定
        Dim Tb As Double '時間ｔｂ設定
    End Structure

    'トラッキング設定データ構造体
    <StructLayout(LayoutKind.Sequential)> Public Structure TRACK_DATA
        Dim Ch_A As Integer 'ＣＨ−Ａ
        Dim Ch_B As Integer 'ＣＨ−Ｂ
        Dim Ch_C As Integer 'ＣＨ−Ｃ
        Dim Ch_D As Integer 'ＣＨ−Ｄ
    End Structure

    'アラームデータ構造体
    <StructLayout(LayoutKind.Sequential)> Public Structure ALARM_DATA
        Dim Eta As Integer      '外部アラーム
        Dim Oha As Integer      'オーバーヒートアラーム
        Dim Ova_A As Integer
        Dim Ova_B As Integer
        Dim Ova_C As Integer
        Dim Ova_D As Integer
        Dim Oca_A As Integer
        Dim Oca_B As Integer
        Dim Oca_C As Integer
        Dim Oca_D As Integer
        Dim Ora_A As Integer
        Dim Ora_B As Integer
        Dim Ora_C As Integer
        Dim Ora_D As Integer
    End Structure

    'リミットデータ構造体
    <StructLayout(LayoutKind.Sequential)> Public Structure LIMIT_DATA
        Dim Current_A As Integer
        Dim Current_B As Integer
        Dim Current_C As Integer
        Dim Current_D As Integer
        Dim Power_A As Integer
        Dim Power_B As Integer
        Dim Power_C As Integer
        Dim Power_D As Integer
    End Structure

    'ＣＨ実装データ構造体
    <StructLayout(LayoutKind.Sequential)> Public Structure CH_DATA
        Dim Ch_A As Integer 'ＣＨ−Ａ
        Dim Ch_B As Integer 'ＣＨ−Ｂ
        Dim Ch_C As Integer 'ＣＨ−Ｃ
        Dim Ch_D As Integer 'ＣＨ−Ｄ
    End Structure


    '********************************************************************************
    '   ＡＰＩ宣言
    '********************************************************************************
    Declare Function LW_DeviceOpen Lib "IF_50" (ByVal Class_Renamed As Integer, ByVal BoardAdrs As Integer, ByVal PcAdrs As Integer, ByVal SysAdrs As Integer) As Integer
    Declare Function LW_DeviceClose Lib "IF_50" (ByVal DeviceId As Integer) As Integer
    Declare Function LW_DeviceRefresh Lib "IF_50" (ByVal DeviceId As Integer) As Integer
    Declare Function LW_SetTimeOut Lib "IF_50" (ByVal DeviceId As Integer, ByVal Time As Integer) As Integer
    Declare Function LW_SetMainInput Lib "IF_50" (ByVal DeviceId As Integer, ByVal Flag As Integer) As Integer
    Declare Function LW_GetMainInput Lib "IF_50" (ByVal DeviceId As Integer) As Integer
    Declare Function LW_SetInputSelect Lib "IF_50" (ByVal DeviceId As Integer, ByVal CH As Integer, ByVal Flag As Integer) As Integer
    Declare Function LW_GetInputSelect Lib "IF_50" (ByVal DeviceId As Integer, ByVal CH As Integer) As Integer
    Declare Function LW_SetPresetNumber Lib "IF_50" (ByVal DeviceId As Integer, ByVal Preset As Integer) As Integer
    Declare Function LW_GetPresetNumber Lib "IF_50" (ByVal DeviceId As Integer) As Integer
    Declare Function LW_SavePreset Lib "IF_50" (ByVal DeviceId As Integer, ByVal Src As Integer, ByVal Dest As Integer) As Integer
    Declare Function LW_GetMonitor Lib "IF_50" (ByVal DeviceId As Integer, ByVal CH As Integer, ByRef Monitor As MONITOR_DATA) As Integer
    Declare Function LW_SetMonitorSelect Lib "IF_50" (ByVal DeviceId As Integer, ByVal Flag As Integer) As Integer
    Declare Function LW_GetMonitorSelect Lib "IF_50" (ByVal DeviceId As Integer) As Integer
    Declare Function LW_SetDisplaySelect Lib "IF_50" (ByVal DeviceId As Integer, ByVal CH As Integer) As Integer
    Declare Function LW_GetDisplaySelect Lib "IF_50" (ByVal DeviceId As Integer) As Integer
    Declare Function LW_SetLoadMode Lib "IF_50" (ByVal DeviceId As Integer, ByVal Preset As Integer, ByVal CH As Integer, ByVal Mode As Integer, ByVal Ref As Integer) As Integer
    Declare Function LW_GetLoadMode Lib "IF_50" (ByVal DeviceId As Integer, ByVal Preset As Integer, ByVal CH As Integer, ByRef ModeData As MODE_DATA) As Integer
    Declare Function LW_SetLoadValue Lib "IF_50" (ByVal DeviceId As Integer, ByVal Preset As Integer, ByVal CH As Integer, ByVal Data As Double) As Integer
    Declare Function LW_GetLoadValue Lib "IF_50" (ByVal DeviceId As Integer, ByVal Preset As Integer, ByVal CH As Integer, ByRef Data As Double) As Integer
    Declare Function LW_SetSiemensValue Lib "IF_50" (ByVal DeviceId As Integer, ByVal Preset As Integer, ByVal CH As Integer, ByVal Data As Integer) As Integer
    Declare Function LW_GetSiemensValue Lib "IF_50" (ByVal DeviceId As Integer, ByVal Preset As Integer, ByVal CH As Integer, ByRef Data As Integer) As Integer
    Declare Function LW_SetCurrentLimit Lib "IF_50" (ByVal DeviceId As Integer, ByVal Preset As Integer, ByVal CH As Integer, ByVal Data As Double) As Integer
    Declare Function LW_GetCurrentLimit Lib "IF_50" (ByVal DeviceId As Integer, ByVal Preset As Integer, ByVal CH As Integer, ByRef Data As Double) As Integer
    Declare Function LW_SaveLoadValue Lib "IF_50" (ByVal DeviceId As Integer, ByVal Preset As Integer, ByVal CH As Integer) As Integer
    Declare Function LW_SaveCurrentLimit Lib "IF_50" (ByVal DeviceId As Integer, ByVal Preset As Integer, ByVal CH As Integer) As Integer
    Declare Function LW_SaveMemoryData Lib "IF_50" (ByVal DeviceId As Integer, ByVal Object_Renamed As Integer) As Integer
    Declare Function LW_SetSwSelect Lib "IF_50" (ByVal DeviceId As Integer, ByVal CH As Integer, ByVal Flag As Integer) As Integer
    Declare Function LW_GetSwSelect Lib "IF_50" (ByVal DeviceId As Integer, ByVal CH As Integer) As Integer
    Declare Function LW_SetSwFreq Lib "IF_50" (ByVal DeviceId As Integer, ByVal Freq As Integer) As Integer
    Declare Function LW_GetSwFreq Lib "IF_50" (ByVal DeviceId As Integer, ByRef Freq As Integer) As Integer
    Declare Function LW_SetSwDuty Lib "IF_50" (ByVal DeviceId As Integer, ByVal Duty As Integer) As Integer
    Declare Function LW_GetSwDuty Lib "IF_50" (ByVal DeviceId As Integer, ByRef Duty As Integer) As Integer
    Declare Function LW_SetSwTime Lib "IF_50" (ByVal DeviceId As Integer, ByVal Ta As Double, ByVal Tb As Double) As Integer
    Declare Function LW_GetSwTime Lib "IF_50" (ByVal DeviceId As Integer, ByRef Time As TIME_DATA) As Integer
    Declare Function LW_SetSwMethod Lib "IF_50" (ByVal DeviceId As Integer, ByVal Flag As Integer) As Integer
    Declare Function LW_GetSwMethod Lib "IF_50" (ByVal DeviceId As Integer) As Integer
    Declare Function LW_SetDelayFunction Lib "IF_50" (ByVal DeviceId As Integer, ByVal Flag As Integer) As Integer
    Declare Function LW_GetDelayFunction Lib "IF_50" (ByVal DeviceId As Integer) As Integer
    Declare Function LW_SetDelayTime Lib "IF_50" (ByVal DeviceId As Integer, ByVal CH As Integer, ByVal Time As Double) As Integer
    Declare Function LW_GetDelayTime Lib "IF_50" (ByVal DeviceId As Integer, ByVal CH As Integer, ByRef Time As Double) As Integer
    Declare Function LW_SetTrackFunction Lib "IF_50" (ByVal DeviceId As Integer, ByVal Flag As Integer) As Integer
    Declare Function LW_GetTrackFunction Lib "IF_50" (ByVal DeviceId As Integer) As Integer
    Declare Function LW_SetTrackDirection Lib "IF_50" (ByVal DeviceId As Integer, ByVal ChA As Integer, ByVal ChB As Integer, ByVal ChC As Integer, ByVal ChD As Integer) As Integer
    Declare Function LW_GetTrackDirection Lib "IF_50" (ByVal DeviceId As Integer, ByRef Track As TRACK_DATA) As Integer
    Declare Function LW_SetTrackMode Lib "IF_50" (ByVal DeviceId As Integer, ByVal Mode As Integer) As Integer
    Declare Function LW_GetTrackMode Lib "IF_50" (ByVal DeviceId As Integer) As Integer
    Declare Function LW_SetTrackValue Lib "IF_50" (ByVal DeviceId As Integer, ByVal Data As Double) As Integer
    Declare Function LW_GetTrackValue Lib "IF_50" (ByVal DeviceId As Integer, ByRef Data As Double) As Integer
    Declare Function LW_ResetAlarm Lib "IF_50" (ByVal DeviceId As Integer) As Integer
    Declare Function LW_GetAlarm Lib "IF_50" (ByVal DeviceId As Integer, ByRef Alarm As ALARM_DATA) As Integer
    Declare Function LW_GetLimit Lib "IF_50" (ByVal DeviceId As Integer, ByRef Limit As LIMIT_DATA) As Integer
    Declare Function LW_SetOperationTimeOut Lib "IF_50" (ByVal DeviceId As Integer, ByVal Time As Integer) As Integer
    Declare Function LW_GetOperationTimeOut Lib "IF_50" (ByVal DeviceId As Integer) As Integer
    Declare Function LW_SetLocal Lib "IF_50" (ByVal DeviceId As Integer) As Integer
    Declare Function LW_SetLocalLockOut Lib "IF_50" (ByVal DeviceId As Integer, ByVal Flag As Integer) As Integer
    Declare Function LW_GetLocalLockOut Lib "IF_50" (ByVal DeviceId As Integer) As Integer
    Declare Function LW_GetIdNumber Lib "IF_50" (ByVal DeviceId As Integer) As Integer
    Declare Function LW_GetChExist Lib "IF_50" (ByVal DeviceId As Integer, ByRef ChData As CH_DATA) As Integer

    '********************************************************************************
    '   定数宣言
    '********************************************************************************
    'デバイス種別
    Public Const GPIB As Short = 1 'ＧＰＩＢ
    Public Const USB As Short = 2 'ＵＳＢ

    'エラーフラグ
    Public Const DEV_ERR As Short = -1 'デバイスエラー
    Public Const TO_ERR As Short = -2 'タイムアウトエラー
    Public Const PAR_ERR As Short = -3 'パラメータエラー
    Public Const RCV_ERR As Short = -4 '受信エラー

    '制御フラグ
    Public Const XOFF As Short = 0 'ＯＦＦ
    Public Const XON As Short = 1 'ＯＮ

    '表示切り替えフラグ
    Public Const VOLT As Short = 0 '電流／電圧表示
    Public Const WATT As Short = 1 '電流／電力表示

    'ＣＨ設定値
    Public Const Ch_A As Short = 1 'ＣＨ−Ａ
    Public Const Ch_B As Short = 2 'ＣＨ−Ｂ
    Public Const Ch_C As Short = 3 'ＣＨ−Ｃ
    Public Const Ch_D As Short = 4 'ＣＨ−Ｄ

    'プリセット設定値
    Public Const PR_1 As Short = 1 'プリセット番号１
    Public Const PR_2 As Short = 2 'プリセット番号２
    Public Const PR_3 As Short = 3 'プリセット番号３
    Public Const PR_4 As Short = 4 'プリセット番号４

    '放電負荷モード設定値
    Public Const M_CCH As Short = 1 'ＣＣモード、電流レンジ「Ｈ」
    Public Const M_CCL As Short = 2 'ＣＣモード、電流レンジ「Ｌ」
    Public Const M_CRH As Short = 3 'ＣＲモード、電流レンジ「Ｈ」
    Public Const M_CRL As Short = 4 'ＣＲモード、電流レンジ「Ｌ」
    Public Const M_CVH As Short = 5 'ＣＶモード、電流レンジ「Ｈ」
    Public Const M_CVL As Short = 6 'ＣＶモード、電流レンジ「Ｌ」
    Public Const M_CPHL As Short = 7 'ＣＰモード、電流レンジ「Ｈ」、電圧レンジ「Ｌ」
    Public Const M_CPHH As Short = 8 'ＣＰモード、電流レンジ「Ｈ」、電圧レンジ「Ｈ」
    Public Const M_CPLL As Short = 9 'ＣＰモード、電流レンジ「Ｌ」、電圧レンジ「Ｌ」
    Public Const M_CPLH As Short = 10 'ＣＰモード、電流レンジ「Ｌ」、電圧レンジ「Ｈ」
    Public Const M_SHORT As Short = 11 'ショートモード

    'コントロールリファレンス設定値
    Public Const REF_IN As Short = 0 '内部電圧コントロール
    Public Const REF_EXT As Short = 1 '外部電圧コントロール

    '保存対象データ設定値
    Public Const OBJ_FREQ As Short = 1 'ＳＷ周波数
    Public Const OBJ_DUTY As Short = 2 'ＳＷデューティ
    Public Const OBJ_TAB As Short = 3 'ＳＷ時間ｔａ、ｔｂ
    Public Const OBJ_DELAY As Short = 4 'ディレイ時間
    Public Const OBJ_TRACK As Short = 5 'トラッキング設定

    'スイッチング方法設定値
    Public Const SW_FREQ As Short = 0 '周波数＆デューティ
    Public Const SW_TAB As Short = 1 '時間ｔａ＆ｔｂ

    'トラッキング方向設定値
    Public Const TRC_NO As Short = 0 'トラッキング無し
    Public Const TRC_PLUS As Short = 1 '「＋」トラッキング
    Public Const TRC_MINUS As Short = 2 '「−」トラッキング

    'トラッキングモード設定値
    Public Const TRC_PERCENT As Short = 0 '％トラッキングモード
    Public Const TRC_ABS As Short = 1 '絶対値トラッキングモード

    'ローカルロックアウト設定値
    Public Const LOCK_FREE As Short = 0 '解除可能
    Public Const LOCK_OUT As Short = 1 '解除不可
End Module
