Appendix B. Sample Visual Basic Cash Drawer Code For Windows - 4pos POS-400 Expander II User Manual

All-in-one point of sales system
Table of Contents

Advertisement

Appendix B. Sample Visual Basic Cash Drawer Code for Windows

NOTE:
' 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
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
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
End If
Requires installation of System Driver. Refer to the System Driver Installation
section for instructions.
FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
0)
Debug.Print("Error writing to Cash Drawer Driver. Error" & Err.LastDllError)
Debug.Print("Error writing to Cash Drawer Driver. Error" & Err.LastDllError)
54

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents