Attribute VB_Name = "OMRAPI"
Option Explicit
'----------------------------------------------------------------------------
'   OMR API for SR-2200 Header
    
'   Copyright 2002- SEKONIC CORPORATION
    
 '  ---------------------------------------------------------------------------
'   version history
'   date        version     notes
'   2002.08.20  1.0.0       first release
'----------------------------------------------------------------------------*/

'/*----------
'system fixed number
'----------*/
Public Enum SR_STATUS
    SR_SUCCESS = 0
    SR_UNSUCCESSFUL
    SR_DISCONNECTED
    SR_WRONG_PARAMETER
    SR_MEMORY_ERROR
    SR_TIMEOUT
    SR_RECEIVE_NAK
    SR_WRONG_RESPONSE
'/*
'    '/*
'    Status Error Information
'      0xXXXXXXXX
'        ||||
'        ||++------- :Page
'        ||
'        |+------ 0x0    :Main
'        |        0x1    :Sensor unit
'        |        0x2    :(reserved)
'        |        0x3    :Barcode reader unit
'        |        0x4    :Printer unit
'        |        0x5    :Stacker unit
'        |        0xf    :other
'        |
'        +---- 0x0   :impossible to recovery(Hard error)
'              0x1   :Communication Error
'              0x2   :Cover open error
'              0x3   :Jam Error
'              0x4   :Warning
'    */

    SR_ERROR_STATUS_A1 = &H10000        '0x00010000
    SR_ERROR_STATUS_A2
    SR_ERROR_STATUS_A3
    SR_ERROR_STATUS_A4
    SR_ERROR_STATUS_A5
    SR_ERROR_STATUS_B1F = &H1020000     '0x01020000
    SR_ERROR_STATUS_B2F
    SR_ERROR_STATUS_B3F
    SR_ERROR_STATUS_B4F
    SR_ERROR_STATUS_B5F
    SR_ERROR_STATUS_B6F
    SR_ERROR_STATUS_B1B = &H2020000     '0x02020000
    SR_ERROR_STATUS_B2B
    SR_ERROR_STATUS_B3B
    SR_ERROR_STATUS_B4B
    SR_ERROR_STATUS_B5B
    SR_ERROR_STATUS_B6B
    SR_ERROR_STATUS_C1 = &H3030000      '0x03030000
    SR_ERROR_STATUS_C2
    SR_ERROR_STATUS_C3
    SR_ERROR_STATUS_C4
    SR_ERROR_STATUS_C5
    SR_ERROR_STATUS_C6
    SR_ERROR_STATUS_D1 = &H4040000      '0x04040000
    SR_ERROR_STATUS_D2
    SR_ERROR_STATUS_D3
    SR_ERROR_STATUS_D4
    SR_ERROR_STATUS_D5
    SR_ERROR_STATUS_E1 = &H5050000      '0x05050000
    SR_ERROR_STATUS_E2
    SR_ERROR_STATUS_E3
    SR_ERROR_STATUS_E4
    SR_ERROR_STATUS_E5
    SR_ERROR_STATUS_F1 = &H1F060000     '0x1f060000
    SR_ERROR_STATUS_F2
    SR_ERROR_STATUS_F3
    SR_ERROR_STATUS_F4
    SR_ERROR_STATUS_F5
    SR_ERROR_STATUS_F6
    SR_ERROR_STATUS_G1 = &H20070000     '0x20070000
    SR_ERROR_STATUS_G2 = &H25070001     '0x25070001
    SR_ERROR_STATUS_G3 = &H25070002     '0x25070002
    SR_ERROR_STATUS_H1 = &H30080000     '0x30080000
    SR_ERROR_STATUS_H2
    SR_ERROR_STATUS_H3
    SR_ERROR_STATUS_H4
    SR_ERROR_STATUS_I1 = &H35090000     '0x35090000
    SR_ERROR_STATUS_I2
    SR_ERROR_STATUS_I3
    SR_ERROR_STATUS_I4
    SR_ERROR_STATUS_P1 = &H42100000     '0x42100000
    SR_ERROR_STATUS_P2 = &H43100001     '0x43100001
    SR_ERROR_STATUS_P3 = &H44100002     '0x44100002
    SR_ERROR_STATUS_P4 = &H45100003     '0x45100003
    SR_ERROR_STATUS_Q1 = &H40110000     '0x40110000
    SR_ERROR_STATUS_Q2
    SR_ERROR_STATUS_Q3
    SR_ERROR_STATUS_Q4
    SR_ERROR_STATUS_R1 = &H40120000     '0x40120000
    SR_ERROR_STATUS_R2
    SR_ERROR_STATUS_R3
    SR_ERROR_STATUS_R4M = &H41120003    '0x41120003
    SR_ERROR_STATUS_R4F = &H41120004    '0x41120004
    SR_ERROR_STATUS_R4B = &H42120005    '0x42120005
    SR_ERROR_STATUS_S1F = &H41130000    '0x41130000
    SR_ERROR_STATUS_S2F
    SR_ERROR_STATUS_S1B = &H42130002    '0x42130002
    SR_ERROR_STATUS_S2B
    SR_ERROR_STATUS_T1 = &H40140000     '0x40140000
    SR_ERROR_STATUS_T2
    SR_ERROR_STATUS_T3
    SR_ERROR_STATUS_T4 = &H45140003     '0x45140003
    SR_ERROR_STATUS_T5
    SR_ERROR_STATUS_T6
    SR_ERROR_STATUS_T7
    SR_ERROR_TERM = &HFFFFFFFF          '0xffffffff

