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

Module CWaveformGeneratorSDK
    '================================================================
    ' cgen_api.vb
    ' Headder file for C-WaveformGenerator
    '                                              CONTEC.Co.,Ltd.
    '================================================================
    '----------------------------------------
    'Function Prototype
    '----------------------------------------
    Declare Function GenOpenApplication Lib "cgen_api.dll" (ByVal DeviceName As String, ByRef AppId As Short, ByVal OpenMode As UShort) As Integer
    Declare Function GenCloseApplication Lib "cgen_api.dll" (ByVal AppId As Short, ByRef Status As UInteger) As Integer
    Declare Function GenStartOperation Lib "cgen_api.dll" (ByVal AppId As Short) As Integer
    Declare Function GenStopOperation Lib "cgen_api.dll" (ByVal AppId As Short) As Integer
    Declare Function GenGetApplicationStatus Lib "cgen_api.dll" (ByVal AppId As Short, ByRef Status As UInteger) As Integer
    Declare Function GenExportSettingFile Lib "cgen_api.dll" (ByVal AppId As Short, ByVal FilePath As String) As Integer
    Declare Function GenImportSettingFile Lib "cgen_api.dll" (ByVal AppId As Short, ByVal FilePath As String) As Integer
    Declare Function GenSaveDataFile Lib "cgen_api.dll" (ByVal AppId As Short, ByVal FilePath As String, ByVal Param1 As Short, ByVal Param2 As Short) As Integer
    Declare Function GenSetDeviceName Lib "cgen_api.dll" (ByVal AppId As Short, ByVal DeviceName As String) As Integer
    Declare Function GenGetDeviceName Lib "cgen_api.dll" (ByVal AppId As Short, ByVal DeviceName As StringBuilder) As Integer
    Declare Function GenSetDeviceSetting Lib "cgen_api.dll" (ByVal AppId As Short, ByVal AoChannels As UShort, ByVal Frequency As Single, ByVal FrequencyType As UShort, ByVal FrequencyUnit As UShort) As Integer
    Declare Function GenGetDeviceSetting Lib "cgen_api.dll" (ByVal AppId As Short, ByRef AoChannels As UShort, ByRef Frequency As Single, ByRef FrequencyType As UShort, ByRef FrequencyUnit As UShort) As Integer
    Declare Function GenSetOscillation Lib "cgen_api.dll" (ByVal AppId As Short, ByVal OscillationType As UShort, ByVal OscillationStart As UShort, ByVal OscillationStop As Single) As Integer
    Declare Function GenGetOscillation Lib "cgen_api.dll" (ByVal AppId As Short, ByRef OscillationType As UShort, ByRef OscillationStart As UShort, ByRef OscillationStop As Single) As Integer
    Declare Function GenSetChannelSetting Lib "cgen_api.dll" (ByVal AppId As Short, ByVal AoChannel As UShort, ByVal Amplitude As Single, ByVal Offset As Single, ByVal AmplitudeType As UShort, ByVal AmplitudeUnit As UShort, ByVal Duty As Single, ByVal Phase As Single) As Integer
    Declare Function GenGetChannelSetting Lib "cgen_api.dll" (ByVal AppId As Short, ByVal AoChannel As UShort, ByRef Amplitude As Single, ByRef Offset As Single, ByRef AmplitudeType As UShort, ByRef AmplitudeUnit As UShort, ByRef Duty As Single, ByRef Phase As Single) As Integer
    Declare Function GenSetWaveType Lib "cgen_api.dll" (ByVal AppId As Short, ByVal AoChannel As UShort, ByVal WaveType As UShort) As Integer
    Declare Function GenGetWaveType Lib "cgen_api.dll" (ByVal AppId As Short, ByVal AoChannel As UShort, ByRef WaveType As UShort) As Integer
    Declare Function GenSetArbitraryDataFile Lib "cgen_api.dll" (ByVal AppId As Short, ByVal AoChannel As UShort, ByVal FilePath As String) As Integer
    Declare Function GenGetArbitraryDataFile Lib "cgen_api.dll" (ByVal AppId As Short, ByVal AoChannel As UShort, ByVal FilePath As StringBuilder) As Integer
    Declare Function GenSetAoSweep Lib "cgen_api.dll" (ByVal AppId As Short, ByVal AoChannel As UShort, ByVal SweepType As UShort, ByVal SweepTime As UShort, ByVal SweepStart As Single, ByVal SweepStop As Single) As Integer
    Declare Function GenGetAoSweep Lib "cgen_api.dll" (ByVal AppId As Short, ByVal AoChannel As UShort, ByRef SweepType As UShort, ByRef SweepTime As UShort, ByRef SweepStart As Single, ByRef SweepStop As Single) As Integer
    Declare Function GenGetErrorString Lib "cgen_api.dll" (ByVal ErrorCode As Integer, ByVal ErrorString As StringBuilder) As Integer


    '================================================================
    ' Parameters
    '================================================================
    '----------------------------------------
    ' App size
    '----------------------------------------
    Public Const GEN_PARAM_WINDOW_OFF As Short = 0                        ' Minimize
    Public Const GEN_PARAM_WINDOW_NORMALF As Short = 1                    ' Normal
    Public Const GEN_PARAM_WINDOW_MAX As Short = 2                        ' Maximize
    '----------------------------------------
    ' Termination processing status
    '----------------------------------------
    Public Const GEN_STATUS_CLOSE_SUCCESS As Short = 0                    ' Normal completed
    Public Const GEN_STATUS_CLOSE_FAILURE As Short = 1                    ' C-WaveformGenerator completed error
    '----------------------------------------
    ' Operation status
    '----------------------------------------
    Public Const GEN_STATUS_BUSY As Short = 1                             ' Running trigger
    Public Const GEN_STATUS_START_TRG As Short = 2                        ' Start trigger
    '----------------------------------------
    ' Number of channels for data save
    '----------------------------------------
    Public Const GEN_PARAM_DATASAVE_SINGLE As Short = 0                   ' Data save for single channel
    Public Const GEN_PARAM_DATASAVE_MULTI As Short = 1                    ' Data save for multi channel
    '----------------------------------------
    ' Frequency type
    '----------------------------------------
    Public Const GEN_PARAM_FREQTYPE_FREQUENCY As Short = 0                ' Frequency
    Public Const GEN_PARAM_FREQTYPE_PERIOD As Short = 1                   ' Period
    '----------------------------------------
    ' Frequency unit
    '----------------------------------------
    Public Const GEN_PARAM_FREQUNIT_HZ_SEC As Short = 0                   ' Frequency [ Hz ], Period [ sec ]
    Public Const GEN_PARAM_FREQUNIT_KHZ_MSEC As Short = 1                 ' Frequency [ kHz ], Period [ msec ]
    '----------------------------------------
    ' Oscillation type
    '----------------------------------------
    Public Const GEN_PARAM_OSCILLATION_NONE As Short = 0                  ' None
    Public Const GEN_PARAM_OSCILLATION_AUTO_BURST As Short = 1            ' Auto burst
    Public Const GEN_PARAM_OSCILLATION_TRIGGER_BURST_RISE As Short = 2    ' Trigger burst(rising edge)
    Public Const GEN_PARAM_OSCILLATION_TRIGGER_BURST_FALL As Short = 3    ' Trigger burst(falling edge)
    '----------------------------------------
    ' Amplitude type
    '----------------------------------------
    Public Const GEN_PARAM_AMPTYPE_AMPLITUDE As Short = 0                 ' Amplitude
    Public Const GEN_PARAM_AMPTYPE_VPP As Short = 1                       ' Vp-p
    '----------------------------------------
    ' Amplitude unit
    '----------------------------------------
    Public Const GEN_PARAM_AMPUNIT_V_MA As Short = 0                      ' Voltage or Current
    Public Const GEN_PARAM_AMPUNIT_BINARY As Short = 1                    ' LSB
    '----------------------------------------
    ' Wave type
    '----------------------------------------
    Public Const GEN_PARAM_WAVE_SINE As Short = 0                         ' Sinewave
    Public Const GEN_PARAM_WAVE_CONSTANT As Short = 1                     ' Constant
    Public Const GEN_PARAM_WAVE_TRIANGULAR As Short = 2                   ' Triangular
    Public Const GEN_PARAM_WAVE_RAMP As Short = 3                         ' Ramp
    Public Const GEN_PARAM_WAVE_SQUARE As Short = 4                       ' Square
    Public Const GEN_PARAM_WAVE_NOISE As Short = 5                        ' Noise
    Public Const GEN_PARAM_WAVE_ARBITRARY As Short = 6                    ' Arbitrary
    '----------------------------------------
    ' Sweep type
    '----------------------------------------
    Public Const GEN_PARAM_SWEEP_NONE As Short = 0                        ' None
    Public Const GEN_PARAM_SWEEP_FREQUENCY As Short = 1                   ' Frequency sweep
    Public Const GEN_PARAM_SWEEP_AMPLITUDE As Short = 2                   ' Amplitude sweep
    Public Const GEN_PARAM_SWEEP_DC_OFFSET As Short = 3                   ' DC offset sweep
    Public Const GEN_PARAM_SWEEP_DUTY_RATIO As Short = 1                  ' Square Duty ratio sweep


    '================================================================
    ' Error codes
    '================================================================
    '----------------------------------------
    ' Initialize Error
    '----------------------------------------
    Public Const GEN_ERR_SUCCESS As Short = 0                         ' Normal completed
    Public Const GEN_ERR_INI_RESOURCE As Short = 1                    ' Failed in the acquisition of the resource
    Public Const GEN_ERR_INI_MEMORY As Short = 3                      ' Failed in the allocation of the memory
    Public Const GEN_ERR_MAKE_OBJECT As Short = 100                   ' Failed in the creation of the object
    Public Const GEN_ERR_OPEN_APPLICATION As Short = 102              ' Cannot use C-WaveformGenerator because other application is using
    Public Const GEN_ERR_CTRL_APPLICATION As Short = 103              ' Failed to application control
    '----------------------------------------
    ' Common Error
    '----------------------------------------
    Public Const GEN_ERR_APPLICATION_SIZE As Short = 10000            ' Unable to specify screen size
    Public Const GEN_ERR_STATUS As Short = 10001                      ' Unable to get status
    Public Const GEN_ERR_FILEPATH As Short = 10002                    ' The setting file path is invalid
    Public Const GEN_ERR_FILETYPE As Short = 10003                    ' The setting file type is invalid
    Public Const GEN_ERR_FILESAVE As Short = 10005                    ' Failed to save file
    Public Const GEN_ERR_STARTED As Short = 10006                     ' Cannot execute because the device is in operation
    Public Const GEN_ERR_DEVICENAME As Short = 10007                  ' A device name isn't stored in DeviceName
    Public Const GEN_ERR_DEVICE_START As Short = 10008                ' Operation start error occurred
    Public Const GEN_ERR_DEVICE_STOP As Short = 10009                 ' Operation stop error occurred
    Public Const GEN_ERR_INVALID_ID As Short = 10010                  ' Invalid AppID was specified
    Public Const GEN_ERR_BUFF_ADDRESS As Short = 10100                ' Invalid data buffer address
    '----------------------------------------
    ' Specific Error
    '----------------------------------------
    '--------------------
    ' Device Setting Error
    '--------------------
    Public Const GEN_ERR_DEVICENAME_ANALOGOUT As Short = 20001        ' The specified device does not have analog output function
    Public Const GEN_ERR_CHANNEL_NUM As Short = 20002                 ' Number of channels is outside the settable range
    Public Const GEN_ERR_FREQUENCY As Short = 20003                   ' Frequency is outside the settable range
    Public Const GEN_ERR_FREQUENCY_TYPE As Short = 20004              ' Frequency type is outside the settable range
    Public Const GEN_ERR_FREQUENCY_UNIT As Short = 20005              ' Frequency unit is outside the settable range
    Public Const GEN_ERR_OSCILLATION_TYPE As Short = 20006            ' Oscillation type is outside the settable range
    Public Const GEN_ERR_OSCILLATION_WAVENUM As Short = 20007         ' Number of oscillations is outside the settable range
    Public Const GEN_ERR_OSCILLATION_STOP_WAVENUM As Short = 20008    ' Number of stops or time is outside the settable range
    Public Const GEN_ERR_OSCILLATION_DATANUM As Short = 20009         ' Created data is outside the settable range
    Public Const GEN_ERR_DEVICESET As Short = 20010                   ' There are no devices that can be configured, the SDK will close
    Public Const GEN_ERR_BASICMODE As Short = 20011                   ' Switched to Basic mode. Settings may change automatically.
    '--------------------
    ' Channel Setting Error
    '--------------------
    Public Const GEN_ERR_CHANNEL_NO As Short = 22000                  ' Channel number is outside the settable range
    Public Const GEN_ERR_AMPLITUDE As Short = 22001                   ' Amplitude is outside the settable range
    Public Const GEN_ERR_OFFSET As Short = 22002                      ' Offset is outside the settable range
    Public Const GEN_ERR_AMPLITUDE_TYPE As Short = 22003              ' Amplitude type is outside the settable range
    Public Const GEN_ERR_AMPLITUDE_UNIT As Short = 22004              ' Amplitude unit is outside the settable range
    Public Const GEN_ERR_DUTY As Short = 22005                        ' Duty ratio is outside the settable range
    Public Const GEN_ERR_PHASE As Short = 22006                       ' Phase is outside the settable range
    Public Const GEN_ERR_WAVE_TYPE As Short = 22007                   ' Waveform type is outside the settable range
    Public Const GEN_ERR_SWEEP_TYPE As Short = 22008                  ' Sweep type is outside the settable range
    Public Const GEN_ERR_SWEEP_RATIO As Short = 22009                 ' Sweep time is outside the settable range
    Public Const GEN_ERR_SWEEP1 As Short = 22010                      ' The value before the sweep change is outside the settable range
    Public Const GEN_ERR_SWEEP2 As Short = 22011                      ' The value after the sweep change is outside the settable range
    Public Const GEN_ERR_WAVEDATA As Short = 20012                    ' Data file is not set when waveform type is arbitrary

    Public Const GEN_ERR_DEVICE As Short = 24001                      ' Device condition error occurred
    Public Const GEN_ERR_RELAY As Short = 24002                       ' Relay error occurred

End Module