Loading

How to Open Cash Drawer using VB.NET

Submitted by: 
Visitors have accessed this post 16729 times.


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.

Hi guys,

I need your help to know a way to select a particular cash drawer when two of them are connected in parallel via a splitter to a Star POS printer.

Any help will be highly appreciated!

Thanks,
MK

Add new comment

(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.

Filtered HTML

  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
To prevent automated spam submissions leave this field empty.