End Enum


'/*-Global Parameter---------------------*/
Public Const SR_INITIAL             As Long = &H80000000
Public Const SR_DISABLE             As Long = 0
Public Const SR_ENABLE              As Long = 1
Public Const SR_FUNCTION_FAIL       As Long = &HFFFFFFFF

'/*-iLanguageFlag------------------------*/
Public Enum SR_STRING
    SR_STRING_NORMAL = 0
    SR_STRING_ENGLISH
    SR_STRING_JAPANESE
End Enum

'/*-iPage -------------------------------*/
Public Enum SR_PAGE
    sr_page_front = 0
    SR_PAGE_BACK
End Enum

Public Const SR_PAGE_MAX   As Long = 2

'/*-Col Row------------------------------*/
Public Const SR_COL_MAX     As Long = 48


'/*-Reading Method(iControlType)---------*/
Public Enum SR_READ
    SR_READ_FRONT_EDGE = 1                        ' '/*  Front Edge control type */
    SR_READ_REAR_EDGE                             '/*  Rear Edge control type  */
    SR_READ_DIRECT                                '/*  Direct type */
    SR_READ_FACOM                                 ' '/*  FACOM type  */
    SR_READ_BETWEEN_MARK_NO_SPACE                 ' '/*  Between mark and mark without front edge space  */
    SR_READ_BETWEEN_MARK                          ' '/*  Between mark and mark   */
    SR_READ_INITIAL = SR_INITIAL                  '/*  Initialize control type */
End Enum


'/*-Feed Mode(iMode)---------------------*/
 Public Const SR_MODE_AUTO As Long = 0
 Public Const SR_MODE_MANUAL As Long = 1

'/*-Sheet thickness----------------------*/
Public Enum SR_THICKNESS
    SR_THICKNESS_AUTO_DETECT = 0           '/*  Auto            */
    SR_THICKNESS_80_MICRON                 '/*  0.08mm (55kg)   */
    SR_THICKNESS_110_MICRON                '/*  0.11mm (72kg)   */
    SR_THICKNESS_130_MICRON                '/*  0.13mm (90kg)   */
    SR_THICKNESS_160_MICRON                '/*  0.16mm (110kg)  */
    SR_THICKNESS_190_MICRON                '/*  0.19mm (135kg)  */
    SR_THICKNESS_INITIAL = SR_INITIAL      '/*  initailze       */
    
    SR_THICKNESS_55_KG = 1                 '/*  0.08mm (55kg)   */
    SR_THICKNESS_72_KG                     '/*  0.11mm (72kg)   */
    SR_THICKNESS_90_KG                     '/*  0.13mm (90kg)   */
    SR_THICKNESS_110_KG                    '/*  0.16mm (110kg)  */
    SR_THICKNESS_135_KG                    '/*  0.19mm (135kg)  */
