cash drawer code, not working.

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Locked
User avatar
mr cubefan
Posts: 33
Joined: Thu Mar 10, 2011 6:23 pm

cash drawer code, not working.

Post by mr cubefan »

Hi everyone, im trying to use the following code in the neobook "vbscript"function editor, but is not working, is there a way to adapt the code to work properly in neobook?, btw the code is for kicking the cash drawer connected to a pos printer.
P.D.: the code works on excel.

Code: Select all

Sub Botón1_Haga_clic_en()
 Open "\\ASUSTEK-PC\EPSON TM-T20II Receipt" For Output As #1
    Print #1, Chr(27) & Chr(112) & Chr(0) & Chr(25) & Chr(250)
 Close #1
End Sub
Thanks in advance!
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: cash drawer code, not working.

Post by Gaev »

mr cubefan:

Looks like you have "defined' a subroutine but there is no place where you "invoke" it ... try this first ...

Code: Select all

Sub Botón1_Haga_clic_en()
 Open "\\ASUSTEK-PC\EPSON TM-T20II Receipt" For Output As #1
    Print #1, Chr(27) & Chr(112) & Chr(0) & Chr(25) & Chr(250)
 Close #1
End Sub
Botón1_Haga_clic_en()
If this still does not work, it might be due to some security related issue.
is there a way to adapt the code to work properly in neobook?
P.D.: the code works on excel.
You might try and Run the commands in a VBScript file e.g. ...

Code: Select all

Run "![PubDir]myTest.vbs" "" "Normal" "" ""
... where myTest.vbs is a text file with the vbs (script) commands.
btw the code is for kicking the cash drawer connected to a pos printer.
I don't have the hardware to verify if this will work, so I just did a test with myTest.vbs (in the [PubDir] like so ...

Code: Select all

WScript.Echo "Hello from my test vbs file"
WScript.Echo "Ended my test vbs file"
... once it is works, try this code instead ...

Code: Select all

WScript.Echo "Hello from my test vbs file"
Open "\\ASUSTEK-PC\EPSON TM-T20II Receipt" For Output As #1
Print #1, Chr(27) & Chr(112) & Chr(0) & Chr(25) & Chr(250)
Close #1
WScript.Echo "Ended my test vbs file"
Once it works, you might consider fine tuning the parameters of the Run command as desirable.
User avatar
mr cubefan
Posts: 33
Joined: Thu Mar 10, 2011 6:23 pm

Re: cash drawer code, not working.

Post by mr cubefan »

Hi Gaev!, thanks for your reply, but none of the posible solutions are working, it simple says the same error,
"ErrorCode 800a0401"
"expected end of statement"
at line 2, character 45
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: cash drawer code, not working.

Post by Gaev »

mr cubefan:
but none of the posible solutions are working, it simple says the same error,
"ErrorCode 800a0401"
"expected end of statement"
at line 2, character 45
a) I am assuning that this code in myTest.vbs worked ...

Code: Select all

WScript.Echo "Hello from my test vbs file"
WScript.Echo "Ended my test vbs file"
You should see two dialog boxes pop up ... please post your experience.

If the script in (a) popped up two dialog boxes, it looks like the Open or Print command has a syntax error (I can't tell which command is at line 2) ... so let us try to find it by process of elimination ... try this code in myTest.vbs ...

Code: Select all

WScript.Echo "Hello from my test vbs file"
Open "\\ASUSTEK-PC\EPSON TM-T20II Receipt" For Output As #1
Close #1
WScript.Echo "Ended my test vbs file"
Again, you should see two dialog boxes pop up ... please post your experience.

If you do get an error message, then the Open command is the culprit ... I read somewhere that VBScript only permits printing to the "default printer" ... so this may be your problem.

If you do NOT get an error message, then the Print command is the culprit ... try and print something simple e.g. ...

Code: Select all

WScript.Echo "Hello from my test vbs file"
Open "\\ASUSTEK-PC\EPSON TM-T20II Receipt" For Output As #1
Print #1, "1234"
Close #1
WScript.Echo "Ended my test vbs file"
Again, you should see two dialog boxes pop up ... and (possibly) have 1234 printed on your printer ... please post your experience.
User avatar
mr cubefan
Posts: 33
Joined: Thu Mar 10, 2011 6:23 pm

Re: cash drawer code, not working.

Post by mr cubefan »

Hi Gaev!, i just tried the posted codes and here are the results:
the 2 dialog boxes are shown correctly no errors, but if i add any of the other lines (open or print) it simply shows the same error as described before.
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: cash drawer code, not working.

Post by Gaev »

mr cubefan:
the 2 dialog boxes are shown correctly no errors, but if i add any of the other lines (open or print) it simply shows the same error as described before.
I read in one of the vbscript forums that such scripts only print to the DEFAULT printer ... so it could be that the error message it puts out is somewhat misleading (not the first time Microsoft has been accused of this).

Other reasons could be that it is some sort of security issue ... while Excel is allowed to write to a shared printer, your NeoBook Application might not.

I suggest that you place this content in a file called vbstest11.vbs ...

Code: Select all

WScript.Echo "Hello from my test vbs file"
Open "\\ASUSTEK-PC\EPSON TM-T20II Receipt" For Output As #1
Print #1, "Hello Amigo"
Close #1
WScript.Echo "Ended my test vbs file"
... and then run it from outside your Neobook Application i.e. ...

a) locate this file in File Explorer (Windows Explorer)
b) right click on the entry and then click on the menu item named Open

