Jump to content
Sign in to follow this  
Kiai

Script to open a cash drawer attached to a USB printer

Recommended Posts

Kiai

I am trying to write an AutoIT script to send commands to a receipt printer (Epson TMU220 attached via USB, virtual port ESDPRT001) to open an attached cash drawer. The drawer opens when printing a test page, but won't open with a clunky POS software program we use. I found the dialog below about the codes necessary, but don't know how to send codes to the receipt printer (not the default printer). I've never tried to send data to a printer using AutoIT -- any help would be appreciated.

On this printer and the cash drawer:

Open Drawer Code for an Epson TM-U220, Posted 03-10-2005, 03:12 PM #1

Hello,

Hey I just installed a new cash drawer with receipt printer but the drawer won't open. Its an MMF drawer by the way, but from what I understand that doesn't matter really. I have tried using the 07 code that was defaulted and also some ASCII code the manuafacturer gave me but nothing works. I also found a code on the internet that should work but it does not. (25,112,0,25,250) Its supposed to be for the model TM-U200 but its the same model as mine basically. Anyone know what the right code is for this printer?

Thanks a lot. I will keep looking in the web to see if I find something else.

Felix

Posted 03-11-2005, 11:12 AM #2

Felix,

It looks like you found the same information we did. The model TM-U220 is pretty much the same model TM-U200 just with some other options. The code to open the cash drawer should be the same. I did notice that the code you have has a zero on it though. This is sometimes a problem depending on the Windows operating system and how it interprets the code numbers. Basically its using decimal numbers to represent the code and the number zero is not recognized as a decimal number. You have to use the ASCII code for the zero which is "48" so your code should actually be

27,112,48,25,250

Try this code and let me know how it goes.

Thanks for your post.

Posted 03-15-2005, 06:51 PM #3

Its amazing what one little number can do. I changed the zero to a 48 and "cling" the cash drawer pops open now.

Thanks for the help. I also saw the file you posted with all the codes. I guess it makes life easy for you guys to have that available. I'm sure others will benefit from it.

Thanks again.

Felix

Share this post


Link to post
Share on other sites
jchd

These "codes" are one of the (Epson classical) so-called ESC/POS sequences: ESC p 0 EM ú. I believe you can very simply write this string to the printer.

The string is:

Local Const $sOpenCashDrawer = Chr(27) & 'p0' & Chr(25) & ChrW(250) ; the last Chr_W_ is not a typo and 'p0' is lowercase p and digit 0

Edit: I forgot to mention what you should do to print text strings to a local printer, if you don't already know how to. (The english name of options/tabs may vary a little as I only guess those names -- I run a french XP.)

You need to have files/printers sharing support enabled, even if you only have one PC and no network.

Open the Printer/Fax Control Panel applet.

Select you receipt printer by right-click and select Sharing

Click Share this printer and give it a (short) name e.g. RECEIPT. Click Apply.

Verify that Start printing immediately is checked

Now you can send text to it, assuming that the computer name is POS-PC:

FileWrite("test.txt", $sOpenCashDrawer)
If FileCopy("test.txt", "\\POS-PC\RECEIPT", 1) Then ConsoleWrite("ESC-P string sent" & @LF)

BTW, it's not hard to locate a copy of the ESC/POS generic commands, even without registering with the Epson lengthy procedure. That document isn't the definitive tech guide but will guide you with the drawer opening.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Kiai

Thanks very much. I won't be able to try this until the store has some down-time. I'll let you know how it works this weekend.

Share this post


Link to post
Share on other sites
Kiai

Thanks very much. I won't be able to try this until the store has some down-time. I'll let you know how it works this weekend.

That was amazingly easy and quick. Thanks! Just replaced the printer and computer name and it works beautifully.

I'm tipping my hat to your intelligence. Thanks again.

Share this post


Link to post
Share on other sites
jchd

That's by chance :idea:


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Asolis

Hello, I have the following code to open a Cash Drawer via COM1, but I do not know how to do that trough a USB 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)

Can someone tell me what changes do I need to do to the above code in order to send the data to the USB port, I tried changing the com1 to USB on this line but it does not work:

Shell("print /d:USB1 open.txt", AppWinStyle.Hide)

I would appreciate any assistance.

Thank you.

Share this post


Link to post
Share on other sites
ConsultingJoe

OK, got it. Checked here first to see if anyone got this working. I have a Star TSP100 but will have to get this to work with some epsons too.

Here is what got it for me: http://www.starmicronics.com/absolutefm/absolutefm/attachments/58/1205a_StarMicronics_CashDrawer_OpenFromCommandPrompt.pdf

Basiclly have the receipt printer connected to your drawer over the phone line cable and setup a generic printer on com 3 and set that drawer in the printer to com 3 and have your usb printer com emulator on and on automatic. then use this command in CMD:

echo ^G > COM3

Let me know if you need help. Is anyone still trying to get this?


[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Share this post


Link to post
Share on other sites
dmaulik142

That was amazingly easy and quick. Thanks! Just replaced the printer and computer name and it works beautifully.

I'm tipping my hat to your intelligence. Thanks again.

Hello Sir

Can you help me by sending code for opening till drawer cash in PHP. Please upload the code file here.

Share this post


Link to post
Share on other sites
Jfish

@dmaulik142 welcome to the forum.  The mods will likely tell you that it is frowned upon to necro-post (open up an old thread) and that this is an AutoIt forum so PHP questions are better suited for other spots on the net.


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.