End Enum

'/*-WarningError-------------------------*/
Public Const SR_WARN_MARK_SKEW       As Long = &H200000
Public Const SR_WARN_LEFT_SKEW       As Long = &H100000
Public Const SR_WARN_DF_ERROR        As Long = &H80000
Public Const SR_WARN_TM_ERROR        As Long = &H40000
Public Const SR_WARN_HOPPER_EMPTY    As Long = &H20000
Public Const SR_WARN_AUTO_REJECT     As Long = &H10000

Public Const SR_WARN_NONE            As Long = &H0
Public Const SR_WARN_ALL             As Long = &H3F0000
Public Const SR_WARN_INITIAL         As Long = &H10000000


'/*-Buzzer Volume------------------------*/
Public Const SR_BUZZER_DISABLE      As Long = 0                  '  '/* Buzzer Off           */
Public Const SR_BUZZER_MIN           As Long = 1            '       '/* Buzzer Volume Min.   */
Public Const SR_BUZZER_MAX           As Long = 5             '      '/* Buzzer Volume Max.   */
Public Const SR_BUZZER_INITIAL = SR_INITIAL

'/*-Buzzer Tone--------------------------*/
Public Enum SR_BUZZER
    SR_BUZZER_TONE_A = 1
    SR_BUZZER_TONE_B
    SR_BUZZER_TONE_C
End Enum


'/*-ID-----------------------------------*/
Public Const SR_ID_LENGTH_MAX           As Long = 20
        

'/*-Hopper(iDirection)-------------------*/
Public Const SR_HOPPER_DOWN              As Long = 0
Public Const SR_HOPPER_UP               As Long = 1


'/*-Eject (iDirection)-------------------*/
Public Enum SR_EJECT
    SR_EJECT_MAIN = 1
    SR_EJECT_SELECT
    SR_EJECT_MAIN_ON_NEXT
    SR_EJECT_SELECT_ON_NEXT
End Enum


'/*-Mark Type----------------------------*/
Public Const SR_MARK_TYPE_16         As Long = 16
Public Const SR_MARK_TYPE_256        As Long = 256


'/*-Sensor-------------------------------*/
Public Const SR_SENSOR_OUTPS        As Long = &H20000000
Public Const SR_SENSOR_RDPS         As Long = &H10000000
Public Const SR_SENSOR_INPS         As Long = &H8000000
Public Const SR_SENSOR_PS0          As Long = &H4000000
Public Const SR_SENSOR_UPPS         As Long = &H2000000
Public Const SR_SENSOR_DWPS         As Long = &H1000000
Public Const SR_SENSOR_SKS          As Long = &H100000
Public Const SR_SENSOR_MAIN_CVR     As Long = &H10000
Public Const SR_SENSOR_SPS          As Long = &H800
Public Const SR_SENSOR_MPS          As Long = &H400
Public Const SR_SENSOR_P2PS         As Long = &H200
Public Const SR_SENSOR_STPS         As Long = &H100
Public Const SR_SENSOR_STK_CVR2     As Long = &H2
Public Const SR_SENSOR_STK_CVR1     As Long = &H1


'/*-Device-------------------------------*/
Public Const SR_DEVICE_UNIT_BACK    As Long = &H10000
Public Const SR_DEVICE_UNIT_BARCODE As Long = &HF00000
Public Const SR_DEVICE_UNIT_BARCODE_V  As Long = &H100000
Public Const SR_DEVICE_UNIT_BARCODE_H  As Long = &H200000
Public Const SR_DEVICE_UNIT_PRINTER As Long = &H1000000
Public Const SR_DEVICE_UNIT_STACKER As Long = &H10000000
Public Const SR_DEVICE_SENSOR_TYPE_MASK  As Long = &H10
Public Const SR_DEVICE_SENSOR_PITCH_MASK As Long = &HF


'/*-Unit Name----------------------------*/
Public Enum SR_UNIT
    SR_UNIT_MAIN = 0                                '/*  Main                */
    SR_UNIT_FRONT                                   '/*  Front Sensor unit   */
    SR_UNIT_BACK                                    '/*  Back Sendor unit    */
    SR_UNIT_BARCODE                                 '/*  Barcode reader unit */
    SR_UNIT_PRINTER                                 '/*  Printer unit        */
    SR_UNIT_STACKER                                 '/*  Stacker unit        */
End Enum


'/*-Print buffer-------------------------*/
Public Enum SR_PRINT
    SR_PRINT_BUFFER_NULL = 0
    SR_PRINT_BUFFER_1
    SR_PRINT_BUFFER_2
    SR_PRINT_BUFFER_3
End Enum


'/*-Print position-----------------------*/
Public Const SR_PRINT_INITIAL       As Long = &HFFFF0000
Public Const SR_PRINT_MILI          As Long = &HFF00000
Public Const SR_PRINT_INCH          As Long = &HFFF0000
Public Const SR_PRINT_POSITION      As Long = &HFFFF

Public Const SR_PRINT_ANGLE_0      As Long = 1
Public Const SR_PRINT_ANGLE_180    As Long = 2


'/*-Field direction----------------------*/
Public Enum SR_DIR
    SR_DIR_LEFT_DOWN_VERTICAL = 0
    SR_DIR_RIGHT_DOWN_VERTICAL
    SR_DIR_LEFT_UP_VERTICAL
    SR_DIR_RIGHT_UP_VERTICAL
    SR_DIR_LEFT_DOWN_HORIZONTAL
    SR_DIR_RIGHT_DOWN_HORIZONTAL
    SR_DIR_LEFT_UP_HORIZONTAL
    SR_DIR_RIGHT_UP_HORIZONTAL
End Enum




'/*-----------------------------------------------------------------------------
'Form and Mark Field structures
'-----------------------------------------------------------------------------*/

'typedef struct tagOMR_MARK_INFO
'{
' long type;
' long rows;
' long columns;
'}OMR_MARK_INFO, *POMR_MARK_INFO;

Public Type OMR_MARK
    type        As Long
    rows        As Long
    columns     As Long
End Type

'------------------------------------------------------------------------------
'OMR_GetMarks(int iPage, OMR_MARK_INFO *pMarkInfo, CHAR *pMarks);
Public Declare Function OMR_GetMarks Lib "OMRAPI.dll" (ByVal iPage As Long, ByRef MarkInfo As OMR_MARK, ByRef MarkArray As Byte) As Long



'/*-----------------------------------------------------------------------------
'OMR API functions
'-----------------------------------------------------------------------------*/


'/*-USB Port Functions-------------------*/
'OMR_STATUS  OMR_API OMR_OpenDeviceUSB();
Public Declare Function OMR_OpenDeviceUSB Lib "OMRAPI.dll" () As Long
'/*-other--------------------------------*/
'OMR_STATUS  OMR_API OMR_CloseDevice(void);
Public Declare Function OMR_CloseDevice Lib "OMRAPI.dll" () As Long

'OMR_STATUS  OMR_API OMR_GetLastError(void);
Public Declare Function OMR_GetLastError Lib "OMRAPI.dll" () As Long

'const CHAR  OMR_API *OMR_FormatMessage(OMR_STATUS status  int iLanguageFlag);
Public Declare Function OMR_FormatMessage Lib "OMRAPI.dll" (ByVal status As Long, ByVal iLanguage As Long) As Long

'const CHAR  OMR_API *OMR_GetST(int iPage);
Public Declare Function OMR_GetST Lib "OMRAPI.dll" (ByVal iPage As Long) As Long

'/*-Commands-----------------------------*/
    '/*-Settings-----------------------------*/
'BOOL        OMR_API OMR_SetNumberOfColumnsToRead(int iColumns);
Public Declare Function OMR_SetNumberOfColumnsToRead Lib "OMRAPI.dll" (ByVal iColumns As Long) As Long

