Appendix B. Sample Vb.net Cash Drawer Code For Windows - Advantech EP-55XX-AR10 User Manual

Ep-55xx series efficiency all-in-one point of sales system
Table of Contents

Advertisement

Appendix B. Sample VB.NET Cash Drawer Code for Windows

NOTE:
Private Declare Function
dwDesiredAccess
As
Integer,
dwCreationDisposition
As
Private Declare Function
Integer,
ByRef
lpInBuffer
As
Integer,
ByRef
lpBytesReturned
Private Declare Function
Public Shared Function CTL_CODE(ByVal
ByVal
Access
As
Integer)
Return
(DeviceType << 16)
End Function
Dim
DeviceHandle
As Integer
Const
GENERIC_READ
As Long
Const
FILE_SHARE_READ
Const
OPEN_EXISTING
Const
INVALID_HANDLE_VALUE
Const
ADVPORT_TYPE
As Long
Dim
ADV_OPEN_CTL_CODE
Dim
ADV_STATUS_CTL_CODE
Private Sub Form1_Load(ByVal
DeviceHandle = CreateFile("\\.\ADVSYS", GENERIC_READ
0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
If
DeviceHandle = INVALID_HANDLE_VALUE
'Failed to Open Cash Drawer Driver
Timer1.Enabled =
MsgBox("Error opening ADVSYS.sys. Error = "
End If
End Sub
Private Sub Button1_Click(ByVal
Dim
iBytesRtn
As Integer
Dim
iRet
As
Integer, iDrawer
' Open Drawer #1
iDrawer = &H1
iRet = DeviceIoControl(DeviceHandle, ADV_OPEN_CTL_CODE, iDrawer, 4, 0, 0, iBytesRtn, 0)
If
(iRet = 0
Or
MsgBox("Error opening ADVSYS.sys. Error = "
End If
End Sub
Private Sub Button2_Click(ByVal
Dim
iBytesRtn
As Integer
Dim
iRet
As
Integer, iDrawer
' Open Drawer #2
iDrawer = &H2
iRet = DeviceIoControl(DeviceHandle, ADV_OPEN_CTL_CODE, iDrawer, 4, 0, 0, iBytesRtn, 0)
Requires installation of System Driver. Refer to the System Driver Installation
section for instructions.
CreateFile
Lib
"kernel32"
ByVal
dwShareMode
As
Integer,
ByVal
dwFlagsAndAttributes
DeviceIoControl
Lib
As
Byte,
ByVal
nInBufferSize
As
Long,
ByVal
CloseHandle
Lib
"kernel32"
DeviceType
As Integer
Or
(Access << 14)
= &H80000000, GENERIC_WRITE
As Long
= &H1, FILE_SHARE_WRITE
As Long
= &H3, FILE_ATTRIBUTE_NORMAL
As Long
= &HFFFFFFFF
= 40000, METHOD_BUFFERED
As Long
= CTL_CODE(ADVPORT_TYPE, &H900, METHOD_BUFFERED, FILE_ANY_ACCESS)
As Long
= CTL_CODE(ADVPORT_TYPE, &H901, METHOD_BUFFERED, FILE_ANY_ACCESS)
sender
As
System.Object,
Then
False
sender
As
System.Object,
As Integer
iBytesRtn <> 1)
Then
sender
As
System.Object,
As Integer
Alias
"CreateFileA"
Integer,
ByVal
lpSecurityAttributes
As
Integer,
"kernel32"
(ByVal
hDevice
As
Integer,
ByRef
lpOverlapped
As
Integer)
(ByVal
hObject
As
As
Integer,
ByVal
func
Or
(func << 2)
Or
Method
As Long
= &H40000000
As Long
= &H2
As Long
= &H80
As Long
= 0, FILE_ANY_ACCESS
ByVal
e
As
System.EventArgs)
Or
GENERIC_WRITE, FILE_SHARE_READ
& Err.LastDllError)
ByVal
e
As
System.EventArgs)
& Err.LastDllError)
ByVal
e
As
System.EventArgs)
(ByVal
lpFileName
As
String,
As
IntPtr,
ByVal
ByVal
hTemplateFile
As
IntPtr)
As
IntPtr,
ByVal
dwIoControlCode
lpOutBuffer
As
Byte,
ByVal
As Integer
Long)
As Integer
As
Integer,
ByVal
Method
As Long
= 0
Handles
MyBase.Load
Or
Handles
Handles
ByVal
As Integer
As
nOutBufferSize
As
Integer,
FILE_SHARE_WRITE,
Button1.Click
Button2.Click
68

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ep-55xx-ar30Ep-55xx-ar20

Table of Contents