If you get the same error at the Open commad, then vbscript is preventing you from printing to a printer other than the DEFAULT printer.

If there is no error, then it was a security issue.


You can also try and place this content in a file called vbstest12.vbs ...

Code: Select all

WScript.Echo "Hello from my test vbs file"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objPrinter = FSO.CreateTextFile("\\ASUSTEK-PC\EPSON TM-T20II Receipt", True)
objPrinter.Write("This is a test ---")
objPrinter.WriteLine("This is a new line")
objPrinter.Close
WScript.Echo "Ended my test vbs file"
Post detailed responses to each test.
User avatar
mr cubefan
Posts: 33
Joined: Thu Mar 10, 2011 6:23 pm

Re: cash drawer code, not working.

Post by mr cubefan »

Hi Gaev!, first of all, thanks mate!!, the last posted code works flawlessly!, now i cand send any esc/pos code to the POS printer.
Here is the same code with the cut and open cash drawer commands.

Code: Select all

Set FSO = CreateObject("Scripting.FileSystemObject")
Set objPrinter = FSO.CreateTextFile("\\ASUSTEK-PC\EPSON TM-T20II Receipt", True)
objPrinter.Write("This is a test ---")
objPrinter.WriteLine("This is a new line")
objPrinter.Write Chr(27) & "m" & Chr(109) ' partial cut code
objPrinter.Write Chr(27) & "p" & CHR(&H0) & CHR(&H64) & CHR(&H64)' open cash drawer code 
objPrinter.Close
btw is there a way to receive data from the printer, to monitor the cash drawer status? (open/close)

Thanks for your time and patience Gaev!
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: cash drawer code, not working.

Post by Gaev »

mr cubefan:
the last posted code works flawlessly!
Glad to hear that; so it looks like the problem with the other code was that it does not allow printing to a NON-DEFAULT printer.
now i cand send any esc/pos code to the POS printer.
Here is the same code with the cut and open cash drawer commands.
Note that you do not need these two lines ...

Code: Select all

objPrinter.Write("This is a test ---")
objPrinter.WriteLine("This is a new line")
... they were included just to see if you could print something simple (without complicated escape codes).
is there a way to receive data from the printer, to monitor the cash drawer status? (open/close)
I am not sure ... since your printer is being treated as a "file", it might be complicated to "read" a particular line/row/byte that constitutes the status code ... but before I investigate this, according to the Quick Reference Guide for this printer, there are two ways to ask for the "drawer status information' ...

Code: Select all

DLE EOT 1    'transmits real time status
GS r 1       'transmits status after completion of prior print or command
... the first one requires you to examine bits (within returned byte); the second one returns a simple value of 1 or 0; so you might try ...

Code: Select all

Set FSO = CreateObject("Scripting.FileSystemObject")
Set objPrinter = FSO.CreateTextFile("\\ASUSTEK-PC\EPSON TM-T20II Receipt", True)
Set drawerStatus = objPrinter.Write("This is a test ---" & Chr(29) & "r2"
WScript.Echo "Drawer Status is " & drawerStatus
objPrinter.Close
... if this does not work, do you have any example (in any language) from Epson that shows how to receive this information ?
User avatar
mr cubefan
Posts: 33
Joined: Thu Mar 10, 2011 6:23 pm

Re: cash drawer code, not working.

Post by mr cubefan »

Hi Gaev!, after trying your last posted code and others found on the internet, i simply can´t make it to receive data from the printer, so i take another aproach. Wiring the switch from the drawer to the PC via rs232 port.
Long ago a user from this forum (ebear) was able to wire a pushbutton to the com port, thats the same thing i want to do, BUT the schematics and components images are missing from the post.
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: cash drawer code, not working.

Post by Gaev »

mr cubefan:

I did some more searching and found/downloaded a html document with sample (html, css and javascript) code ... the way to get the printer to provide the information you need is to make a call ... and, within the call, supply the name of a separate function which is to receive the response ... this is just like how you code internet get/post requests in a Browser.

However, I am not sure you can do the same in a "vbs/javscript function called from within NeoBook" ... the called (javascript) function might be closed by NeoBook before the response is received ... you would have to ask Dave to verify this.

In any case, I am not sure if you really need to get the state of the drawer ... you can just force the desired state (open/close) ... no harm in requesting that it be closed when it is already closed (and same for opening it).
User avatar
mr cubefan
Posts: 33
Joined: Thu Mar 10, 2011 6:23 pm

Re: cash drawer code, not working.

Post by mr cubefan »

Hi Gaev!, first of all, thanks for your time and effort trying to solve my little problem, but like i said before i take another aproach to detect the drawer state. I simply build a serial loopback cable, with the pin 2 attached to the cash drawer switch and the pin 3 to the other switch pin. Every 2 seconds the main app send a text string via the serial port, if the string is received then the drawer is closed, if not the drawer is open and a subroutine is executed. This configuration is working as expected.
Thanks!
Locked