54
Appendix B. Sample Visual Basic Cash Drawer Code for Windows
NOTE:
Requires installation of System Driver. Refer to the System Driver Installation
section for instructions.
‘ Use inside a form’s code section and use Option Explicit
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
(ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, _
ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As IntPtr, _
ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, _
ByVal hTemplateFile As IntPtr) As Integer
Private Declare Function DeviceIoControl Lib "kernel32" _
(ByVal hDevice As IntPtr, ByVal dwIoControlCode As Integer, _
ByRef lpInBuffer As Byte, ByVal nInBufferSize As Integer, _
ByRef lpOutBuffer As Byte, ByVal nOutBufferSize As Integer, _
ByRef lpBytesReturned As Long, ByVal lpOverlapped As Integer) As Integer
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Integer
‘ A Form with a single button and one static text box
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim DeviceHandle As Integer = 0, iBytesRtn As Integer
Dim iRet As Integer, iDrawer As Integer, iStatus As Integer
Const GENERIC_READ As Long = &H80000000, GENERIC_WRITE As Long = &H40000000
Const FILE_SHARE_READ As Long = &H1, FILE_SHARE_WRITE As Long = &H2
Const OPEN_EXISTING As Long = &H3, FILE_ATTRIBUTE_NORMAL As Long = &H80
Const INVALID_HANDLE_VALUE As Long = &HFFFFFFFF
Const ADV_OPEN_CTL_CODE As Long = &HDAF52400
Const ADV_STATUS_CTL_CODE As Long = &HDAF52480
Err.Clear()
DeviceHandle = CreateFile("\\.\ADVSYS", GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or
FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
0)
If DeviceHandle = INVALID_HANDLE_VALUE Then
'Failed to Open Cash Drawer Driver
Debug.Print("Error opening ADVSYS.sys. Error = " & Err.LastDllError)
Else
' Open Drawer #1
iDrawer = 1
iRet = DeviceIoControl(DeviceHandle, ADV_OPEN_CTL_CODE, iDrawer, 4, 0, 0, iBytesRtn, 0)
If (iRet = 0 Or iBytesRtn <> 1) Then
Debug.Print("Error writing to Cash Drawer Driver. Error" & Err.LastDllError)
End If
' Open Drawer #2
iDrawer = 2
iRet = DeviceIoControl(DeviceHandle, ADV_OPEN_CTL_CODE, iDrawer, 4, 0, 0, iBytesRtn, 0)
If (iRet = 0 Or iBytesRtn <> 1) Then
Debug.Print("Error writing to Cash Drawer Driver. Error" & Err.LastDllError)
End If
Содержание POS-400 Expander II
Страница 14: ...7 Dimensions Unit mm ...
Страница 49: ...42 8 When installation is complete click Finish ...
Страница 51: ...44 MSR Driver Installation optional 1 First plug in the MSR module 2 Reboot system to complete installation ...
Страница 53: ...46 8 Click Yes to restart the system required ...