'int         OMR_API OMR_GetNumberOfColumnsToRead(void);
Public Declare Function OMR_GetNumberOfColumnsToRead Lib "OMRAPI.dll" () As Long


'BOOL        OMR_API OMR_SetReadingMethod(int iControlType  int iMultipleValue);
Public Declare Function OMR_SetReadingMethod Lib "OMRAPI.dll" (ByVal iControlType As Long, ByVal iMultipleValue As Long) As Long

'BOOL        OMR_API OMR_GetReadingMethod(int *iControlType  int *iMultipleValue);
Public Declare Function OMR_GetReadingMethod Lib "OMRAPI.dll" (ByRef iControlType As Long, ByRef iMultipleValue As Long) As Long

'BOOL        OMR_API OMR_SetBackSensorUnit(int iDirective);
Public Declare Function OMR_SetBackSensorUnit Lib "OMRAPI.dll" (ByVal iDirective As Long) As Long

'int         OMR_API OMR_GetBackSensorUnit(void);
Public Declare Function OMR_GetBackSensorUnit Lib "OMRAPI.dll" () As Long

'BOOL        OMR_API OMR_SetSheetFeedMode(int iMode  int iInsertTime);
Public Declare Function OMR_SetSheetFeedMode Lib "OMRAPI.dll" (ByVal iMode As Long, ByVal iInsertTime As Long) As Long
'Public Declare Function OMR_SetSheetFeedMode Lib "OMRAPI.dll" (ByRef iMode As Long, ByRef iInsertTime As Long) As Long

'BOOL        OMR_API OMR_GetSheetFeedMode(int *iMode  int *iInsertTime);
Public Declare Function OMR_GetSheetFeedMode Lib "OMRAPI.dll" (ByRef iMode As Long, ByRef iInsertTime As Long) As Long
'Public Declare Function OMR_GetSheetFeedMode Lib "OMRAPI.dll" (ByRef iMode As Integer, ByRef iInsertTime As Integer) As Integer

'BOOL        OMR_API OMR_SetSheetThickness(int iThickness);
Public Declare Function OMR_SetSheetThickness Lib "OMRAPI.dll" (ByVal iThickness As Long) As Long

'int         OMR_API OMR_GetSheetThickness(void);
Public Declare Function OMR_GetSheetThickness Lib "OMRAPI.dll" () As Long

'BOOL        OMR_API OMR_SetWarningError(DWORD dwConfigData, int iSkewCol, int iSkewLevel);
Public Declare Function OMR_SetWarningError Lib "OMRAPI.dll" (ByVal dwConfigData As Long, ByVal iSkewCol As Long, ByVal iSkewLevel As Long) As Long

'BOOL        OMR_API OMR_GetWarningError(DWORD *dwConfigData  int *iSkewCol, int *iSkewLevel);
Public Declare Function OMR_GetWarningError Lib "OMRAPI.dll" (ByRef dwConfigData As Long, ByRef iSkewCol As Long, ByRef iSkewLevel As Long) As Long

'BOOL        OMR_API OMR_SetPanelConfig(int iPanelEnable);
Public Declare Function OMR_SetPanelConfig Lib "OMRAPI.dll" (ByVal iPanelEnable As Long) As Long

'int         OMR_API OMR_GetPanelConfig(void);
Public Declare Function OMR_GetPanelConfig Lib "OMRAPI.dll" () As Long

'BOOL        OMR_API OMR_SetBuzzerConfig(int iVolume  int iTone);
Public Declare Function OMR_SetBuzzerConfig Lib "OMRAPI.dll" (ByVal iVolume As Long, ByVal iTone As Long) As Long

'BOOL        OMR_API OMR_GetBuzzerConfig(int *iVolume  int *iTone);
Public Declare Function OMR_GetBuzzerConfig Lib "OMRAPI.dll" (ByRef iVolume As Long, ByRef iTone As Long) As Long

