How to Open Cash Drawer using VB.NET

I just want to share with you the code that I have found on the internet on how to open a Cash Drawer using VB.NET. I am in no way claim this code as my own work. I want to share this with you because there’s a lot of question on the internet on how to open a Cash Drawer on VB.NET. The code will simply open the cash drawer using either the LPT port or COM port. Use the following code and test it if it will work on the brand of your cash drawer.
  1.     Private Sub OpenCashDrawer()
  2.         Dim intFileNo As Integer = FreeFile()
  3.  
  4.         'Use this code if you are using LPT Port
  5.         FileOpen(1, "c:\escapes.txt", OpenMode.Output)
  6.         PrintLine(1, Chr(27) & "p" & Chr(0) & Chr(25) & Chr(250))
  7.         FileClose(1)
  8.  
  9.         Shell("print /d:lpt1 c:\escapes.txt", vbNormalFocus)
  10.  
  11.         'Use this code if you are using COM Port
  12.         FileOpen(1, AppDomain.CurrentDomain.BaseDirectory & "open.txt", OpenMode.Output)
  13.         PrintLine(1, Chr(27) & Chr(112) & Chr(0) & Chr(25) & Chr(250))
  14.         FileClose(1)
  15.  
  16.         Shell("print /d:com1 open.txt", AppWinStyle.Hide)
  17.     End Sub

Comments

Hi, Thanks for sharing What would i have to change in this code for vb6 Thanks a lot

tnx for the share. . . this is just what i search for . . . thank you.

What do I have to do to this code to open a cash drawer if the POS printer is connected trough a USB port? 'Use this code if you are using COM Port FileOpen(1, AppDomain.CurrentDomain.BaseDirectory & "open.txt", OpenMode.Output) PrintLine(1, Chr(27) & Chr(112) & Chr(0) & Chr(25) & Chr(250)) FileClose(1) Shell("print /d:com1 open.txt", AppWinStyle.Hide)

hi can u post what inside in the escapes.txt and open.txt files?

thank you very much! ur post help me a lot :)

Hi I can't find what inside escapes.txt and open.txt files. Can u post it please? Thanks.

Can any one please help me to know what is Open.txt or escape.txt
what written inside them. where it should be located.what is the purpose of those.
i found above code on lot of places but no body ever explain about opent.txt and escape.txt.
can any body help.

Add new comment