'BOOL        OMR_API OMR_SetID(CHAR *pID);
Public Declare Function OMR_SetID Lib "OMRAPI.dll" (ByRef pID As Byte) As Long

'BOOL        OMR_API OMR_GetID(CHAR *pID);
Public Declare Function OMR_GetID Lib "OMRAPI.dll" (ByRef pID As Byte) As Long

'BOOL        OMR_API OMR_SetPrintString(int  CHAR *);
'BOOL        OMR_API OMR_GetPrintString(int  CHAR *);
'BOOL        OMR_API OMR_SetPrintPosition(DWORD);
'DWORD       OMR_API OMR_GetPrintPosition(void);
'BOOL        OMR_API OMR_SetPrintOrder(int  int  int);
'BOOL        OMR_API OMR_GetPrintOrder(int*  int*  int*);
'BOOL        OMR_API OMR_SetPrintAngle(DWORD);
'DWORD       OMR_API OMR_GetPrintAngle(void);
'//BOOL      OMR_API OMR_SetPrintFont(CHAR *pFont);
'//BOOL      OMR_API OMR_GetPrintFont(CHAR *pFont);
'//BOOL      OMR_API OMR_SetBarCodeConfig(CHAR *pCommand);
'*/

    '/*-movement request---------------------*/
'BOOL        OMR_API OMR_Reset(void);
Public Declare Function OMR_Reset Lib "OMRAPI.dll" () As Long

'BOOL        OMR_API OMR_FeedSheet(void);
Public Declare Function OMR_FeedSheet Lib "OMRAPI.dll" () As Long

'BOOL        OMR_API OMR_MoveHopper(int iDirection);
Public Declare Function OMR_MoveHopper Lib "OMRAPI.dll" (ByVal iDirection As Long) As Long

'BOOL        OMR_API OMR_EjectSheet(int iDirection);
Public Declare Function OMR_EjectSheet Lib "OMRAPI.dll" (ByVal iDirection As Long) As Long

'BOOL        OMR_API OMR_InitialSetting(void);
Public Declare Function OMR_InitialSetting Lib "OMRAPI.dll" () As Long

'OMR_STATUS  OMR_API OMR_CancelError(void);
Public Declare Function OMR_CancelError Lib "OMRAPI.dll" () As Long

    '/*-deta request-------------------------*/
'BOOL        OMR_API OMR_GetMarks(int iPage  OMR_MARK *stMark);
'Public Declare Function OMR_GetMarks Lib "OMRAPI.dll" (ByVal iPage As Long, ByRef stMark As OMR_MARK) As Long

'OMR_STATUS  OMR_API OMR_GetStatus(void);
Public Declare Function OMR_GetStatus Lib "OMRAPI.dll" () As Long

'DWORD       OMR_API OMR_GetSensorInfo(void);
Public Declare Function OMR_GetSensorInfo Lib "OMRAPI.dll" () As Long

'DWORD       OMR_API OMR_GetDeviceInfo(void);
Public Declare Function OMR_GetDeviceInfo Lib "OMRAPI.dll" () As Long

'BOOL        OMR_API OMR_GetMachineName(CHAR* pResult);
Public Declare Function OMR_GetMachineName Lib "OMRAPI.dll" (ByRef pResult As Byte) As Long

'BOOL        OMR_API OMR_GetVersion(int iTarget  CHAR* pResult);
Public Declare Function OMR_GetVersion Lib "OMRAPI.dll" (ByVal iTarget As Long, ByRef pResult As Byte) As Long


'#ifdef __cplusplus
'}
'#End If

'#End If '/*__OMR_API_H_*/


Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long

Public Function OMR_FormatMessageVb(status As Long, Optional iLanguage As Long = SR_STRING_NORMAL)
    Dim strMessage  As String * 256
    
    If lstrcpy(strMessage, OMR_FormatMessage(status, iLanguage)) = 0 Then
        MsgBox "lstrcpy function is fail.", vbCritical
        Exit Function
    End If
    OMR_FormatMessageVb = Left(strMessage, InStr(strMessage, Chr(0)) - 1)
End Function

